From 5517ebc6c1c4d344536267df04795d8872ac7e3d Mon Sep 17 00:00:00 2001 From: Jeremy Fiel <32110157+jeremyfiel@users.noreply.github.com> Date: Tue, 22 Oct 2024 16:35:57 +0000 Subject: [PATCH] feat(test): add schema tests and schema --- schemas/v1.0/readme.md | 36 ++++++++++ schemas/v1.0/schema.yaml | 71 ++++++++++++++++++- .../fail/actions-invalid-description.yaml | 7 ++ tests/v1.0/fail/actions-invalid-target.yaml | 7 ++ tests/v1.0/fail/actions-minimal.yaml | 5 ++ tests/v1.0/fail/actions-missing-target.yaml | 6 ++ tests/v1.0/fail/actions-missing.yaml | 5 ++ .../fail/actions-no-update-with-remove.yaml | 9 +++ tests/v1.0/fail/actions-not-unique.yaml | 9 +++ tests/v1.0/fail/extends-invalid-type.yaml | 7 ++ tests/v1.0/fail/info-missing-title.yaml | 5 ++ tests/v1.0/fail/info-missing-version.yaml | 5 ++ tests/v1.0/fail/invalid-overlay-version.yaml | 6 ++ ...ns-array-modification-example-remove.yaml} | 0 ...ns-array-modification-example-update.yaml} | 0 tests/v1.0/pass/actions-description.yaml | 7 ++ tests/v1.0/pass/actions-extensions.yaml | 7 ++ ...> actions-structured-overlay-example.yaml} | 3 +- ... => actions-targeted-overlay-example.yaml} | 0 ...ample.yaml => actions-traits-example.yaml} | 0 ... => actions-wildcard-overlay-example.yaml} | 0 tests/v1.0/pass/info-extensions.yaml | 7 ++ tests/v1.0/pass/root-extensions.yaml | 7 ++ 23 files changed, 207 insertions(+), 2 deletions(-) create mode 100644 schemas/v1.0/readme.md create mode 100644 tests/v1.0/fail/actions-invalid-description.yaml create mode 100644 tests/v1.0/fail/actions-invalid-target.yaml create mode 100644 tests/v1.0/fail/actions-minimal.yaml create mode 100644 tests/v1.0/fail/actions-missing-target.yaml create mode 100644 tests/v1.0/fail/actions-missing.yaml create mode 100644 tests/v1.0/fail/actions-no-update-with-remove.yaml create mode 100644 tests/v1.0/fail/actions-not-unique.yaml create mode 100644 tests/v1.0/fail/extends-invalid-type.yaml create mode 100644 tests/v1.0/fail/info-missing-title.yaml create mode 100644 tests/v1.0/fail/info-missing-version.yaml create mode 100644 tests/v1.0/fail/invalid-overlay-version.yaml rename tests/v1.0/pass/{array-modification-example-remove.yaml => actions-array-modification-example-remove.yaml} (100%) rename tests/v1.0/pass/{array-modification-example-update.yaml => actions-array-modification-example-update.yaml} (100%) create mode 100644 tests/v1.0/pass/actions-description.yaml create mode 100644 tests/v1.0/pass/actions-extensions.yaml rename tests/v1.0/pass/{structured-overlay-example.yaml => actions-structured-overlay-example.yaml} (92%) rename tests/v1.0/pass/{targeted-overlay-example.yaml => actions-targeted-overlay-example.yaml} (100%) rename tests/v1.0/pass/{traits-example.yaml => actions-traits-example.yaml} (100%) rename tests/v1.0/pass/{wildcard-overlay-example.yaml => actions-wildcard-overlay-example.yaml} (100%) create mode 100644 tests/v1.0/pass/info-extensions.yaml create mode 100644 tests/v1.0/pass/root-extensions.yaml diff --git a/schemas/v1.0/readme.md b/schemas/v1.0/readme.md new file mode 100644 index 0000000..6a99c33 --- /dev/null +++ b/schemas/v1.0/readme.md @@ -0,0 +1,36 @@ +# OpenAPI Overlay 1.0.x JSON Schema + +Here you can find the JSON Schema for validating Overlays of versions 1.0.x. + +As a reminder, the JSON Schema is not the source of truth for the Specification. +In cases of conflicts between the Specification itself and the JSON Schema, the +Specification wins. Also, some Specification constraints cannot be represented +with the JSON Schema so it's highly recommended to employ other methods to +ensure compliance. + +The iteration version of the JSON Schema can be found in the `$id` field. +For example, the value of `$id: https://spec.openapis.org/overlay/1.0/schema/2024-10-17` means this iteration was created on October 17, 2024. + +## Contributing + +To submit improvements to the schema, modify the `schema.yaml` and add test cases for your changes. + +The TSC will then: +- Run tests on the updated schema +- Update the iteration version +- Publish the new version + +## Tests + +The [test suite](../../tests/v1.0) is part of this package. + +```bash +npm install +npm test +``` + +You can also validate a document individually. + +```bash +node scripts/validate.mjs path/to/document/to/validate.yaml +``` \ No newline at end of file diff --git a/schemas/v1.0/schema.yaml b/schemas/v1.0/schema.yaml index 96196d5..7364212 100644 --- a/schemas/v1.0/schema.yaml +++ b/schemas/v1.0/schema.yaml @@ -1,5 +1,74 @@ $id: https://spec.openapis.org/overlay/1.0/schema/WORK-IN-PROGRESS $schema: https://json-schema.org/draft/2020-12/schema description: The description of Overlay v1.0.x documents - type: object +properties: + overlay: + type: string + pattern: ^1\.0\.\d+$ + info: + $ref: "#/$defs/info-object" + extends: + type: string + format: uri-reference + actions: + type: array + minItems: 1 + uniqueItems: true + items: + $ref: "#/$defs/action-object" +required: + - overlay + - info + - actions +$ref: "#/$defs/specification-extensions" +unevaluatedProperties: false +$defs: + info-object: + type: object + properties: + title: + type: string + version: + type: string + required: + - title + - version + $ref: "#/$defs/specification-extensions" + unevaluatedProperties: false + action-object: + properties: + target: + type: string + pattern: ^\$ + description: + type: string + update: + type: + - string + - boolean + - object + - array + - number + - "null" + remove: + type: boolean + default: false + allOf: + - if: + properties: + remove: + const: true + required: + - remove + then: + not: + required: + - update + required: + - target + $ref: "#/$defs/specification-extensions" + unevaluatedProperties: false + specification-extensions: + patternProperties: + ^x-: true diff --git a/tests/v1.0/fail/actions-invalid-description.yaml b/tests/v1.0/fail/actions-invalid-description.yaml new file mode 100644 index 0000000..0564531 --- /dev/null +++ b/tests/v1.0/fail/actions-invalid-description.yaml @@ -0,0 +1,7 @@ +overlay: 1.0.0 +info: + title: Actions invalid description + version: 1.0.0 +actions: + - target: '$' # Root of document + description: 10 diff --git a/tests/v1.0/fail/actions-invalid-target.yaml b/tests/v1.0/fail/actions-invalid-target.yaml new file mode 100644 index 0000000..bfff4d8 --- /dev/null +++ b/tests/v1.0/fail/actions-invalid-target.yaml @@ -0,0 +1,7 @@ +overlay: 1.0.0 +info: + title: Invalid `target`, must begin with `$` + version: 1.0.0 +actions: + - target: info.description + update: An updated description diff --git a/tests/v1.0/fail/actions-minimal.yaml b/tests/v1.0/fail/actions-minimal.yaml new file mode 100644 index 0000000..97ba931 --- /dev/null +++ b/tests/v1.0/fail/actions-minimal.yaml @@ -0,0 +1,5 @@ +overlay: 1.0.0 +info: + title: Minimal actions + version: 1.0.0 +actions: [] diff --git a/tests/v1.0/fail/actions-missing-target.yaml b/tests/v1.0/fail/actions-missing-target.yaml new file mode 100644 index 0000000..a624df7 --- /dev/null +++ b/tests/v1.0/fail/actions-missing-target.yaml @@ -0,0 +1,6 @@ +overlay: 1.0.0 +info: + title: Missing actions `target` + version: 1.0.0 +actions: + - update: my description diff --git a/tests/v1.0/fail/actions-missing.yaml b/tests/v1.0/fail/actions-missing.yaml new file mode 100644 index 0000000..078b7c6 --- /dev/null +++ b/tests/v1.0/fail/actions-missing.yaml @@ -0,0 +1,5 @@ +overlay: 1.0.0 +info: + title: Missing `actions` + version: 1.0.0 +extends: '/openapi.yaml' diff --git a/tests/v1.0/fail/actions-no-update-with-remove.yaml b/tests/v1.0/fail/actions-no-update-with-remove.yaml new file mode 100644 index 0000000..d135587 --- /dev/null +++ b/tests/v1.0/fail/actions-no-update-with-remove.yaml @@ -0,0 +1,9 @@ +overlay: 1.0.0 +info: + title: No `update` with `remove` + version: 1.0.0 +actions: + - target: $.info + update: + description: An updated description + remove: true diff --git a/tests/v1.0/fail/actions-not-unique.yaml b/tests/v1.0/fail/actions-not-unique.yaml new file mode 100644 index 0000000..62256f8 --- /dev/null +++ b/tests/v1.0/fail/actions-not-unique.yaml @@ -0,0 +1,9 @@ +overlay: 1.0.0 +info: + title: Actions not unique + version: 1.0.0 +actions: + - target: '$.info.title' + update: 'My New title' + - target: '$.info.title' + update: 'My New title' diff --git a/tests/v1.0/fail/extends-invalid-type.yaml b/tests/v1.0/fail/extends-invalid-type.yaml new file mode 100644 index 0000000..0e6ab26 --- /dev/null +++ b/tests/v1.0/fail/extends-invalid-type.yaml @@ -0,0 +1,7 @@ +overlay: 1.0.0 +info: + title: Invalid `extends` type + version: 1.0.0 +extends: {} +actions: + - target: '$.' # Root of document diff --git a/tests/v1.0/fail/info-missing-title.yaml b/tests/v1.0/fail/info-missing-title.yaml new file mode 100644 index 0000000..a4e7f14 --- /dev/null +++ b/tests/v1.0/fail/info-missing-title.yaml @@ -0,0 +1,5 @@ +overlay: 1.0.0 +info: + version: 1.0.0 +actions: + - target: '$.' # Root of document diff --git a/tests/v1.0/fail/info-missing-version.yaml b/tests/v1.0/fail/info-missing-version.yaml new file mode 100644 index 0000000..41c90ca --- /dev/null +++ b/tests/v1.0/fail/info-missing-version.yaml @@ -0,0 +1,5 @@ +overlay: 1.0.0 +info: + title: Missing Info version +actions: + - target: '$.' # Root of document diff --git a/tests/v1.0/fail/invalid-overlay-version.yaml b/tests/v1.0/fail/invalid-overlay-version.yaml new file mode 100644 index 0000000..8d50cda --- /dev/null +++ b/tests/v1.0/fail/invalid-overlay-version.yaml @@ -0,0 +1,6 @@ +overlay: 2 +info: + title: Invalid Overlay version + version: 1.0.0 +actions: + - target: '$.' # Root of document diff --git a/tests/v1.0/pass/array-modification-example-remove.yaml b/tests/v1.0/pass/actions-array-modification-example-remove.yaml similarity index 100% rename from tests/v1.0/pass/array-modification-example-remove.yaml rename to tests/v1.0/pass/actions-array-modification-example-remove.yaml diff --git a/tests/v1.0/pass/array-modification-example-update.yaml b/tests/v1.0/pass/actions-array-modification-example-update.yaml similarity index 100% rename from tests/v1.0/pass/array-modification-example-update.yaml rename to tests/v1.0/pass/actions-array-modification-example-update.yaml diff --git a/tests/v1.0/pass/actions-description.yaml b/tests/v1.0/pass/actions-description.yaml new file mode 100644 index 0000000..a15c94e --- /dev/null +++ b/tests/v1.0/pass/actions-description.yaml @@ -0,0 +1,7 @@ +overlay: 1.0.0 +info: + title: Actions Description + version: 1.0.0 +actions: + - target: '$' # Root of document + description: this is an action description diff --git a/tests/v1.0/pass/actions-extensions.yaml b/tests/v1.0/pass/actions-extensions.yaml new file mode 100644 index 0000000..206de4b --- /dev/null +++ b/tests/v1.0/pass/actions-extensions.yaml @@ -0,0 +1,7 @@ +overlay: 1.0.0 +info: + title: Actions Extensions + version: 1.0.0 +actions: + - target: '$' # Root of document + x-myActionsExtension: {} diff --git a/tests/v1.0/pass/structured-overlay-example.yaml b/tests/v1.0/pass/actions-structured-overlay-example.yaml similarity index 92% rename from tests/v1.0/pass/structured-overlay-example.yaml rename to tests/v1.0/pass/actions-structured-overlay-example.yaml index 2f50dee..054b901 100644 --- a/tests/v1.0/pass/structured-overlay-example.yaml +++ b/tests/v1.0/pass/actions-structured-overlay-example.yaml @@ -2,6 +2,7 @@ overlay: 1.0.0 info: title: Structured Overlay version: 1.0.0 +extends: '/openapi.yaml' actions: - target: '$' # Root of document update: @@ -18,4 +19,4 @@ actions: summary: 'Retrieve a list of pets' x-rate-limit: 100 components: - tags: + tags: [] diff --git a/tests/v1.0/pass/targeted-overlay-example.yaml b/tests/v1.0/pass/actions-targeted-overlay-example.yaml similarity index 100% rename from tests/v1.0/pass/targeted-overlay-example.yaml rename to tests/v1.0/pass/actions-targeted-overlay-example.yaml diff --git a/tests/v1.0/pass/traits-example.yaml b/tests/v1.0/pass/actions-traits-example.yaml similarity index 100% rename from tests/v1.0/pass/traits-example.yaml rename to tests/v1.0/pass/actions-traits-example.yaml diff --git a/tests/v1.0/pass/wildcard-overlay-example.yaml b/tests/v1.0/pass/actions-wildcard-overlay-example.yaml similarity index 100% rename from tests/v1.0/pass/wildcard-overlay-example.yaml rename to tests/v1.0/pass/actions-wildcard-overlay-example.yaml diff --git a/tests/v1.0/pass/info-extensions.yaml b/tests/v1.0/pass/info-extensions.yaml new file mode 100644 index 0000000..bcee3b6 --- /dev/null +++ b/tests/v1.0/pass/info-extensions.yaml @@ -0,0 +1,7 @@ +overlay: 1.0.0 +info: + title: Info Extensions + version: 1.0.0 + x-myInfoExtension: {} +actions: + - target: '$' # Root of document diff --git a/tests/v1.0/pass/root-extensions.yaml b/tests/v1.0/pass/root-extensions.yaml new file mode 100644 index 0000000..e311b42 --- /dev/null +++ b/tests/v1.0/pass/root-extensions.yaml @@ -0,0 +1,7 @@ +overlay: 1.0.0 +info: + title: Root Extensions + version: 1.0.0 +actions: + - target: '$' # Root of document +x-myExtension: {}