Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 62 additions & 22 deletions calm-hub-ui/cypress/fixtures/conference-signup-pattern.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://calm.finos.org/calm/schemas/2025-03/meta/calm.json",
"$schema": "https://calm.finos.org/release/1.3/meta/calm.json",
"$id": "https://calm.finos.org/calm/namespaces/workshop/patterns/1/versions/1.0.0",
"type": "object",
"title": "Conference Signup Pattern",
Expand All @@ -11,7 +11,7 @@
"maxItems": 5,
"prefixItems": [
{
"$ref": "https://calm.finos.org/calm/schemas/2025-03/meta/core.json#/defs/node",
"$ref": "https://calm.finos.org/release/1.3/meta/core.json#/defs/node",
"type": "object",
"properties": {
"unique-id": {
Expand All @@ -32,19 +32,25 @@
"maxItems": 1,
"prefixItems": [
{
"$ref": "https://calm.finos.org/calm/schemas/2025-03/meta/interface.json#/defs/url-interface",
"$ref": "https://calm.finos.org/release/1.3/meta/interface.json#/defs/interface-type",
"properties": {
"unique-id": {
"const": "conference-website-url"
},
"url": {
"type": "string"
}
}
},
"required": [
"url"
]
}
]
}
}
},
{
"$ref": "https://calm.finos.org/calm/schemas/2025-03/meta/core.json#/defs/node",
"$ref": "https://calm.finos.org/release/1.3/meta/core.json#/defs/node",
"type": "object",
"properties": {
"unique-id": {
Expand All @@ -65,19 +71,29 @@
"maxItems": 1,
"prefixItems": [
{
"$ref": "https://calm.finos.org/calm/schemas/2025-03/meta/interface.json#/defs/host-port-interface",
"$ref": "https://calm.finos.org/release/1.3/meta/interface.json#/defs/interface-type",
"properties": {
"unique-id": {
"const": "load-balancer-host-port"
},
"host": {
"type": "string"
},
"port": {
"type": "integer"
}
}
},
"required": [
"host",
"port"
]
}
]
}
}
},
{
"$ref": "https://calm.finos.org/calm/schemas/2025-03/meta/core.json#/defs/node",
"$ref": "https://calm.finos.org/release/1.3/meta/core.json#/defs/node",
"type": "object",
"properties": {
"unique-id": {
Expand All @@ -98,27 +114,39 @@
"maxItems": 2,
"prefixItems": [
{
"$ref": "https://calm.finos.org/calm/schemas/2025-03/meta/interface.json#/defs/container-image-interface",
"$ref": "https://calm.finos.org/release/1.3/meta/interface.json#/defs/interface-type",
"properties": {
"unique-id": {
"const": "attendees-image"
},
"image": {
"type": "string"
}
}
},
"required": [
"image"
]
},
{
"$ref": "https://calm.finos.org/calm/schemas/2025-03/meta/interface.json#/defs/port-interface",
"$ref": "https://calm.finos.org/release/1.3/meta/interface.json#/defs/interface-type",
"properties": {
"unique-id": {
"const": "attendees-port"
},
"port": {
"type": "integer"
}
}
},
"required": [
"port"
]
}
]
}
}
},
{
"$ref": "https://calm.finos.org/calm/schemas/2025-03/meta/core.json#/defs/node",
"$ref": "https://calm.finos.org/release/1.3/meta/core.json#/defs/node",
"type": "object",
"properties": {
"unique-id": {
Expand All @@ -139,27 +167,39 @@
"maxItems": 2,
"prefixItems": [
{
"$ref": "https://calm.finos.org/calm/schemas/2025-03/meta/interface.json#/defs/container-image-interface",
"$ref": "https://calm.finos.org/release/1.3/meta/interface.json#/defs/interface-type",
"properties": {
"unique-id": {
"const": "database-image"
},
"image": {
"type": "string"
}
}
},
"required": [
"image"
]
},
{
"$ref": "https://calm.finos.org/calm/schemas/2025-03/meta/interface.json#/defs/port-interface",
"$ref": "https://calm.finos.org/release/1.3/meta/interface.json#/defs/interface-type",
"properties": {
"unique-id": {
"const": "database-port"
},
"port": {
"type": "integer"
}
}
},
"required": [
"port"
]
}
]
}
}
},
{
"$ref": "https://calm.finos.org/calm/schemas/2025-03/meta/core.json#/defs/node",
"$ref": "https://calm.finos.org/release/1.3/meta/core.json#/defs/node",
"type": "object",
"properties": {
"unique-id": {
Expand All @@ -184,7 +224,7 @@
"maxItems": 4,
"prefixItems": [
{
"$ref": "https://calm.finos.org/calm/schemas/2025-03/meta/core.json#/defs/relationship",
"$ref": "https://calm.finos.org/release/1.3/meta/core.json#/defs/relationship",
"type": "object",
"properties": {
"unique-id": {
Expand Down Expand Up @@ -214,7 +254,7 @@
]
},
{
"$ref": "https://calm.finos.org/calm/schemas/2025-03/meta/core.json#/defs/relationship",
"$ref": "https://calm.finos.org/release/1.3/meta/core.json#/defs/relationship",
"type": "object",
"properties": {
"unique-id": {
Expand Down Expand Up @@ -244,7 +284,7 @@
]
},
{
"$ref": "https://calm.finos.org/calm/schemas/2025-03/meta/core.json#/defs/relationship",
"$ref": "https://calm.finos.org/release/1.3/meta/core.json#/defs/relationship",
"type": "object",
"properties": {
"unique-id": {
Expand Down Expand Up @@ -274,7 +314,7 @@
]
},
{
"$ref": "https://calm.finos.org/calm/schemas/2025-03/meta/core.json#/defs/relationship",
"$ref": "https://calm.finos.org/release/1.3/meta/core.json#/defs/relationship",
"properties": {
"unique-id": {
"const": "deployed-in-k8s-cluster"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,35 @@ describe('parsePatternData', () => {
expect(node?.data.interfaces[1].type).toBe('port-interface');
});

it('does not use a generic interface definition as the interface type', () => {
const pattern = makePattern([
schemaNode('svc-1', 'Service', 'service', {
interfaces: {
prefixItems: [
{
$ref: 'https://calm.finos.org/release/1.3/meta/interface.json#/defs/interface-type',
properties: {
'unique-id': { const: 'svc-1-host-port' },
},
},
{
$ref: 'https://calm.finos.org/release/1.3/meta/interface.json#/defs/interface-definition',
properties: {
'unique-id': { const: 'svc-1-definition' },
},
},
],
},
}),
]);
const result = parsePatternData(pattern);
const node = result.nodes.find((n) => n.id === 'svc-1');
expect(node?.data.interfaces).toEqual([
{ 'unique-id': 'svc-1-host-port' },
{ 'unique-id': 'svc-1-definition' },
]);
});

it('extracts controls from pattern schema', () => {
const pattern = makePattern(
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ function readSchemaValue(obj: SchemaObject | undefined, key: string): string | u
return undefined;
}

// These generic definitions do not name an interface type. From CALM 1.3, an interface can refer only to them.
const GENERIC_INTERFACE_DEFINITIONS = new Set(['interface-type', 'interface-definition']);

/**
* Extracts interfaces from a pattern node's schema item.
* Reads prefixItems and extracts unique-id and $ref type for each interface.
Expand All @@ -91,7 +94,8 @@ function extractInterfaces(item: SchemaObject): SchemaObject[] | undefined {
const uniqueId = iface['properties']?.['unique-id']?.['const'];
const ref = iface['$ref'] as string | undefined;
// Extract the interface type from the $ref (e.g., "url-interface" from ".../defs/url-interface")
const interfaceType = ref?.split('/').pop();
const definition = ref?.split('/').pop();
const interfaceType = definition && !GENERIC_INTERFACE_DEFINITIONS.has(definition) ? definition : undefined;
return {
'unique-id': uniqueId || '',
...(interfaceType && { type: interfaceType }),
Expand Down
Loading
Loading