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
2 changes: 1 addition & 1 deletion .github/workflows/check-schemas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
go-version-file: go.mod

- name: Install go-jsonschema
run: go install github.com/atombender/go-jsonschema@latest
run: go install github.com/atombender/go-jsonschema@v0.23.0

- name: Generate JSON schemas
run: node tools/gen-json-schemas.mjs
Expand Down
9 changes: 7 additions & 2 deletions tools/gen-json-schemas.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ import { execSync } from 'child_process';
import fs from 'fs';
import path from 'path';

let goJSONSchemaHelp = '';

// ensure go-jsonschema is installed
try {
execSync('go-jsonschema -h', { stdio: 'ignore' });
goJSONSchemaHelp = execSync('go-jsonschema -h', { encoding: 'utf8' });
console.log('go-jsonschema is installed.');
} catch (e) {
console.log('go-jsonschema is not installed. Please install it first.');
process.exit(1);
}

const supportsDisableOmitZero = goJSONSchemaHelp.includes('--disable-omitzero');

console.log('Generating Go structs from JSON schemas...');

// find every directory in internal/rules that contains schema.json and generate Go struct
Expand Down Expand Up @@ -96,10 +100,11 @@ for (const schemaDir of schemaDirs) {

console.log(`Generating Go struct for schema: ${schemaPath} and outputting to: ${outputPath}`);
try {
const omitZeroArg = supportsDisableOmitZero ? ' --disable-omitzero' : '';
execSync(
`go-jsonschema "${schemaPath}" -o "${outputPath}" -p ${
path.basename(schemaDir)
} --tags json --resolve-extension json`,
} --tags json --resolve-extension json${omitZeroArg}`,
{
stdio: 'inherit',
},
Expand Down
Loading