From 979384c6037a263816fb325db079ef989659fe47 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/schema.yaml | 102 +++++++++++++++++- 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 | 6 ++ tests/v1.0/fail/info-missing-title.yaml | 4 + tests/v1.0/fail/info-missing-version.yaml | 4 + tests/v1.0/fail/invalid-overlay-version.yaml | 5 + ...ns-array-modification-example-remove.yaml} | 0 ...ns-array-modification-example-update.yaml} | 0 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 ++ 20 files changed, 182 insertions(+), 4 deletions(-) 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-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/schema.yaml b/schemas/v1.0/schema.yaml index 96196d5..23eb692 100644 --- a/schemas/v1.0/schema.yaml +++ b/schemas/v1.0/schema.yaml @@ -1,5 +1,101 @@ -$id: https://spec.openapis.org/overlay/1.0/schema/WORK-IN-PROGRESS +$id: https://spec.openapis.org/overlay/1.0/schema/2024-10-17 $schema: https://json-schema.org/draft/2020-12/schema -description: The description of Overlay v1.0.x documents - +description: The description of OpenAPI Initiative Overlay v1.0.0 documents + without schema validation, as defined by + https://spec.openapis.org/overlay/v1.0.0 type: object +$comment: https://spec.openapis.org/overlay/v1.0.0#overlay-object +properties: + overlay: + description: The version number of the Overlay Specification + 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: + $comment: https://spec.openapis.org/overlay/v1.0.0#info-object + description: Provides metadata about the Overlay description + type: object + properties: + title: + description: A human readable title of the Overlay Description + type: string + version: + description: The version identifier of the Overlay document (which is distinct + from the Overlay Specification version) + type: string + required: + - title + - version + $ref: "#/$defs/specification-extensions" + unevaluatedProperties: false + action-object: + $comment: https://spec.openapis.org/overlay/v1.0.0#action-object + description: This object represents one or more changes to be applied to the + target document at the location defined by the target JSONPath expression. + properties: + target: + description: A JSONPath expression selecting nodes in the target document + type: string + pattern: ^\$[.\[]?.*$ + description: + description: A description of the action. [[CommonMark]] syntax MAY be used for + rich text representation. + type: string + update: + description: If the target selects an object node, the value of this field + MUST be an object with the properties and values to merge with the + node. If the target selects an array, the value of this field MUST + be an entry to append to the array. + type: + - string + - boolean + - object + - array + - number + - "null" + remove: + description: A boolean value that indicates that the target object is to be + removed from the the map or array it is contained in + type: boolean + default: false + allOf: + - description: The `update` field has no impact if the `remove` field of this + action object is true. + if: + properties: + remove: + const: true + required: + - remove + then: + not: + required: + - update + required: + - target + $ref: "#/$defs/specification-extensions" + unevaluatedProperties: false + specification-extensions: + $comment: https://spec.openapis.org/overlay/v1.0.0#specification-extensions + description: While the Overlay Specification tries to accommodate most use + cases, additional data can be added to extend the specification at certain + points + patternProperties: + ^x-: true 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..c1c00b1 --- /dev/null +++ b/tests/v1.0/fail/extends-invalid-type.yaml @@ -0,0 +1,6 @@ +overlay: 1.0.0 +info: + title: Invalid `extends` type + version: 1.0.0 +extends: {} +actions: [] 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..00e5b3b --- /dev/null +++ b/tests/v1.0/fail/info-missing-title.yaml @@ -0,0 +1,4 @@ +overlay: 1.0.0 +info: + version: 1.0.0 +actions: [] 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..96cbbf5 --- /dev/null +++ b/tests/v1.0/fail/info-missing-version.yaml @@ -0,0 +1,4 @@ +overlay: 1.0.0 +info: + title: Missing Info version +actions: [] 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..585a7ed --- /dev/null +++ b/tests/v1.0/fail/invalid-overlay-version.yaml @@ -0,0 +1,5 @@ +overlay: 2 +info: + title: Invalid Overlay version + version: 1.0.0 +actions: [] 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-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: {}