From dd17f32e7c610b9943a8e863130840e6b9e3331f Mon Sep 17 00:00:00 2001 From: tatomyr Date: Sun, 6 Oct 2024 19:42:59 +0300 Subject: [PATCH] remove $schema keyword; describe X-Type with X-Type itself; resolve external $refs --- README.md | 46 +- .../__tests__/__snapshots__/e2e.test.js.snap | 880 +++++++++++++++--- applications/__tests__/adapter.test.js | 6 - applications/__tests__/e2e.test.js | 18 +- applications/__tests__/resolver.test.js | 6 +- applications/json-schema-adapter.js | 2 +- applications/resources/external-refs.yaml | 6 + .../resources/openapi-literal-schema.yaml | 37 - .../resources/openapi-with-external-refs.yaml | 37 + applications/resources/openapi-with-refs.yaml | 2 +- .../x-types-described-with-x-types.yaml | 50 + applications/x-types-adapter.js | 3 - applications/x-types-plugin.js | 4 - applications/x-types-resolver.js | 7 +- package-lock.json | 26 +- package.json | 4 +- x-types.yaml | 21 + 17 files changed, 913 insertions(+), 242 deletions(-) create mode 100644 applications/resources/external-refs.yaml delete mode 100644 applications/resources/openapi-literal-schema.yaml create mode 100644 applications/resources/openapi-with-external-refs.yaml create mode 100644 applications/resources/x-types-described-with-x-types.yaml create mode 100644 x-types.yaml diff --git a/README.md b/README.md index 79df887..a8a5d72 100644 --- a/README.md +++ b/README.md @@ -3,20 +3,21 @@ **JSON X-Type** is a data type format for describing JSON-like structures in a simple and natural way. Any [valid JSON](https://www.json.org/) can be validated against a **JSON X-Type** definition. +**JSON X-Type** can be described by itself ([🔗](./x-types.yaml)). + ## Reserved Keywords -| Keyword | Description | Usage | -| -------------------------------- | ------------------------------------------------------------------- | ---------- | -| string | String type. | key, value | -| number | Number type. | value | -| boolean | Boolean type. | value | -| `null` | The `null` value. (Note: The string "null" has no special meaning.) | value | -| undefined | Indicates that the value is not set. | value | -| array | Array generic. | key | -| any | Any value (not validated). | value | -| $and ([🔗](#types-combining)) | Represents the combination of array members. | key | -| $ref ([🔗](#references)) | Reference to another **JSON X-Type**. | key | -| $schema ([🔗](#literal-schemas)) | A literal JSON Schema definition. | key | +| Keyword | Description | Usage | +| ----------------------------- | ------------------------------------------------------------------- | ---------- | +| string | String type. | key, value | +| number | Number type. | value | +| boolean | Boolean type. | value | +| `null` | The `null` value. (Note: The string "null" has no special meaning.) | value | +| undefined | Indicates that the value is not set. | value | +| array | Array generic. | key | +| any | Any value (not validated). | value | +| $and ([🔗](#types-combining)) | Represents the combination of array members. | key | +| $ref ([🔗](#references)) | Reference to another **JSON X-Type**. | key | The list can be extended with other `$`-prefixed keywords. So it's a good idea to escape any custom keys that start with `$` using the `$literal` prefix ([🔗](#literals-escaping)). @@ -103,8 +104,6 @@ Note that it doesn't make sense to combine primitive types or objects that have The above example results in `foo` being both `string` and `number`, which is effectively equivalent to TypeScript's `never` type. -The `$schema` property also cannot be combined using the `$and` notation ([🔗](#literal-schemas)). - Impossible combinations should result in the `undefined` type. ## Literals Escaping @@ -132,7 +131,7 @@ It is possible to refer to other **JSON X-Types** using the [JSON Pointer](https ```json { "foo": {"$ref": "#/bar"}, - "bar": "["string", "number", "boolean"]" + "bar": ["string", "number", "boolean"] } ``` @@ -152,23 +151,6 @@ Alternatively, the `$ref` keyword can be used as a prefix which is easier to wri If a reference cannot be resolved, it should be treated as `any`. -## Literal Schemas - -If something cannot be expressed in terms of **JSON X-Type**, it should go under this key: - -```json -{ - "$schema": { - "type": "string", - "contentMediaType": "application/jwt", - "contentSchema": {"type": "array"} - } -} -``` - -Note that it's not possible to use **JSON X-Types** inside `$schema`. -Additionally, `$schema` cannot be used inside `$and` operators ([🔗](#types-combining)). - ## Types Extending Possible extensions are described [here](./extensions.md). diff --git a/applications/__tests__/__snapshots__/e2e.test.js.snap b/applications/__tests__/__snapshots__/e2e.test.js.snap index 3a0e352..b6a665c 100644 --- a/applications/__tests__/__snapshots__/e2e.test.js.snap +++ b/applications/__tests__/__snapshots__/e2e.test.js.snap @@ -314,65 +314,6 @@ components: {} exports[`bundle > do not bundle an openapi with type never 1`] = `undefined`; -exports[`bundle > openapi that contains literal $schema 1`] = ` -"openapi: 3.1.0 -info: - title: Test - version: 1.0.0 -paths: - /test: - get: - responses: - '200': - description: Test literal $schema - content: - application/json: - x-type: - $schema: - type: string - example: Should pass. - schema: - type: string - application/problems+json: - x-type: - WrongSchemaFormat: - $schema: - type: object - properties: - Correct: - type: string - Wrong: - type: wrong! - unexpected-property: Should fail! - Referenced: - $schema: - $ref: '#/components/schemas/Foo' - schema: - type: object - properties: - WrongSchemaFormat: - type: object - properties: - Correct: - type: string - Wrong: - type: wrong! - unexpected-property: Should fail! - Referenced: - type: string - not-expected: Should fail! - required: - - WrongSchemaFormat - - Referenced - additionalProperties: false -components: - schemas: - Foo: - type: string - not-expected: Should fail! -" -`; - exports[`bundle > preserve existing schemas if preserveExistingSchemas is true 1`] = ` "openapi: 3.1.0 info: @@ -482,7 +423,7 @@ components: exports[`bundle > resolve different type of $refs on different levels and ignore wrong $refs (with --force) when bundling 1`] = ` "openapi: 3.1.0 info: - title: Test + title: Test internal $refs version: 1.0.0 paths: /test: @@ -983,76 +924,6 @@ run \`redocly lint --generate-ignore-file\` to add all problems to the ignore fi " `; -exports[`lint > openapi that contains literal $schema 1`] = ` -"validating applications/resources/openapi-literal-schema.yaml... -[1] applications/resources/openapi-literal-schema.yaml:18:13 at #/paths/~1test/get/responses/200/content/application~1problems+json/schema/properties/WrongSchemaFormat/unexpected-property - -Property \`unexpected-property\` is not expected here. - -16 | example: Should pass. -17 | -18 | application/problems+json: - | ^^^^^^^^^^^^^^^^^^^^^^^^^ -19 | x-type: -20 | WrongSchemaFormat: - -Error was generated by the spec rule. - - -[2] applications/resources/openapi-literal-schema.yaml:19:15 at #/paths/~1test/get/responses/200/content/application~1problems+json/schema/properties/WrongSchemaFormat/properties/Wrong/type - -\`type\` can be one of the following only: "object", "array", "string", "number", "integer", "boolean", "null". - -17 | -18 | application/problems+json: -19 | x-type: - | ^^^^^^^ -20 | WrongSchemaFormat: - | ^^^^^^^^^^^^^^^^^^ - … | < 10 more lines > -31 | $ref: '#/components/schemas/Foo' - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -32 | -33 | components: - -Error was generated by the spec rule. - - -[3] applications/resources/openapi-literal-schema.yaml:18:13 at #/paths/~1test/get/responses/200/content/application~1problems+json/schema/properties/Referenced/not-expected - -Property \`not-expected\` is not expected here. - -16 | example: Should pass. -17 | -18 | application/problems+json: - | ^^^^^^^^^^^^^^^^^^^^^^^^^ -19 | x-type: -20 | WrongSchemaFormat: - -Error was generated by the spec rule. - - -[4] applications/resources/openapi-literal-schema.yaml:37:7 at #/components/schemas/Foo/not-expected - -Property \`not-expected\` is not expected here. - -35 | Foo: -36 | type: string -37 | not-expected: Should fail! - | ^^^^^^^^^^^^ -38 | - -Error was generated by the spec rule. - - -applications/resources/openapi-literal-schema.yaml: validated in ms - -❌ Validation failed with 4 errors. -run \`redocly lint --generate-ignore-file\` to add all problems to the ignore file. - -" -`; - exports[`lint > openapi that contains wrong and correct $ands 1`] = ` "validating applications/resources/openapi-and.yaml... ERROR! Expected an array but got: @@ -1258,6 +1129,81 @@ run \`redocly lint --generate-ignore-file\` to add all problems to the ignore fi " `; +exports[`lint > openapi with external $refs 1`] = ` +"validating applications/resources/openapi-with-external-refs.yaml... +WARNING! Circular reference detected: #/Bukh +ERROR! Cannot resolve $ref: +external-refs.yaml#/NotExistingField +[1] applications/resources/openapi-with-external-refs.yaml:23:23 at #/paths/~1test/get/responses/200/content/application~1json/examples/Incorrect/value/0 + +Example value must conform to the schema: \`0\` property type must be boolean. + +21 | Incorrect: +22 | value: +23 | - wrong, should be a boolean value + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +24 | - false # this is still correct +25 | 404: + +referenced from applications/resources/openapi-with-external-refs.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json + +Error was generated by the no-invalid-media-type-examples rule. + + +[2] applications/resources/openapi-with-external-refs.yaml:23:23 at #/paths/~1test/get/responses/200/content/application~1json/examples/Incorrect/value/0 + +Example value must conform to the schema: \`0\` property type must be array. + +21 | Incorrect: +22 | value: +23 | - wrong, should be a boolean value + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +24 | - false # this is still correct +25 | 404: + +referenced from applications/resources/openapi-with-external-refs.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json + +Error was generated by the no-invalid-media-type-examples rule. + + +[3] applications/resources/openapi-with-external-refs.yaml:23:23 at #/paths/~1test/get/responses/200/content/application~1json/examples/Incorrect/value/0 + +Example value must conform to the schema: \`0\` property must match a schema in anyOf. + +21 | Incorrect: +22 | value: +23 | - wrong, should be a boolean value + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +24 | - false # this is still correct +25 | 404: + +referenced from applications/resources/openapi-with-external-refs.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json + +Error was generated by the no-invalid-media-type-examples rule. + + +[4] applications/resources/openapi-with-external-refs.yaml:31:19 at #/paths/~1test/get/responses/404/content/application~1json/x-type/AWrongRef + +Can't resolve $ref + +29 | x-type: +30 | AWrongRef: +31 | $ref: external-refs.yaml#/NotExistingField + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +32 | example: +33 | AWrongRef: Accepts anything + +Error was generated by the no-unresolved-refs rule. + + +applications/resources/openapi-with-external-refs.yaml: validated in ms + +❌ Validation failed with 4 errors. +run \`redocly lint --generate-ignore-file\` to add all problems to the ignore file. + +" +`; + exports[`lint > openapi with mixed types 1`] = ` "validating applications/resources/openapi-mixed-types.yaml... [1] applications/resources/openapi-mixed-types.yaml:9:7 at #/components/x-types/MixedTypeArray/neighbour @@ -1368,3 +1314,677 @@ run \`redocly lint --generate-ignore-file\` to add all problems to the ignore fi " `; + +exports[`lint > x-types described with x-types themselves 1`] = ` +"validating applications/resources/x-types-described-with-x-types.yaml... +WARNING! Circular reference detected: #/Or +WARNING! Circular reference detected: #/Or +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/Or +WARNING! Circular reference detected: #/Or +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/Or +WARNING! Circular reference detected: #/Or +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/Or +WARNING! Circular reference detected: #/Or +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/Or +WARNING! Circular reference detected: #/Or +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/Or +WARNING! Circular reference detected: #/Or +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/Or +WARNING! Circular reference detected: #/Or +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/Or +WARNING! Circular reference detected: #/And +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/Array +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/XType +WARNING! Circular reference detected: #/Record +[1] applications/resources/x-types-described-with-x-types.yaml:18:21 at #/paths/~1test/get/responses/200/content/application~1json/examples/WrongAndUsage/value + +Example value must conform to the schema: type must be string. + +16 | WrongAndUsage: +17 | value: +18 | $and: + | ^^^^^ +19 | - {Az: number} + | ^^^^^^^^^^^^^^ +20 | - {Bukh: string} + | ^^^^^^^^^^^^^^^^ +21 | wrong: should not be defined along the \`$and\` keyword! + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +22 | CorrectAndUsage: +23 | value: + +referenced from applications/resources/x-types-described-with-x-types.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json + +Error was generated by the no-invalid-media-type-examples rule. + + +[2] applications/resources/x-types-described-with-x-types.yaml:18:21 at #/paths/~1test/get/responses/200/content/application~1json/examples/WrongAndUsage/value + +Example value must conform to the schema: type must be number. + +16 | WrongAndUsage: +17 | value: +18 | $and: + | ^^^^^ +19 | - {Az: number} + | ^^^^^^^^^^^^^^ +20 | - {Bukh: string} + | ^^^^^^^^^^^^^^^^ +21 | wrong: should not be defined along the \`$and\` keyword! + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +22 | CorrectAndUsage: +23 | value: + +referenced from applications/resources/x-types-described-with-x-types.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json + +Error was generated by the no-invalid-media-type-examples rule. + + +[3] applications/resources/x-types-described-with-x-types.yaml:18:21 at #/paths/~1test/get/responses/200/content/application~1json/examples/WrongAndUsage/value + +Example value must conform to the schema: type must be boolean. + +16 | WrongAndUsage: +17 | value: +18 | $and: + | ^^^^^ +19 | - {Az: number} + | ^^^^^^^^^^^^^^ +20 | - {Bukh: string} + | ^^^^^^^^^^^^^^^^ +21 | wrong: should not be defined along the \`$and\` keyword! + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +22 | CorrectAndUsage: +23 | value: + +referenced from applications/resources/x-types-described-with-x-types.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json + +Error was generated by the no-invalid-media-type-examples rule. + + +[4] applications/resources/x-types-described-with-x-types.yaml:18:21 at #/paths/~1test/get/responses/200/content/application~1json/examples/WrongAndUsage/value + +Example value must conform to the schema: type must be null. + +16 | WrongAndUsage: +17 | value: +18 | $and: + | ^^^^^ +19 | - {Az: number} + | ^^^^^^^^^^^^^^ +20 | - {Bukh: string} + | ^^^^^^^^^^^^^^^^ +21 | wrong: should not be defined along the \`$and\` keyword! + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +22 | CorrectAndUsage: +23 | value: + +referenced from applications/resources/x-types-described-with-x-types.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json + +Error was generated by the no-invalid-media-type-examples rule. + + +[5] applications/resources/x-types-described-with-x-types.yaml:18:21 at #/paths/~1test/get/responses/200/content/application~1json/examples/WrongAndUsage/value + +Example value must conform to the schema: type must be array. + +16 | WrongAndUsage: +17 | value: +18 | $and: + | ^^^^^ +19 | - {Az: number} + | ^^^^^^^^^^^^^^ +20 | - {Bukh: string} + | ^^^^^^^^^^^^^^^^ +21 | wrong: should not be defined along the \`$and\` keyword! + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +22 | CorrectAndUsage: +23 | value: + +referenced from applications/resources/x-types-described-with-x-types.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json + +Error was generated by the no-invalid-media-type-examples rule. + + +[6] applications/resources/x-types-described-with-x-types.yaml:21:21 at #/paths/~1test/get/responses/200/content/application~1json/examples/WrongAndUsage/value/wrong + +Example value must conform to the schema: must NOT have additional properties \`wrong\`. + +19 | - {Az: number} +20 | - {Bukh: string} +21 | wrong: should not be defined along the \`$and\` keyword! + | ^^^^^ +22 | CorrectAndUsage: +23 | value: + +referenced from applications/resources/x-types-described-with-x-types.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json + +Error was generated by the no-invalid-media-type-examples rule. + + +[7] applications/resources/x-types-described-with-x-types.yaml:18:21 at #/paths/~1test/get/responses/200/content/application~1json/examples/WrongAndUsage/value + +Example value must conform to the schema: must have required property 'array'. + +16 | WrongAndUsage: +17 | value: +18 | $and: + | ^^^^^ +19 | - {Az: number} + | ^^^^^^^^^^^^^^ +20 | - {Bukh: string} + | ^^^^^^^^^^^^^^^^ +21 | wrong: should not be defined along the \`$and\` keyword! + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +22 | CorrectAndUsage: +23 | value: + +referenced from applications/resources/x-types-described-with-x-types.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json + +Error was generated by the no-invalid-media-type-examples rule. + + +[8] applications/resources/x-types-described-with-x-types.yaml:18:21 at #/paths/~1test/get/responses/200/content/application~1json/examples/WrongAndUsage/value/$and + +Example value must conform to the schema: must NOT have additional properties \`$and\`. + +16 | WrongAndUsage: +17 | value: +18 | $and: + | ^^^^ +19 | - {Az: number} +20 | - {Bukh: string} + +referenced from applications/resources/x-types-described-with-x-types.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json + +Error was generated by the no-invalid-media-type-examples rule. + + +[9] applications/resources/x-types-described-with-x-types.yaml:21:21 at #/paths/~1test/get/responses/200/content/application~1json/examples/WrongAndUsage/value/wrong + +Example value must conform to the schema: must NOT have additional properties \`wrong\`. + +19 | - {Az: number} +20 | - {Bukh: string} +21 | wrong: should not be defined along the \`$and\` keyword! + | ^^^^^ +22 | CorrectAndUsage: +23 | value: + +referenced from applications/resources/x-types-described-with-x-types.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json + +Error was generated by the no-invalid-media-type-examples rule. + + +[10] applications/resources/x-types-described-with-x-types.yaml:18:21 at #/paths/~1test/get/responses/200/content/application~1json/examples/WrongAndUsage/value/$and + +Example value must conform to the schema: must NOT have additional properties \`$and\`. + +16 | WrongAndUsage: +17 | value: +18 | $and: + | ^^^^ +19 | - {Az: number} +20 | - {Bukh: string} + +referenced from applications/resources/x-types-described-with-x-types.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json + +Error was generated by the no-invalid-media-type-examples rule. + + +[11] applications/resources/x-types-described-with-x-types.yaml:18:21 at #/paths/~1test/get/responses/200/content/application~1json/examples/WrongAndUsage/value + +Example value must conform to the schema: must match a schema in anyOf. + +16 | WrongAndUsage: +17 | value: +18 | $and: + | ^^^^^ +19 | - {Az: number} + | ^^^^^^^^^^^^^^ +20 | - {Bukh: string} + | ^^^^^^^^^^^^^^^^ +21 | wrong: should not be defined along the \`$and\` keyword! + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +22 | CorrectAndUsage: +23 | value: + +referenced from applications/resources/x-types-described-with-x-types.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json + +Error was generated by the no-invalid-media-type-examples rule. + + +[12] applications/resources/x-types-described-with-x-types.yaml:29:21 at #/paths/~1test/get/responses/200/content/application~1json/examples/WrongArrayUsage/value + +Example value must conform to the schema: type must be string. + +27 | WrongArrayUsage: +28 | value: +29 | array: string + | ^^^^^^^^^^^^^ +30 | wrong: should not ne defined along the \`array\` keyword! + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +31 | CorrectArrayUsage: +32 | value: + +referenced from applications/resources/x-types-described-with-x-types.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json + +Error was generated by the no-invalid-media-type-examples rule. + + +[13] applications/resources/x-types-described-with-x-types.yaml:29:21 at #/paths/~1test/get/responses/200/content/application~1json/examples/WrongArrayUsage/value + +Example value must conform to the schema: type must be number. + +27 | WrongArrayUsage: +28 | value: +29 | array: string + | ^^^^^^^^^^^^^ +30 | wrong: should not ne defined along the \`array\` keyword! + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +31 | CorrectArrayUsage: +32 | value: + +referenced from applications/resources/x-types-described-with-x-types.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json + +Error was generated by the no-invalid-media-type-examples rule. + + +[14] applications/resources/x-types-described-with-x-types.yaml:29:21 at #/paths/~1test/get/responses/200/content/application~1json/examples/WrongArrayUsage/value + +Example value must conform to the schema: type must be boolean. + +27 | WrongArrayUsage: +28 | value: +29 | array: string + | ^^^^^^^^^^^^^ +30 | wrong: should not ne defined along the \`array\` keyword! + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +31 | CorrectArrayUsage: +32 | value: + +referenced from applications/resources/x-types-described-with-x-types.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json + +Error was generated by the no-invalid-media-type-examples rule. + + +[15] applications/resources/x-types-described-with-x-types.yaml:29:21 at #/paths/~1test/get/responses/200/content/application~1json/examples/WrongArrayUsage/value + +Example value must conform to the schema: type must be null. + +27 | WrongArrayUsage: +28 | value: +29 | array: string + | ^^^^^^^^^^^^^ +30 | wrong: should not ne defined along the \`array\` keyword! + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +31 | CorrectArrayUsage: +32 | value: + +referenced from applications/resources/x-types-described-with-x-types.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json + +Error was generated by the no-invalid-media-type-examples rule. + + +[16] applications/resources/x-types-described-with-x-types.yaml:29:21 at #/paths/~1test/get/responses/200/content/application~1json/examples/WrongArrayUsage/value + +Example value must conform to the schema: type must be array. + +27 | WrongArrayUsage: +28 | value: +29 | array: string + | ^^^^^^^^^^^^^ +30 | wrong: should not ne defined along the \`array\` keyword! + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +31 | CorrectArrayUsage: +32 | value: + +referenced from applications/resources/x-types-described-with-x-types.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json + +Error was generated by the no-invalid-media-type-examples rule. + + +[17] applications/resources/x-types-described-with-x-types.yaml:29:21 at #/paths/~1test/get/responses/200/content/application~1json/examples/WrongArrayUsage/value + +Example value must conform to the schema: must have required property '$and'. + +27 | WrongArrayUsage: +28 | value: +29 | array: string + | ^^^^^^^^^^^^^ +30 | wrong: should not ne defined along the \`array\` keyword! + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +31 | CorrectArrayUsage: +32 | value: + +referenced from applications/resources/x-types-described-with-x-types.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json + +Error was generated by the no-invalid-media-type-examples rule. + + +[18] applications/resources/x-types-described-with-x-types.yaml:29:21 at #/paths/~1test/get/responses/200/content/application~1json/examples/WrongArrayUsage/value/array + +Example value must conform to the schema: must NOT have additional properties \`array\`. + +27 | WrongArrayUsage: +28 | value: +29 | array: string + | ^^^^^ +30 | wrong: should not ne defined along the \`array\` keyword! +31 | CorrectArrayUsage: + +referenced from applications/resources/x-types-described-with-x-types.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json + +Error was generated by the no-invalid-media-type-examples rule. + + +[19] applications/resources/x-types-described-with-x-types.yaml:30:21 at #/paths/~1test/get/responses/200/content/application~1json/examples/WrongArrayUsage/value/wrong + +Example value must conform to the schema: must NOT have additional properties \`wrong\`. + +28 | value: +29 | array: string +30 | wrong: should not ne defined along the \`array\` keyword! + | ^^^^^ +31 | CorrectArrayUsage: +32 | value: + +referenced from applications/resources/x-types-described-with-x-types.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json + +Error was generated by the no-invalid-media-type-examples rule. + + +[20] applications/resources/x-types-described-with-x-types.yaml:30:21 at #/paths/~1test/get/responses/200/content/application~1json/examples/WrongArrayUsage/value/wrong + +Example value must conform to the schema: must NOT have additional properties \`wrong\`. + +28 | value: +29 | array: string +30 | wrong: should not ne defined along the \`array\` keyword! + | ^^^^^ +31 | CorrectArrayUsage: +32 | value: + +referenced from applications/resources/x-types-described-with-x-types.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json + +Error was generated by the no-invalid-media-type-examples rule. + + +[21] applications/resources/x-types-described-with-x-types.yaml:29:21 at #/paths/~1test/get/responses/200/content/application~1json/examples/WrongArrayUsage/value/array + +Example value must conform to the schema: must NOT have additional properties \`array\`. + +27 | WrongArrayUsage: +28 | value: +29 | array: string + | ^^^^^ +30 | wrong: should not ne defined along the \`array\` keyword! +31 | CorrectArrayUsage: + +referenced from applications/resources/x-types-described-with-x-types.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json + +Error was generated by the no-invalid-media-type-examples rule. + + +[22] applications/resources/x-types-described-with-x-types.yaml:29:21 at #/paths/~1test/get/responses/200/content/application~1json/examples/WrongArrayUsage/value + +Example value must conform to the schema: must match a schema in anyOf. + +27 | WrongArrayUsage: +28 | value: +29 | array: string + | ^^^^^^^^^^^^^ +30 | wrong: should not ne defined along the \`array\` keyword! + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +31 | CorrectArrayUsage: +32 | value: + +referenced from applications/resources/x-types-described-with-x-types.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json + +Error was generated by the no-invalid-media-type-examples rule. + + +applications/resources/x-types-described-with-x-types.yaml: validated in ms + +❌ Validation failed with 22 errors. +run \`redocly lint --generate-ignore-file\` to add all problems to the ignore file. + +" +`; diff --git a/applications/__tests__/adapter.test.js b/applications/__tests__/adapter.test.js index ec18ad0..33580b2 100644 --- a/applications/__tests__/adapter.test.js +++ b/applications/__tests__/adapter.test.js @@ -53,12 +53,6 @@ describe('adapter', () => { }) }) - test('literal $schema', () => { - expect(translateXTypeToSchema({$schema: {type: 'string'}})).toEqual({ - type: 'string', - }) - }) - test('arrays', () => { expect(translateXTypeToSchema({array: 'string'})).toEqual({ type: 'array', diff --git a/applications/__tests__/e2e.test.js b/applications/__tests__/e2e.test.js index 556db82..17d26a2 100644 --- a/applications/__tests__/e2e.test.js +++ b/applications/__tests__/e2e.test.js @@ -105,13 +105,6 @@ describe('bundle', () => { expect(stdout).toMatchSnapshot() }) - test('openapi that contains literal $schema', () => { - const {stdout} = runCommand( - 'redocly bundle applications/resources/openapi-literal-schema.yaml --config=applications/x-redocly.yaml' - ) - expect(stdout).toMatchSnapshot() - }) - test('generate x-types from JSON Schemas', () => { const {stdout} = runCommand( 'redocly bundle applications/resources/pets.yaml --config=applications/generate-x-types-redocly.yaml' @@ -173,9 +166,16 @@ describe('lint', () => { expect(stderr).toMatchSnapshot() }) - test('openapi that contains literal $schema', () => { + test('x-types described with x-types themselves', () => { + const {stderr} = runCommand( + 'redocly lint applications/resources/x-types-described-with-x-types.yaml --config=applications/x-redocly.yaml' + ) + expect(stripCWD(stderr)).toMatchSnapshot() + }) + + test('openapi with external $refs', () => { const {stderr} = runCommand( - 'redocly lint applications/resources/openapi-literal-schema.yaml --config=applications/x-redocly.yaml' + 'redocly lint applications/resources/openapi-with-external-refs.yaml --config=applications/x-redocly.yaml' ) expect(stripCWD(stderr)).toMatchSnapshot() }) diff --git a/applications/__tests__/resolver.test.js b/applications/__tests__/resolver.test.js index f2614ca..0150bfa 100644 --- a/applications/__tests__/resolver.test.js +++ b/applications/__tests__/resolver.test.js @@ -160,9 +160,13 @@ describe('resolver', () => { {string: {$ref: '#/Json'}}, {array: {$ref: '#/Json'}}, ], + location: {source: {absoluteRef: '#/Json'}}, } case '#/Record': - return {node: {string: {$ref: '#/Json'}}} + return { + node: {string: {$ref: '#/Json'}}, + location: {source: {absoluteRef: '#/Record'}}, + } default: throw new Error('Unknown $ref') } diff --git a/applications/json-schema-adapter.js b/applications/json-schema-adapter.js index 5aa2917..b662717 100644 --- a/applications/json-schema-adapter.js +++ b/applications/json-schema-adapter.js @@ -107,7 +107,7 @@ export function translateJSONSchemaToXType(schema, ctx) { return undefined } - return {$schema: schema} + return {$schema: schema} // FIXME: this is wrong. We simply wasn't able to translate the schema. Remove it later and replace with `undefined` or `any`. } function extractObjectLikeNode(schema, ctx) { diff --git a/applications/resources/external-refs.yaml b/applications/resources/external-refs.yaml new file mode 100644 index 0000000..e00c122 --- /dev/null +++ b/applications/resources/external-refs.yaml @@ -0,0 +1,6 @@ +Az: + array: + $ref: '#/Bukh' +Bukh: + - boolean + - $ref: '#/Az' diff --git a/applications/resources/openapi-literal-schema.yaml b/applications/resources/openapi-literal-schema.yaml deleted file mode 100644 index e8181d2..0000000 --- a/applications/resources/openapi-literal-schema.yaml +++ /dev/null @@ -1,37 +0,0 @@ -openapi: 3.1.0 -info: - title: Test - version: 1.0.0 -paths: - /test: - get: - responses: - 200: - description: Test literal $schema - content: - application/json: - x-type: - $schema: - type: string - example: Should pass. - - application/problems+json: - x-type: - WrongSchemaFormat: - $schema: - type: object - properties: - Correct: - type: string - Wrong: - type: wrong! - unexpected-property: Should fail! - Referenced: - $schema: - $ref: '#/components/schemas/Foo' - -components: - schemas: - Foo: - type: string - not-expected: Should fail! diff --git a/applications/resources/openapi-with-external-refs.yaml b/applications/resources/openapi-with-external-refs.yaml new file mode 100644 index 0000000..ff18265 --- /dev/null +++ b/applications/resources/openapi-with-external-refs.yaml @@ -0,0 +1,37 @@ +openapi: 3.1.0 +info: + title: Test external nested $refs + version: 1.0.0 +paths: + /test: + get: + responses: + 200: + description: An object with refs + content: + application/json: + x-type: + $ref: external-refs.yaml#/Az + examples: + Correct: + value: + - true + - false + - [false, true] + Incorrect: + value: + - wrong, should be a boolean value + - false # this is still correct + 404: + description: A wrong ref + content: + application/json: + x-type: + AWrongRef: + $ref: external-refs.yaml#/NotExistingField + example: + AWrongRef: Accepts anything +# TODO: investigate how does it works without referencing the external-refs.yaml in the components (compare to x-types-described-with-x-types.yaml) +# components: +# x-types: +# $ref: external-refs.yaml diff --git a/applications/resources/openapi-with-refs.yaml b/applications/resources/openapi-with-refs.yaml index 8c2e6e6..777a70f 100644 --- a/applications/resources/openapi-with-refs.yaml +++ b/applications/resources/openapi-with-refs.yaml @@ -1,6 +1,6 @@ openapi: 3.1.0 info: - title: Test + title: Test internal $refs version: 1.0.0 paths: /test: diff --git a/applications/resources/x-types-described-with-x-types.yaml b/applications/resources/x-types-described-with-x-types.yaml new file mode 100644 index 0000000..91b19c3 --- /dev/null +++ b/applications/resources/x-types-described-with-x-types.yaml @@ -0,0 +1,50 @@ +openapi: 3.1.0 +info: + title: Test X-Types described with X-Types + version: 1.0.0 +paths: + /test: + get: + responses: + 200: + description: Test. + content: + application/json: + x-type: + $ref: ../../x-types.yaml#/XType + examples: + WrongAndUsage: + value: + $and: + - {Az: number} + - {Bukh: string} + wrong: should not be defined along the `$and` keyword! + CorrectAndUsage: + value: + $and: + - {Az: number} + - {Bukh: string} + WrongArrayUsage: + value: + array: string + wrong: should not ne defined along the `array` keyword! + CorrectArrayUsage: + value: + array: string + CorrectPrimitive: + value: some-string-literal + CorrectRecord: + value: + Az: + Bukh: + Vidh: + Glagol: number + string: boolean + CorrectOr: + value: + - Az + - Bukh: any + +components: + x-types: + $ref: ../../x-types.yaml # needed for using $refs outside the main document diff --git a/applications/x-types-adapter.js b/applications/x-types-adapter.js index 452d0a8..a5037ac 100644 --- a/applications/x-types-adapter.js +++ b/applications/x-types-adapter.js @@ -179,9 +179,6 @@ export const translateXTypeToSchema = xType => { let patternProperties = {} let required = [] const {string, $descriptions, $schema, ...props} = xType - if ($schema) { - return $schema - } const additionalProperties = typeof string === 'undefined' ? false : translateXTypeToSchema(string) diff --git a/applications/x-types-plugin.js b/applications/x-types-plugin.js index 45cda9d..b00e8f4 100644 --- a/applications/x-types-plugin.js +++ b/applications/x-types-plugin.js @@ -35,10 +35,6 @@ const getType = value => { } if (isObject(value)) { - if (typeof value.$schema !== 'undefined') { - return {properties: {$schema: 'Schema'}} - } - if (typeof value.array !== 'undefined') { return 'XTypeArray' } diff --git a/applications/x-types-resolver.js b/applications/x-types-resolver.js index 70c7b7f..3e938f9 100644 --- a/applications/x-types-resolver.js +++ b/applications/x-types-resolver.js @@ -15,13 +15,14 @@ export const resolveAndMerge = (xType, ctx, parents = []) => { // Returning `any` to avoid circular references: return 'any' } - const resolved = ctx.resolve(xType).node - if (resolved === undefined) { + const resolved = ctx.resolve(xType, ctx._from) + if (resolved.node === undefined) { console.error('ERROR! Cannot resolve $ref:') console.error(xType.$ref) return 'any' } - return resolveAndMerge(resolved, ctx, [...parents, xType]) + ctx._from = resolved.location.source.absoluteRef // this is needed for resolving $refs outside the main document + return resolveAndMerge(resolved.node, ctx, [...parents, xType]) } // Handle AND types diff --git a/package-lock.json b/package-lock.json index d6c1df7..40bad37 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,8 +9,8 @@ "version": "0.0.2", "license": "ISC", "devDependencies": { - "@redocly/cli": "1.25.3", - "@redocly/openapi-core": "1.25.3", + "@redocly/cli": "1.25.5", + "@redocly/openapi-core": "1.25.5", "@vitest/coverage-v8": "^1.4.0", "eslint": "^8.57.0", "prettier": "^3.2.5", @@ -768,12 +768,12 @@ } }, "node_modules/@redocly/cli": { - "version": "1.25.3", - "resolved": "https://registry.npmjs.org/@redocly/cli/-/cli-1.25.3.tgz", - "integrity": "sha512-58odmEj+gr7xp9fvAqzf+t6M4O3olvPOFe7SMu9mAdCaEGLr6o/AMdRvDwF+z1svinK/yAt4375/eL+H2LgPtQ==", + "version": "1.25.5", + "resolved": "https://registry.npmjs.org/@redocly/cli/-/cli-1.25.5.tgz", + "integrity": "sha512-sFh4A8wqwuig7mF/nYNVIyxSfKKZikWC+uVH6OB1IepYQXNsHFaLAU1VaNI9gS5mMvWmYx5SEuSCVB9LaNFBhw==", "dev": true, "dependencies": { - "@redocly/openapi-core": "1.25.3", + "@redocly/openapi-core": "1.25.5", "abort-controller": "^3.0.0", "chokidar": "^3.5.1", "colorette": "^1.2.0", @@ -803,19 +803,19 @@ } }, "node_modules/@redocly/config": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/@redocly/config/-/config-0.11.0.tgz", - "integrity": "sha512-vAc77vCuWsVgLx2LN02P6jqLBhHuot6O1LsSJEAAkWEvXARSGSQVon50QW7jlbCMg9OFTYYYRPN4W6K/YmnM3w==", + "version": "0.12.1", + "resolved": "https://registry.npmjs.org/@redocly/config/-/config-0.12.1.tgz", + "integrity": "sha512-RW3rSirfsPdr0uvATijRDU3f55SuZV3m7/ppdTDvGw4IB0cmeZRkFmqTrchxMqWP50Gfg1tpHnjdxUCNo0E2qg==", "dev": true }, "node_modules/@redocly/openapi-core": { - "version": "1.25.3", - "resolved": "https://registry.npmjs.org/@redocly/openapi-core/-/openapi-core-1.25.3.tgz", - "integrity": "sha512-dqJkyydgagW3FXX5cjtSUAnabsld4K6yq7RFgQ+ngI1m43PkEoSQt8pp+SfQDszSEoMbc7QKj8afbe7mZw17TA==", + "version": "1.25.5", + "resolved": "https://registry.npmjs.org/@redocly/openapi-core/-/openapi-core-1.25.5.tgz", + "integrity": "sha512-BNgXjqesJu4L5f8F73c2hkkH5IdvjYCKYFgIl+m9oNgqGRIPBJjtiEGOx7jkQ6nElN4311z7Z4aTECtklaaHwg==", "dev": true, "dependencies": { "@redocly/ajv": "^8.11.2", - "@redocly/config": "^0.11.0", + "@redocly/config": "^0.12.1", "colorette": "^1.2.0", "https-proxy-agent": "^7.0.4", "js-levenshtein": "^1.1.6", diff --git a/package.json b/package.json index ce237a8..44c5b45 100644 --- a/package.json +++ b/package.json @@ -27,8 +27,8 @@ }, "homepage": "https://github.com/tatomyr/json-types#readme", "devDependencies": { - "@redocly/cli": "1.25.3", - "@redocly/openapi-core": "1.25.3", + "@redocly/cli": "1.25.5", + "@redocly/openapi-core": "1.25.5", "@vitest/coverage-v8": "^1.4.0", "eslint": "^8.57.0", "prettier": "^3.2.5", diff --git a/x-types.yaml b/x-types.yaml new file mode 100644 index 0000000..33856ac --- /dev/null +++ b/x-types.yaml @@ -0,0 +1,21 @@ +XType: + - string # including `string`, `number`, `boolean`, `undefined`, `any`, and string literals + - number # literal numbers + - boolean # literal booleans + - null # literal null value + - $ref: '#/Or' + - $ref: '#/And' + - $ref: '#/Array' + - $ref: '#/Record' +Or: + array: + $ref: '#/XType' +And: + $literal:$and: + $ref: '#/Or' +Array: + $literal:array: + $ref: '#/XType' +Record: + string::pattern(^(?!\$and$)(?!array$).*$): # including `string` and any string literals, but excluding `$and` and `array`. + $ref: '#/XType'