Skip to content

Commit 9602bbc

Browse files
committed
feat: generate merged schema for postman import
1 parent 8cf7054 commit 9602bbc

File tree

6 files changed

+1950
-5
lines changed

6 files changed

+1950
-5
lines changed

packages/live-status-gateway-api/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
node_modules
22
dist
3+
temp
34
test
45
src/**.js
56

packages/live-status-gateway-api/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@
2929
"license-validate": "run -T sofie-licensecheck",
3030
"gendocs": "yarn resolve-nested-examples && ag ./dist/api/asyncapi.yaml @asyncapi/html-template -o docs -p singleFile=true -p outFilename=liveStatus.html",
3131
"genserver": "yarn resolve-nested-examples && ag ./dist/api/asyncapi.yaml @asyncapi/nodejs-ws-template -o server -p server=development",
32-
"generate-schema-types": "node scripts/generate-schema-types.mjs",
33-
"resolve-nested-examples": "node scripts/resolve-nested-examples.mjs"
32+
"generate-schema-types": "yarn resolve-nested-examples && node scripts/generate-schema-types.mjs",
33+
"resolve-nested-examples": "node scripts/resolve-nested-examples.mjs && yarn merge-schemas",
34+
"merge-schemas": "node scripts/merge-schemas.mjs"
3435
},
3536
"engines": {
3637
"node": ">=14.19"
@@ -63,4 +64,4 @@
6364
]
6465
},
6566
"packageManager": "yarn@4.10.3"
66-
}
67+
}

packages/live-status-gateway-api/scripts/generate-schema-types.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const generator = new TypeScriptGenerator({
6161
})
6262

6363
const parser = new Parser()
64-
const asyncApiDoc = await fromFile(parser, 'dist/api/asyncapi.yaml').parse()
64+
const asyncApiDoc = await fromFile(parser, 'src/generated/asyncapi.yaml').parse()
6565
if (!asyncApiDoc.document) {
6666
// Ignore the expected legacy version error
6767
const filteredDiagnostics = asyncApiDoc.diagnostics.filter((d) => d.code !== 'asyncapi-latest-version')
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import fs from 'fs'
2+
import path from 'path'
3+
import YAML from 'yaml'
4+
import { fromFile, Parser } from '@asyncapi/parser'
5+
6+
const ROOT_FILE = './temp/api/asyncapi.yaml'
7+
const OUTPUT_FILE = './src/generated/asyncapi.yaml'
8+
9+
async function main() {
10+
try {
11+
const parser = new Parser()
12+
const { document } = await fromFile(parser, ROOT_FILE).parse()
13+
14+
if (!document) {
15+
throw new Error('Failed to parse the AsyncAPI document.')
16+
}
17+
18+
// Convert the resolved document to JS object
19+
const resolved = document.json()
20+
21+
// Ensure output directory exists
22+
fs.mkdirSync(path.dirname(OUTPUT_FILE), { recursive: true })
23+
24+
// Write out single YAML file
25+
fs.writeFileSync(OUTPUT_FILE, YAML.stringify(resolved), 'utf-8')
26+
27+
console.log(`Fully resolved AsyncAPI schema written to: ${OUTPUT_FILE}`)
28+
} catch (err) {
29+
console.error('Failed to generate resolved AsyncAPI schema:', err)
30+
throw err
31+
}
32+
}
33+
34+
main()

packages/live-status-gateway-api/scripts/resolve-nested-examples.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from 'path'
33
import YAML from 'yaml'
44

55
const ROOT_DIR = './api'
6-
const RESOLVED_DIST_DIR = './dist/api/'
6+
const RESOLVED_DIST_DIR = './temp/api/'
77

88
/**
99
* Ensures that a directory exists, creating it and all necessary parent directories

0 commit comments

Comments
 (0)