Skip to content
Snippets Groups Projects
Commit 66ac3d28 authored by Martin Lowe's avatar Martin Lowe :flag_ca:
Browse files

Merge branch 'malowe/main/support_pkg' into 'main'

Update build to use new ef-api-support pkg

See merge request !8
parents 16894b89 ac959d61
No related branches found
No related tags found
1 merge request!8Update build to use new ef-api-support pkg
Pipeline #7829 failed
...@@ -2,18 +2,13 @@ ...@@ -2,18 +2,13 @@
"name": "eclipsefdn-cve-api-support", "name": "eclipsefdn-cve-api-support",
"version": "1.0.0", "version": "1.0.0",
"dependencies": { "dependencies": {
"@redocly/openapi-cli": "^1.0.0-beta.54", "eclipsefdn-api-support": "^1.0.0"
"@openapi-contrib/openapi-schema-to-json-schema": "^3.1.1",
"@stoplight/json-ref-resolver": "^3.1.2",
"decamelize": "^5.0.0",
"js-yaml": "^4.1.0",
"yargs": "^17.0.1"
}, },
"private": true, "private": true,
"scripts": { "scripts": {
"start": "yarn run generate-json-schema && npx @redocly/openapi-cli preview-docs spec/openapi.yaml -p 8097", "start": "yarn run generate-json-schema && npx @redocly/openapi-cli preview-docs spec/openapi.yaml -p 8097",
"test": "yarn run generate-json-schema && npx @redocly/openapi-cli lint spec/openapi.yaml", "test": "yarn run generate-json-schema && npx @redocly/openapi-cli lint spec/openapi.yaml",
"generate-json-schema": "yarn run clean && node src/main/js/openapi2schema.js -s spec/openapi.yaml -t src/test/resources", "generate-json-schema": "yarn run clean && node node_modules/eclipsefdn-api-support/src/openapi2schema.js -s spec/openapi.yaml -t src/test/resources",
"clean": "rm -rf src/test/resources/schemas/" "clean": "rm -rf src/test/resources/schemas/"
} }
} }
/**
* Copyright (c) 2021 Eclipse
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* Author: Martin Lowe <martin.lowe@eclipsefoundation.org>
*
* SPDX-License-Identifier: EPL-2.0
*/
const toJsonSchema = require('@openapi-contrib/openapi-schema-to-json-schema');
const Resolver = require('@stoplight/json-ref-resolver');
const yaml = require('js-yaml');
const fs = require('fs');
const decamelize = require('decamelize');
const args = require('yargs')
.option('s', {
alias: 'src',
desc: 'The fully qualified path to the YAML spec.',
})
.option('t', {
alias: 'target',
desc: 'The fully qualified path to write the JSON schema to',
}).argv;
if (!args.s || !args.t) {
process.exit(1);
}
run();
/**
* Generates JSON schema files for consumption of the Java tests.
*/
async function run() {
try {
// load in the openapi yaml spec as an object
const doc = yaml.load(fs.readFileSync(args.s, 'utf8'));
// resolve $refs in openapi spec
let resolvedInp = await new Resolver.Resolver().resolve(doc);
const out = toJsonSchema(resolvedInp.result);
// if folder doesn't exist, create it
if (!fs.existsSync(`${args.t}/schemas`)) {
fs.mkdirSync(`${args.t}/schemas`);
}
// for each of the schemas, generate a JSON schema file
for (let schemaName in out.components.schemas) {
fs.writeFileSync(`${args.t}/schemas/${decamelize(schemaName, { separator: '-' })}-schema.json`, JSON.stringify(out.components.schemas[schemaName]));
}
} catch (e) {
console.log(e);
}
}
...@@ -274,6 +274,18 @@ dependency-graph@~0.11.0: ...@@ -274,6 +274,18 @@ dependency-graph@~0.11.0:
resolved "https://registry.yarnpkg.com/dependency-graph/-/dependency-graph-0.11.0.tgz#ac0ce7ed68a54da22165a85e97a01d53f5eb2e27" resolved "https://registry.yarnpkg.com/dependency-graph/-/dependency-graph-0.11.0.tgz#ac0ce7ed68a54da22165a85e97a01d53f5eb2e27"
integrity sha512-JeMq7fEshyepOWDfcfHK06N3MhyPhz++vtqWhMT5O9A3K42rdsEDpfdVqjaqaAhsw6a+ZqeDvQVtD0hFHQWrzg== integrity sha512-JeMq7fEshyepOWDfcfHK06N3MhyPhz++vtqWhMT5O9A3K42rdsEDpfdVqjaqaAhsw6a+ZqeDvQVtD0hFHQWrzg==
eclipsefdn-api-support@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/eclipsefdn-api-support/-/eclipsefdn-api-support-1.0.0.tgz#c8937b5ca0d78a8b40af893853a0f47dd6e9b5fd"
integrity sha512-SjhoMWW1JADNJzFd5cQhiYnFGctSNGvhc+U4AH+1/eHA/Qbcs7SatpHLn9pBNSHFq0JqYjLa+9yMznc3FrSJFA==
dependencies:
"@openapi-contrib/openapi-schema-to-json-schema" "^3.1.1"
"@redocly/openapi-cli" "^1.0.0-beta.54"
"@stoplight/json-ref-resolver" "^3.1.2"
decamelize "^5.0.0"
js-yaml "^4.1.0"
yargs "^17.0.1"
emoji-regex@^8.0.0: emoji-regex@^8.0.0:
version "8.0.0" version "8.0.0"
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37" resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment