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

update: Add working group json schema testing to build

parent 16a65786
Branches
No related tags found
1 merge request!91update: Add working group json schema testing to build
Pipeline #56007 passed
......@@ -22,6 +22,7 @@ install-yarn:;
compile-test-resources: install-yarn;
yarn run generate-json-schema
yarn test
compile-java: compile-test-resources;
mvn compile package
......
This diff is collapsed.
......@@ -4,12 +4,13 @@
"dependencies": {
"@types/node": "^20.11.30",
"eclipsefdn-api-support": "1.0.0",
"tsx": "^4.7.1"
"tsx": "^4.7.1",
"zod": "^3.23.8"
},
"private": true,
"scripts": {
"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 && node src/test/js/WorkingGroupFormatValidator.js -f src/main/resources/working_groups.json",
"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/",
"report-wg-levels": "tsx src/main/js/reportLevels.ts"
......
......@@ -12,13 +12,13 @@ servers:
description: Production endpoint for Eclipse Foundation working group data
paths:
"":
/:
parameters:
- name: status
in: query
schema:
type: string
description: The project status
type: string
description: The project status
get:
tags:
- Working Groups
......
/** **************************************************************
Copyright (C) 2023 Eclipse Foundation, Inc.
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/
Contributors:
Martin Lowe <martin.lowe@eclipse-foundation.org>
SPDX-License-Identifier: EPL-2.0
******************************************************************/
const argv = require('yargs')
.usage('Usage: $0 [options]')
.example('$0', '')
.option('f', {
alias: 'file',
description: 'The location of the JSON file to test. Should be readable by the current user',
}).argv;
const { z } = require('zod');
const fs = require('fs');
const WGPA_FORMAT = z.object({
document_id: z.string(),
pdf: z.string().url()
}).nullable();
const WORKING_GROUP_SCHEMA = z.object({
working_groups: z.record(z.string(), z.object({
alias: z.string(),
title: z.string(),
status: z.string(),
parent_organization: z.string(),
logo: z.string().url(),
description: z.string(),
resources: z.object({
charter: z.string().url().or(z.string().max(0)),
participation_agreements: z.object({
individual: WGPA_FORMAT,
organization: WGPA_FORMAT
}),
website: z.string().url().or(z.string().max(0)),
members: z.string().url().or(z.string().max(0)),
sponsorship: z.string().url().or(z.string().max(0)),
contact_form: z.string().url().or(z.string().max(0))
}),
levels: z.array(z.object({
relation: z.string().max(5),
description: z.string()
}))
})),
});
// attempt to parse the passed file as override JSON
try {
const out = castJsonToFormat(fs.readFileSync(argv.f, { encoding: 'UTF-8' }));
// let the user know what we found generally.
console.log(`Successfully parsed ${Object.keys(out.working_groups).length} working groups`);
} catch (e) {
console.log(`Error encountered while processing JSON at ${argv.f}: ` + e);
// error out if bad
process.exit(1);
}
function castJsonToFormat(jsonString) {
return WORKING_GROUP_SCHEMA.parse(JSON.parse(jsonString));
}
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment