Skip to content

Commit 3d3b41a

Browse files
feat: change to have up to do date version in contract root
1 parent 5be710e commit 3d3b41a

File tree

8 files changed

+255
-17
lines changed

8 files changed

+255
-17
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: PersonRegisteredContract
3+
version: 2
4+
summary: |
5+
A summary
6+
producers:
7+
- Producer
8+
consumers:
9+
- Consumer
10+
owners:
11+
- Name
12+
---
13+
14+
<Admonition>Some information</Admonition>
15+
16+
### Details
17+
18+
Some details...
19+
20+
<Schema />
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"type": "object",
4+
"properties": {
5+
"detail-type": {
6+
"type": "string",
7+
"const": "PersonRegisteredContract"
8+
},
9+
"detail": {
10+
"type": "object",
11+
"properties": {
12+
"detail-version": {
13+
"type": "number",
14+
"const": 2
15+
},
16+
"data": {
17+
"type": "object",
18+
"properties": {
19+
"firstName": {
20+
"type": "string"
21+
}
22+
},
23+
"required": [
24+
"firstName"
25+
],
26+
"additionalProperties": false
27+
}
28+
},
29+
"required": [
30+
"detail-version",
31+
"data"
32+
],
33+
"additionalProperties": false
34+
}
35+
},
36+
"required": [
37+
"detail",
38+
"detail-type"
39+
],
40+
"additionalProperties": false,
41+
"definitions": {}
42+
}

event-catalog/events/Test/index.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Test
3+
version: 1
4+
summary: |
5+
A summary
6+
producers:
7+
- Producer
8+
consumers:
9+
- Consumer
10+
owners:
11+
- Name
12+
---
13+
14+
<Admonition>Some information</Admonition>
15+
16+
### Details
17+
18+
Some details...
19+
20+
<Schema />
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"type": "object",
4+
"properties": {
5+
"detail-type": {
6+
"type": "string",
7+
"const": "Test"
8+
},
9+
"detail": {
10+
"type": "object",
11+
"properties": {
12+
"detail-version": {
13+
"type": "number",
14+
"const": 1
15+
},
16+
"data": {
17+
"type": "object",
18+
"properties": {
19+
"test": {
20+
"type": "string"
21+
}
22+
},
23+
"required": [
24+
"test"
25+
],
26+
"additionalProperties": false
27+
}
28+
},
29+
"required": [
30+
"detail-version",
31+
"data"
32+
],
33+
"additionalProperties": false
34+
}
35+
},
36+
"required": [
37+
"detail",
38+
"detail-type"
39+
],
40+
"additionalProperties": false,
41+
"definitions": {}
42+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Test
3+
version: 1
4+
summary: |
5+
A summary
6+
producers:
7+
- Producer
8+
consumers:
9+
- Consumer
10+
owners:
11+
- Name
12+
---
13+
14+
<Admonition>Some information</Admonition>
15+
16+
### Details
17+
18+
Some details...
19+
20+
<Schema />
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"type": "object",
4+
"properties": {
5+
"detail-type": {
6+
"type": "string",
7+
"const": "Test"
8+
},
9+
"detail": {
10+
"type": "object",
11+
"properties": {
12+
"detail-version": {
13+
"type": "number",
14+
"const": 1
15+
},
16+
"data": {
17+
"type": "object",
18+
"properties": {
19+
"test": {
20+
"type": "string"
21+
}
22+
},
23+
"required": [
24+
"test"
25+
],
26+
"additionalProperties": false
27+
}
28+
},
29+
"required": [
30+
"detail-version",
31+
"data"
32+
],
33+
"additionalProperties": false
34+
}
35+
},
36+
"required": [
37+
"detail",
38+
"detail-type"
39+
],
40+
"additionalProperties": false,
41+
"definitions": {}
42+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Contract } from "../../types";
2+
export interface Test extends Contract {
3+
"detail-type": "Test";
4+
detail: {
5+
"detail-version": 1;
6+
data: {
7+
test: string;
8+
};
9+
};
10+
}

src/generate-docs.ts

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import path from "path";
55
import { generateSchemaDetails } from "./helpers/generateSchemaDetails.js";
66
import { writeIndexFile } from "./helpers/writeIndexFile.js";
77
import { writeSchemaFile } from "./helpers/writeSchemaFile.js";
8+
import { ContractSchemaType, SchemaDetails } from "./types.js";
89

910
//Note: contract file name must include term 'Contract' to be parsed
1011
const getContractFileNames = async (
@@ -15,27 +16,65 @@ const getContractFileNames = async (
1516
return files.filter((fileName) => fileName.includes("Contract"));
1617
};
1718

18-
const getRecordOfNewestVersions = (
19-
newestVersions: Record<string, number>,
20-
detailType: string,
21-
detailVersion: number
22-
): Record<string, number> => {
23-
if ("detailType" in newestVersions) {
24-
if (newestVersions[detailType] < detailVersion) {
25-
newestVersions[detailType] = detailVersion;
19+
const getRecordOfNewestContractVersions = (
20+
newestContractVersions: Record<
21+
string,
22+
{ detailVersion: number; schema: ContractSchemaType }
23+
>,
24+
schemaDetails: SchemaDetails
25+
): Record<string, { detailVersion: number; schema: ContractSchemaType }> => {
26+
const { detailType, detailVersion, schema } = schemaDetails;
27+
28+
if ("detailType" in newestContractVersions) {
29+
if (newestContractVersions[detailType].detailVersion < detailVersion) {
30+
newestContractVersions[detailType] = {
31+
detailVersion,
32+
schema,
33+
};
2634
}
2735
} else {
28-
newestVersions[detailType] = detailVersion;
36+
newestContractVersions[detailType] = {
37+
detailVersion,
38+
schema,
39+
};
40+
}
41+
return newestContractVersions;
42+
};
43+
44+
const writeNewestContractVersionDocs = async (
45+
newestContractVersions: Record<
46+
string,
47+
{ detailVersion: number; schema: ContractSchemaType }
48+
>,
49+
pathToDocumentationFolder: string
50+
) => {
51+
for (const detailType in newestContractVersions) {
52+
const detailVersion = newestContractVersions[detailType].detailVersion;
53+
const pathToContractDocumentationFolder = path.join(
54+
`${pathToDocumentationFolder}/${detailType}`
55+
);
56+
await writeIndexFile(
57+
pathToContractDocumentationFolder,
58+
detailType,
59+
detailVersion
60+
);
61+
62+
await writeSchemaFile(
63+
pathToContractDocumentationFolder,
64+
newestContractVersions[detailType].schema
65+
);
2966
}
30-
return newestVersions;
3167
};
3268

3369
export const generateDocumentation = async (
3470
pathToContractsFolder: string,
3571
pathToDocumentationFolder: string
3672
): Promise<void> => {
3773
const contractFileNames = await getContractFileNames(pathToContractsFolder);
38-
let newestVersions: Record<string, number> = {};
74+
let newestContractVersions: Record<
75+
string,
76+
{ detailVersion: number; schema: ContractSchemaType }
77+
> = {};
3978

4079
for (const contractFileName of contractFileNames) {
4180
const { detailType, detailVersion, schema } = generateSchemaDetails(
@@ -57,13 +96,16 @@ export const generateDocumentation = async (
5796

5897
await writeSchemaFile(pathToContractDocumentationFolder, schema);
5998

60-
newestVersions = getRecordOfNewestVersions(
61-
newestVersions,
62-
detailType,
63-
detailVersion
99+
newestContractVersions = getRecordOfNewestContractVersions(
100+
newestContractVersions,
101+
{ detailType, detailVersion, schema }
64102
);
65103

66-
console.log(`Created docs for ${contractFileName}`);
67-
console.log(newestVersions);
104+
console.log(newestContractVersions);
68105
}
106+
107+
writeNewestContractVersionDocs(
108+
newestContractVersions,
109+
pathToDocumentationFolder
110+
);
69111
};

0 commit comments

Comments
 (0)