diff --git a/.gitmodules b/.gitmodules index ca8320435d..e69de29bb2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "tests/v3.1/openapi3-examples"] - path = tests/openapi3-examples - url = git@github.com:Mermade/openapi3-examples.git diff --git a/scripts/validate.js b/scripts/validate.js index cf1c2d09ca..c9c70db797 100755 --- a/scripts/validate.js +++ b/scripts/validate.js @@ -24,14 +24,14 @@ const args = process.argv.reduce((acc, arg) => { (async function () { try { + const schemaType = args.schema || "schema"; + const schemaVersion = args.version || "2021-03-02"; + const outputFormat = args.format || JsonSchema.BASIC; + // Config JsonSchema.setMetaOutputFormat(outputFormat); //JsonSchema.setShouldMetaValidate(false); - const schemaType = args.schema || "schema"; - const schemaVersion = args.version || "2021-03-02"; - const ouputFormat = args.format || JsonSchema.BASIC; - // Load schemas JsonSchema.add(dialect); JsonSchema.add(vocabulary); diff --git a/tests/openapi3-examples b/tests/openapi3-examples deleted file mode 160000 index 9c2997e1a2..0000000000 --- a/tests/openapi3-examples +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 9c2997e1a25919a8182080cc43a4db06d2dc775d diff --git a/tests/v3.1/fail/no_containers.yaml b/tests/v3.1/fail/no_containers.yaml new file mode 100644 index 0000000000..6cc86aae92 --- /dev/null +++ b/tests/v3.1/fail/no_containers.yaml @@ -0,0 +1,4 @@ +iopenapi: 3.1.0 +info: + title: API + version: 1.0.0 diff --git a/tests/v3.1/fail/sever_enum_empty.yaml b/tests/v3.1/fail/sever_enum_empty.yaml new file mode 100644 index 0000000000..62d751e171 --- /dev/null +++ b/tests/v3.1/fail/sever_enum_empty.yaml @@ -0,0 +1,11 @@ +openapi: 3.1.0 +info: + title: API + version: 1.0.0 +servers: + - url: https://example.com/{var} + variables: + var: + enum: [] + default: a +components: {} diff --git a/tests/v3.1/fail/sever_enum_unknown.yaml b/tests/v3.1/fail/sever_enum_unknown.yaml new file mode 100644 index 0000000000..eb8c8f6872 --- /dev/null +++ b/tests/v3.1/fail/sever_enum_unknown.yaml @@ -0,0 +1,12 @@ +openapi: 3.1.0 +info: + title: API + version: 1.0.0 +servers: + - url: https://example.com/{var} + variables: + var: + enum: + - a + default: b +components: {} diff --git a/tests/v3.1/fail/unknown_container.yaml b/tests/v3.1/fail/unknown_container.yaml new file mode 100644 index 0000000000..e0565f4a5a --- /dev/null +++ b/tests/v3.1/fail/unknown_container.yaml @@ -0,0 +1,5 @@ +openapi: 3.1.0 +info: + title: API + version: 1.0.0 +overlays: {} diff --git a/tests/v3.1/pass/comp_pathitems.yaml b/tests/v3.1/pass/comp_pathitems.yaml new file mode 100644 index 0000000000..502ca1fca2 --- /dev/null +++ b/tests/v3.1/pass/comp_pathitems.yaml @@ -0,0 +1,6 @@ +openapi: 3.1.0 +info: + title: API + version: 1.0.0 +components: + pathItems: {} diff --git a/tests/v3.1/pass/info_summary.yaml b/tests/v3.1/pass/info_summary.yaml new file mode 100644 index 0000000000..30d224afc2 --- /dev/null +++ b/tests/v3.1/pass/info_summary.yaml @@ -0,0 +1,6 @@ +openapi: 3.1.0 +info: + title: API + summary: My lovely API + version: 1.0.0 +components: {} diff --git a/tests/v3.1/pass/license_identifier.yaml b/tests/v3.1/pass/license_identifier.yaml new file mode 100644 index 0000000000..fbdba5efbe --- /dev/null +++ b/tests/v3.1/pass/license_identifier.yaml @@ -0,0 +1,9 @@ +openapi: 3.1.0 +info: + title: API + summary: My lovely API + version: 1.0.0 + license: + name: Apache + identifier: Apache-2.0 +components: {} diff --git a/tests/v3.1/pass/mega.yaml b/tests/v3.1/pass/mega.yaml new file mode 100644 index 0000000000..8838c03a6d --- /dev/null +++ b/tests/v3.1/pass/mega.yaml @@ -0,0 +1,49 @@ +openapi: 3.1.0 +info: + summary: My API's summary + title: My API + version: 1.0.0 + license: + name: Apache 2.0 + identifier: Apache-2.0 +jsonSchemaDialect: https://spec.openapis.org/oas/3.1/dialect/base +paths: + /: + get: + parameters: [] + /{pathTest}: {} +webhooks: + myWebhook: + $ref: '#/components/pathItems/myPathItem' + description: Overriding description +components: + securitySchemes: + mtls: + type: mutualTLS + pathItems: + myPathItem: + post: + requestBody: + required: true + content: + 'application/json': + schema: + type: object + properties: + type: + type: string + int: + type: integer + exclusiveMaximum: 100 + exclusiveMinimum: 0 + none: + type: 'null' + arr: + type: array + $comment: Array without items keyword + either: + type: ['string','null'] + discriminator: + propertyName: type + x-extension: true + myArbitraryKeyword: true diff --git a/tests/v3.1/pass/minimal_comp.yaml b/tests/v3.1/pass/minimal_comp.yaml new file mode 100644 index 0000000000..4553689ab4 --- /dev/null +++ b/tests/v3.1/pass/minimal_comp.yaml @@ -0,0 +1,5 @@ +openapi: 3.1.0 +info: + title: API + version: 1.0.0 +components: {} diff --git a/tests/v3.1/pass/minimal_hooks.yaml b/tests/v3.1/pass/minimal_hooks.yaml new file mode 100644 index 0000000000..e67b2889de --- /dev/null +++ b/tests/v3.1/pass/minimal_hooks.yaml @@ -0,0 +1,5 @@ +openapi: 3.1.0 +info: + title: API + version: 1.0.0 +webhooks: {} diff --git a/tests/v3.1/pass/minimal_paths.yaml b/tests/v3.1/pass/minimal_paths.yaml new file mode 100644 index 0000000000..016e86796f --- /dev/null +++ b/tests/v3.1/pass/minimal_paths.yaml @@ -0,0 +1,5 @@ +openapi: 3.1.0 +info: + title: API + version: 1.0.0 +paths: {} diff --git a/tests/v3.1/pass/path_no_response.yaml b/tests/v3.1/pass/path_no_response.yaml new file mode 100644 index 0000000000..334608f111 --- /dev/null +++ b/tests/v3.1/pass/path_no_response.yaml @@ -0,0 +1,7 @@ +openapi: 3.1.0 +info: + title: API + version: 1.0.0 +paths: + /: + get: {} diff --git a/tests/v3.1/pass/path_var_empty_pathitem.yaml b/tests/v3.1/pass/path_var_empty_pathitem.yaml new file mode 100644 index 0000000000..ba92742f10 --- /dev/null +++ b/tests/v3.1/pass/path_var_empty_pathitem.yaml @@ -0,0 +1,6 @@ +openapi: 3.1.0 +info: + title: API + version: 1.0.0 +paths: + /{var}: {} diff --git a/tests/v3.1/pass/schema.yaml b/tests/v3.1/pass/schema.yaml new file mode 100644 index 0000000000..e192529a68 --- /dev/null +++ b/tests/v3.1/pass/schema.yaml @@ -0,0 +1,55 @@ +openapi: 3.1.0 +info: + title: API + version: 1.0.0 +paths: {} +components: + schemas: + model: + type: object + properties: + one: + description: type array + type: + - integer + - string + two: + description: type 'null' + type: "null" + three: + description: type array including 'null' + type: + - string + - "null" + four: + description: array with no items + type: array + five: + description: singular example + type: string + examples: + - exampleValue + six: + description: exclusiveMinimum true + exclusiveMinimum: 10 + seven: + description: exclusiveMinimum false + minimum: 10 + eight: + description: exclusiveMaximum true + exclusiveMaximum: 20 + nine: + description: exclusiveMaximum false + maximum: 20 + ten: + description: nullable string + type: + - string + - "null" + eleven: + description: x-nullable string + type: + - string + - "null" + twelve: + description: file/binary diff --git a/tests/v3.1/test.js b/tests/v3.1/test.js index 77d62cb02f..43f7e80588 100644 --- a/tests/v3.1/test.js +++ b/tests/v3.1/test.js @@ -6,8 +6,6 @@ const dialect = require("../../schemas/v3.1/dialect/base.schema.json"); const vocabulary = require("../../schemas/v3.1/meta/base.schema.json"); -const testSuitePath = `${__dirname}/../openapi3-examples/3.1`; - JsonSchema.setMetaOutputFormat(JsonSchema.BASIC); //JsonSchema.setShouldMetaValidate(false); @@ -20,10 +18,10 @@ before(async () => { }); describe("Pass", () => { - fs.readdirSync(`${testSuitePath}/pass`, { withFileTypes: true }) + fs.readdirSync(`${__dirname}/pass`, { withFileTypes: true }) .filter((entry) => entry.isFile() && /\.yaml$/.test(entry.name)) .forEach((entry) => { - const file = `${testSuitePath}/pass/${entry.name}`; + const file = `${__dirname}/pass/${entry.name}`; it(entry.name, async () => { const instance = yaml.parse(fs.readFileSync(file, "utf8")); @@ -35,10 +33,10 @@ describe("Pass", () => { }); describe("Fail", () => { - fs.readdirSync(`${testSuitePath}/fail`, { withFileTypes: true }) + fs.readdirSync(`${__dirname}/fail`, { withFileTypes: true }) .filter((entry) => entry.isFile() && /\.yaml$/.test(entry.name)) .forEach((entry) => { - const file = `${testSuitePath}/fail/${entry.name}`; + const file = `${__dirname}/fail/${entry.name}`; it(entry.name, async () => { const instance = yaml.parse(fs.readFileSync(file, "utf8"));