From 4ccdf0df4f464a0c5850d300ff094e98f397e7f1 Mon Sep 17 00:00:00 2001 From: Ralf Handl Date: Tue, 12 Aug 2025 10:29:42 +0200 Subject: [PATCH] schema tests: 100% statement coverage --- tests/schema/pass/link-object-examples.yaml | 4 ++++ ...hema-object-deprecated-example-keyword.yaml | 18 ++++++++++++++++++ .../schema/pass/specification-extensions.yaml | 6 ++++++ tests/schema/schema.test.mjs | 18 ++++++++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 tests/schema/pass/schema-object-deprecated-example-keyword.yaml create mode 100644 tests/schema/pass/specification-extensions.yaml diff --git a/tests/schema/pass/link-object-examples.yaml b/tests/schema/pass/link-object-examples.yaml index 92142a94a6..b7d8e737ad 100644 --- a/tests/schema/pass/link-object-examples.yaml +++ b/tests/schema/pass/link-object-examples.yaml @@ -45,6 +45,10 @@ paths: operationRef: https://na2.gigantic-server.com/#/paths/~12.0~1repositories~1%7Busername%7D/get parameters: username: $response.body#/username + withBody: + operationId: queryUserWithBody + requestBody: + userId: $request.path.id # the path item of the linked operation /users/{userid}/address: parameters: diff --git a/tests/schema/pass/schema-object-deprecated-example-keyword.yaml b/tests/schema/pass/schema-object-deprecated-example-keyword.yaml new file mode 100644 index 0000000000..f66640f4c3 --- /dev/null +++ b/tests/schema/pass/schema-object-deprecated-example-keyword.yaml @@ -0,0 +1,18 @@ +openapi: 3.1.0 +info: + title: API + version: 1.0.0 +paths: + /user: + parameters: + - in: query + name: example + schema: + # Allow an arbitrary JSON object to keep + # the example simple + type: object + # DEPRECATED: don't use example keyword inside Schema Object + example: { + "numbers": [1, 2], + "flag": null + } diff --git a/tests/schema/pass/specification-extensions.yaml b/tests/schema/pass/specification-extensions.yaml new file mode 100644 index 0000000000..3d63a5f148 --- /dev/null +++ b/tests/schema/pass/specification-extensions.yaml @@ -0,0 +1,6 @@ +openapi: 3.1.0 +info: + title: API + version: 1.0.0 +paths: {} +x-tensions: specification extensions are prefixed with `x-` diff --git a/tests/schema/schema.test.mjs b/tests/schema/schema.test.mjs index e7b84f0a74..ba82a55a5b 100644 --- a/tests/schema/schema.test.mjs +++ b/tests/schema/schema.test.mjs @@ -14,6 +14,24 @@ await registerSchema("./src/schemas/validation/schema.yaml"); const fixtures = './tests/schema'; describe("v3.1", () => { + test("schema.yaml schema test", async () => { + // Files in the pass/fail folders get run against schema-base.yaml. + // This instance is instead run against schema.yaml. + const oad = { + openapi: "3.1.0", + info: { + title: "API", + version: "1.0.0" + }, + components: { + schemas: { + foo: {} + } + } + }; + await expect(oad).to.matchJsonSchema("./src/schemas/validation/schema.yaml"); // <-- "schema.yaml" instead of "schema-base.yaml" + }); + describe("Pass", () => { readdirSync(`${fixtures}/pass`, { withFileTypes: true }) .filter((entry) => entry.isFile() && /\.yaml$/.test(entry.name))