Skip to content

Add support for flows inside pattern using const to a url reference + confirm generated arch document renders flow in docify #1374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,8 @@
}
}
],
"flows": [
"https://calm.finos.org/workshop/flows/conference-signup.flow.json"
],
"$schema": "https://calm.finos.org/release/1.0-rc1/meta/calm.json"
}
13 changes: 12 additions & 1 deletion calm/workshop/conference-secure-signup.pattern.json
Original file line number Diff line number Diff line change
Expand Up @@ -452,11 +452,22 @@
]
}]

},
"flows": {
"type": "array",
"minItems": 1,
"maxItems": 1,
"prefixItems": [
{
"const": "https://calm.finos.org/workshop/flows/conference-signup.flow.json"
}
]
}
},
"required": [
"nodes",
"relationships",
"metadata"
"metadata",
"flows"
]
}
3 changes: 2 additions & 1 deletion calm/workshop/directory.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"https://calm.finos.org/workshop/controls/micro-segmentation.requirement.json": "controls/micro-segmentation.requirement.json",
"https://calm.finos.org/workshop/controls/permitted-connection.requirement.json": "controls/permitted-connection.requirement.json",
"https://calm.finos.org/workshop/controls/permitted-connection-http.config.json": "controls/permitted-connection-http.config.json",
"https://calm.finos.org/workshop/controls/permitted-connection-jdbc.config.json": "controls/permitted-connection-jdbc.config.json"
"https://calm.finos.org/workshop/controls/permitted-connection-jdbc.config.json": "controls/permitted-connection-jdbc.config.json",
"https://calm.finos.org/workshop/flows/conference-signup.flow.json": "flows/conference-signup.flow.json"
}
24 changes: 24 additions & 0 deletions calm/workshop/flows/conference-signup.flow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$schema": "https://calm.finos.org/release/1.0-rc1/meta/flow.json",
"$id": "https://calm.finos.org/workshop/flow/conference-signup.flow.json",
"unique-id": "flow-conference-signup",
"name": "Conference Signup Flow",
"description": "Flow for registering a user through the conference website and storing their details in the attendee database.",
"transitions": [
{
"relationship-unique-id": "conference-website-load-balancer",
"sequence-number": 1,
"summary": "User submits sign-up form via Conference Website to Load Balancer"
},
{
"relationship-unique-id": "load-balancer-attendees",
"sequence-number": 2,
"summary": "Load Balancer forwards request to Attendees Service"
},
{
"relationship-unique-id": "attendees-attendees-store",
"sequence-number": 3,
"summary": "Attendees Service stores attendee info in the Attendees Store"
}
]
}
41 changes: 41 additions & 0 deletions shared/src/commands/generate/components/instantiate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,45 @@ describe('instantiate', () => {
expect(result.nodes[0]['node-type']).toBe('[[ NODE_TYPE ]]');
expect(result.nodes[0]['details']['arch']).toBe('[[ ARCH ]]');
});

it('uses const values directly for array items', async () => {
// Define a pattern document with an array that contains items with const values
const patternWithConstArrayItems = {
$schema: 'schema#',
$id: 'test-pattern-const-array',
properties: {
simpleArray: {
type: 'array',
prefixItems: [
{ const: 'string-value' },
{ const: 42 },
{ const: true },
{ const: null },
{ const: { nestedKey: 'nested-value' } },
{
type: 'object',
properties: {
key: { type: 'string' }
},
required: ['key']
}
]
}
}
};

(fs.readFileSync as Mock).mockImplementation(() => JSON.stringify(patternWithConstArrayItems));

const pattern = JSON.parse(fs.readFileSync(patternPath, { encoding: 'utf-8' }));
const result = await instantiate(pattern, true, new SchemaDirectory(null));

expect(result['simpleArray']).toEqual([
'string-value',
42,
true,
null,
{ nestedKey: 'nested-value' },
{ key: '[[ KEY ]]' } // Non-const item should be instantiated with placeholder
]);
});
});
15 changes: 10 additions & 5 deletions shared/src/commands/generate/components/instantiate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,17 @@ async function instantiateFromProperties(
const resolvedDef = await resolveSchema(def as JsonSchema, schemaDir);

if (resolvedDef.type === 'array' && resolvedDef.prefixItems) {
output[key] = await Promise.all(resolvedDef.prefixItems.map(async (itemDef, idx) => {
const resolvedItem = await resolveSchema(itemDef, schemaDir);
return instantiateObject(resolvedItem, schemaDir, [key, `${idx}`]);
}));
output[key] = await Promise.all(
resolvedDef.prefixItems.map(async (itemDef, idx) => {
const resolvedItem = await resolveSchema(itemDef, schemaDir);
if (resolvedItem.const !== undefined) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing

if (resolvedItem.const !== undefined) {
    return resolvedItem.const;
}

over

if (resolvedItem.const) {
    return resolvedItem.const;
}

Allows support for

{ const: null }

return resolvedItem.const;
}
return await instantiateObject(resolvedItem, schemaDir, [key, `${idx}`]);
})
);
} else {
output[key] = instantiateObject(resolvedDef, schemaDir, [key]);
output[key] = await instantiateObject(resolvedDef, schemaDir, [key]);
}
}

Expand Down
21 changes: 17 additions & 4 deletions shared/src/docify/docifier.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const INPUT_DIR = join(
);
const WORKSHOP_DIR = join(
__dirname,
'../../../calm/workshop/controls'
'../../../calm/workshop'
);

const OUTPUT_DIR = join(__dirname, '../../test_fixtures/docify/workshop/actual-output');
Expand All @@ -26,15 +26,22 @@ describe('Docifier E2E - Real Model and Template', () => {

it('generates documentation from the conference-signup.arch.json model', async () => {

const docifier = new Docifier('WEBSITE', join(INPUT_DIR, 'conference-signup.arch.json'), NON_SECURE_VERSION_DOC_WEBSITE, new Map<string,string>());
//TODO: This test needs manual mapping until flows folder is republished.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If folks are happy with this PR, then recommend we first just publish the new flows document to S3 and then this will not be needed

const mapping = new Map<string, string>([
['https://calm.finos.org/workshop/flows/conference-signup.flow.json', join(WORKSHOP_DIR, 'flows/conference-signup.flow.json')],
]);


const docifier = new Docifier('WEBSITE', join(INPUT_DIR, 'conference-signup.arch.json'), NON_SECURE_VERSION_DOC_WEBSITE, mapping);
await docifier.docify();
await expectDirectoryMatch(join(EXPECTED_OUTPUT_DIR,'non-secure'),join(OUTPUT_DIR,'non-secure'));

});

it('generates documentation from the conference-secure-signup.arch.json model with explicit local mapping', async () => {
const mapping = new Map<string, string>([
['https://calm.finos.org/workshop/controls/micro-segmentation.config.json', join(WORKSHOP_DIR, 'micro-segmentation.config.json')],
['https://calm.finos.org/workshop/controls/micro-segmentation.config.json', join(WORKSHOP_DIR, 'controls/micro-segmentation.config.json')],
['https://calm.finos.org/workshop/flows/conference-signup.flow.json', join(WORKSHOP_DIR, 'flows/conference-signup.flow.json')],
]);

const docifier = new Docifier('WEBSITE', join(INPUT_DIR, 'conference-secure-signup-amended.arch.json'), SECURE_VERSION_DOC_WEBSITE, mapping);
Expand All @@ -45,7 +52,13 @@ describe('Docifier E2E - Real Model and Template', () => {
});

it('generates documentation from the conference-secure-signup.arch.json model with no mapping as workshop documents are available', async () => {
const docifier = new Docifier('WEBSITE', join(INPUT_DIR, 'conference-secure-signup-amended.arch.json'), SECURE_VERSION_DOC_WEBSITE, new Map<string,string>());

//TODO: This test needs manual mapping until flows folder is republished.
const mapping = new Map<string, string>([
['https://calm.finos.org/workshop/flows/conference-signup.flow.json', join(WORKSHOP_DIR, 'flows/conference-signup.flow.json')],
]);

const docifier = new Docifier('WEBSITE', join(INPUT_DIR, 'conference-secure-signup-amended.arch.json'), SECURE_VERSION_DOC_WEBSITE, mapping);
await docifier.docify();
await expectDirectoryMatch(join(EXPECTED_OUTPUT_DIR,'secure'),join(OUTPUT_DIR,'secure'));

Expand Down
1 change: 1 addition & 0 deletions shared/src/template/template-processor.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ describe('TemplateProcessor E2E', () => {
['https://calm.finos.org/workshop/controls/permitted-connection.requirement.json', join(WORKSHOP_DIR, 'controls/permitted-connection.requirement.json')],
['https://calm.finos.org/workshop/controls/permitted-connection-http.config.json', join(WORKSHOP_DIR, 'controls/permitted-connection-http.config.json')],
['https://calm.finos.org/workshop/controls/permitted-connection-jdbc.config.json', join(WORKSHOP_DIR, 'controls/permitted-connection-jdbc.config.json')],
['https://calm.finos.org/workshop/flows/conference-signup.flow.json', join(WORKSHOP_DIR, 'flows/conference-signup.flow.json')],
]);
const processor = new TemplateProcessor(
amendedPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,8 @@
}
}
],
"flows": [
"https://calm.finos.org/workshop/flows/conference-signup.flow.json"
],
"$schema": "https://calm.finos.org/draft/2025-03/meta/calm.json"
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,8 @@
}
}
],
"flows": [
"https://calm.finos.org/workshop/flows/conference-signup.flow.json"
],
"$schema": "https://calm.finos.org/workshop/conference-secure-signup.pattern.json"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
id: flow-conference-signup
title: Conference Signup Flow
---

## Details
<div className="table-container">
| Field | Value |
|---------------------|--------------------------|
| **Unique ID** | flow-conference-signup |
| **Name** | Conference Signup Flow |
| **Description** | Flow for registering a user through the conference website and storing their details in the attendee database. |
</div>

## Sequence Diagram
```mermaid
sequenceDiagram
Conference Website ->> Load Balancer: User submits sign-up form via Conference Website to Load Balancer
Load Balancer ->> Attendees Service: Load Balancer forwards request to Attendees Service
Attendees Service ->> Attendees Store: Attendees Service stores attendee info in the Attendees Store
```
## Controls
_No controls defined._

## Metadata
_No Metadata defined._
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ UpdateLayoutConfig($c4ShapeInRow="2", $c4BoundaryInRow="0")


## Flows
_No flows defined._
- [Conference Signup Flow](flows/flow-conference-signup)

## Controls
| ID | Name | Description | Domain | Scope | Applied To |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,12 @@ module.exports = {
'relationships/deployed-in-k8s-cluster'
],
},
{
type: 'category',
label: 'Flows',
items: [
'flows/flow-conference-signup'
],
}
]
};
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,8 @@
}
}
],
"flows": [
"https://calm.finos.org/workshop/flows/conference-signup.flow.json"
],
"$schema": "https://calm.finos.org/workshop/conference-secure-signup.pattern.json"
}
Loading