From 8828e97da0ac64aed13036876ddebd68a991060c Mon Sep 17 00:00:00 2001 From: Mike Ralphson Date: Thu, 10 Jun 2021 10:57:28 +0100 Subject: [PATCH 1/2] Add test cases for valid and invalid top-level schemaObject types Signed-off-by: Mike Ralphson --- package.json | 3 +++ tests/v3.1/fail/invalid_schema_types.yaml | 13 +++++++++++++ tests/v3.1/pass/valid_schema_types.yaml | 14 ++++++++++++++ tests/v3.1/test.js | 4 ++-- 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 tests/v3.1/fail/invalid_schema_types.yaml create mode 100644 tests/v3.1/pass/valid_schema_types.yaml diff --git a/package.json b/package.json index ac2cac61d3..08cbfdd010 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,9 @@ "url": "https://github.com/OAI/OpenAPI-Specification.git" }, "license": "Apache-2.0", + "scripts": { + "test": "npx mocha tests/**/test.js" + }, "readmeFilename": "README.md", "files": [ "README.md", diff --git a/tests/v3.1/fail/invalid_schema_types.yaml b/tests/v3.1/fail/invalid_schema_types.yaml new file mode 100644 index 0000000000..d295b1f0ed --- /dev/null +++ b/tests/v3.1/fail/invalid_schema_types.yaml @@ -0,0 +1,13 @@ +openapi: 3.1.1 + +# this example shows invalid types for the schemaObject + +info: + title: API + version: 1.0.0 +components: + schemas: + invalid_null: null + invalid_number: 0 + invalid_array: [] + diff --git a/tests/v3.1/pass/valid_schema_types.yaml b/tests/v3.1/pass/valid_schema_types.yaml new file mode 100644 index 0000000000..4431adcda5 --- /dev/null +++ b/tests/v3.1/pass/valid_schema_types.yaml @@ -0,0 +1,14 @@ +openapi: 3.1.1 + +# this example shows that top-level schemaObjects MAY be booleans + +info: + title: API + version: 1.0.0 +components: + schemas: + anything_boolean: true + nothing_boolean: false + anything_object: {} + nothing_object: { not: {} } + diff --git a/tests/v3.1/test.js b/tests/v3.1/test.js index 5e7bf55692..8fef3a6543 100644 --- a/tests/v3.1/test.js +++ b/tests/v3.1/test.js @@ -17,7 +17,7 @@ before(async () => { metaSchema = await JsonSchema.get("https://spec.openapis.org/oas/3.1/schema/2021-05-20"); }); -describe("Pass", () => { +describe("v3.1 Pass", () => { fs.readdirSync(`${__dirname}/pass`, { withFileTypes: true }) .filter((entry) => entry.isFile() && /\.yaml$/.test(entry.name)) .forEach((entry) => { @@ -32,7 +32,7 @@ describe("Pass", () => { }); }); -describe("Fail", () => { +describe("v3.1 Fail", () => { fs.readdirSync(`${__dirname}/fail`, { withFileTypes: true }) .filter((entry) => entry.isFile() && /\.yaml$/.test(entry.name)) .forEach((entry) => { From e2da14a38229a57453a7f9209dffec41fa0b94f3 Mon Sep 17 00:00:00 2001 From: Mike Ralphson Date: Thu, 10 Jun 2021 11:11:03 +0100 Subject: [PATCH 2/2] Update workflow actions to node 14 Signed-off-by: Mike Ralphson --- .github/workflows/schema-tests.yaml | 31 ++++++++++++++++++++++++ .github/workflows/validate-markdown.yaml | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/schema-tests.yaml diff --git a/.github/workflows/schema-tests.yaml b/.github/workflows/schema-tests.yaml new file mode 100644 index 0000000000..11a699bf9e --- /dev/null +++ b/.github/workflows/schema-tests.yaml @@ -0,0 +1,31 @@ +name: schema-test + +# Author: @MikeRalphson / runs @jdesrosiers tests +# Issue: https://github.com/OAI/OpenAPI-Specification/pull/2489 + +# +# This workflow runs the npm test script to validate passing and failing +# testcases for the metaschema. +# + +# run this on push to any branch and creation of pull-requests +on: + push: {} + pull_request: {} + workflow_dispatch: {} + +jobs: + test: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 # checkout repo content + - uses: actions/setup-node@v1 # setup Node.js + with: + node-version: '14.x' + - name: Install dependencies + run: npm i + - name: Run tests + run: npm run test + diff --git a/.github/workflows/validate-markdown.yaml b/.github/workflows/validate-markdown.yaml index 05af39ceaf..7cba565cd5 100644 --- a/.github/workflows/validate-markdown.yaml +++ b/.github/workflows/validate-markdown.yaml @@ -21,7 +21,7 @@ jobs: - uses: actions/checkout@v2 # checkout repo content - uses: actions/setup-node@v1 # setup Node.js with: - node-version: '12.x' + node-version: '14.x' - name: Validate markdown run: npx mdv versions/3.*.md