diff --git a/applications/__tests__/__snapshots__/e2e.test.js.snap b/applications/__tests__/__snapshots__/e2e.test.js.snap index a470fbe..6711389 100644 --- a/applications/__tests__/__snapshots__/e2e.test.js.snap +++ b/applications/__tests__/__snapshots__/e2e.test.js.snap @@ -228,6 +228,28 @@ paths: value: false schema: type: number + '203': + description: A transitive reference + content: + application/json: + x-type: + $ref: '#/components/x-types/Bar' + examples: + Correct: + value: + - anything + Incorrect: + value: anything + schema: + type: array + items: + anyOf: + - type: string + - type: number + - type: boolean + - type: object + - type: array + - type: 'null' '404': description: A wrong ref content: @@ -254,6 +276,9 @@ paths: components: x-types: Foo: any + Bar: + array: + $ref: '#/components/x-types/Foo' " `; @@ -301,15 +326,16 @@ run \`redocly lint --generate-ignore-file\` to add all problems to the ignore fi exports[`lint > lints x-openapi-with-refs.yaml 1`] = ` "validating applications/outputs/x-openapi-with-refs.yaml... -[1] applications/outputs/x-openapi-with-refs.yaml:103:10 at #/components/x-types/Foo +[1] applications/outputs/x-openapi-with-refs.yaml:125:10 at #/components/x-types/Foo Expected type \`XTypeObject\` (object) but got \`string\` -101 | components: -102 | x-types: -103 | Foo: any +123 | components: +124 | x-types: +125 | Foo: any | ^^^ -104 | +126 | Bar: +127 | array: referenced from applications/outputs/x-openapi-with-refs.yaml:15:19 at #/paths/~1test/get/responses/200/content/application~1json/x-type/AFieldWithRegularRef @@ -380,23 +406,39 @@ referenced from applications/outputs/x-openapi-with-refs.yaml:70:15 at #/paths/~ Error was generated by the no-invalid-media-type-examples rule. -[6] applications/outputs/x-openapi-with-refs.yaml:84:19 at #/paths/~1test/get/responses/404/content/application~1json/x-type/AWrongRef +[6] applications/outputs/x-openapi-with-refs.yaml:89:26 at #/paths/~1test/get/responses/203/content/application~1json/examples/Incorrect/value + +Example value must conform to the schema: type must be array. + +87 | - anything +88 | Incorrect: +89 | value: anything + | ^^^^^^^^ +90 | schema: +91 | type: array + +referenced from applications/outputs/x-openapi-with-refs.yaml:82:15 at #/paths/~1test/get/responses/203/content/application~1json + +Error was generated by the no-invalid-media-type-examples rule. + + +[7] applications/outputs/x-openapi-with-refs.yaml:106:19 at #/paths/~1test/get/responses/404/content/application~1json/x-type/AWrongRef Can't resolve $ref: ENOENT: no such file or directory './applications/outputs/wrong-file.yaml' -82 | x-type: -83 | AWrongRef: -84 | $ref: wrong-file.yaml - | ^^^^^^^^^^^^^^^^^^^^^ -85 | example: -86 | AWrongRef: Accepts anything +104 | x-type: +105 | AWrongRef: +106 | $ref: wrong-file.yaml + | ^^^^^^^^^^^^^^^^^^^^^ +107 | example: +108 | AWrongRef: Accepts anything Error was generated by the no-unresolved-refs rule. applications/outputs/x-openapi-with-refs.yaml: validated in ms -❌ Validation failed with 6 errors. +❌ Validation failed with 7 errors. run \`redocly lint --generate-ignore-file\` to add all problems to the ignore file. " diff --git a/applications/resources/openapi-with-refs.yaml b/applications/resources/openapi-with-refs.yaml index 02666fb..b526e4c 100644 --- a/applications/resources/openapi-with-refs.yaml +++ b/applications/resources/openapi-with-refs.yaml @@ -40,6 +40,16 @@ paths: value: 42 Incorrect: value: false + 203: + description: A transitive reference + content: + application/json: + x-type: $ref:#/components/x-types/Bar + examples: + Correct: + value: [anything] + Incorrect: + value: anything 404: description: A wrong ref content: @@ -51,3 +61,5 @@ paths: components: x-types: Foo: any + Bar: + array: $ref:#/components/x-types/Foo diff --git a/applications/x-types-plugin.js b/applications/x-types-plugin.js index fe47ebd..4a6f777 100644 --- a/applications/x-types-plugin.js +++ b/applications/x-types-plugin.js @@ -81,6 +81,18 @@ module.exports = { "x-type": getType, }, }, + Components: { + ...types.Components, + properties: { + ...types.Components.properties, + "x-types": { + name: "NamedXTypes", + properties: {}, + additionalProperties: getType, + }, + }, + }, + // TODO: Add more types here } }, }, diff --git a/package-lock.json b/package-lock.json index 8185ecf..296f4e9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.0.1", "license": "ISC", "devDependencies": { - "@redocly/cli": "^1.10.6", + "@redocly/cli": "^1.11.0", "@vitest/coverage-v8": "^1.4.0", "eslint": "^8.57.0", "prettier": "^3.2.5", @@ -749,12 +749,12 @@ } }, "node_modules/@redocly/cli": { - "version": "1.10.6", - "resolved": "https://registry.npmjs.org/@redocly/cli/-/cli-1.10.6.tgz", - "integrity": "sha512-KSy8fidqmnY3IQJ3zd+3j6QNu7xxj7mNzkN7q71wVXhWVqqB0WuBb2HmsnFgtGFzm83UHwVDFNpFR9qpK9HsMg==", + "version": "1.11.0", + "resolved": "https://registry.npmjs.org/@redocly/cli/-/cli-1.11.0.tgz", + "integrity": "sha512-ZBNaSdbX+A5CR4X3sxLYqUI3z9CazK7GoQqpTXijZ+bJ0R0Sd+DuR3dZqrd6Fh9k+UdYPRitOkU19bjPQ+fJjQ==", "dev": true, "dependencies": { - "@redocly/openapi-core": "1.10.6", + "@redocly/openapi-core": "1.11.0", "abort-controller": "^3.0.0", "chokidar": "^3.5.1", "colorette": "^1.2.0", @@ -783,19 +783,19 @@ } }, "node_modules/@redocly/config": { - "version": "0.1.5", - "resolved": "https://registry.npmjs.org/@redocly/config/-/config-0.1.5.tgz", - "integrity": "sha512-nE7jePALlLDC7hueRy/yWFlTqNv6yrVQnKQVwVepOzuf0PTUYsBWQ2fNxh7Z2L/3PDjTs/Jc2IHmkwAkFyHmnw==", + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/@redocly/config/-/config-0.2.0.tgz", + "integrity": "sha512-r0TqTPVXrxdvhpbOntWnJofOx0rC7u+A+tfC0KFwMtw38QCNb3pwodVjeLa7MT5Uu+fcPxfO119yLBj0QHvBuQ==", "dev": true }, "node_modules/@redocly/openapi-core": { - "version": "1.10.6", - "resolved": "https://registry.npmjs.org/@redocly/openapi-core/-/openapi-core-1.10.6.tgz", - "integrity": "sha512-qWZszssMMe/UrJ4LN4qh2mdcIx5uMHwnvtkAEdmWYWlUv+LNaBeqazjDt0UrCOX5EsrD4d+21oxQJNdbyGMVVA==", + "version": "1.11.0", + "resolved": "https://registry.npmjs.org/@redocly/openapi-core/-/openapi-core-1.11.0.tgz", + "integrity": "sha512-VH10SAkDu+jVW9tDFJWWYroFxHVY9N5VS4gorXw0cK8L+LydUOQ4KiZaKbTsTF2piWmZCxngZI7sNPHMiJ4Ftg==", "dev": true, "dependencies": { "@redocly/ajv": "^8.11.0", - "@redocly/config": "^0.1.4", + "@redocly/config": "^0.2.0", "colorette": "^1.2.0", "js-levenshtein": "^1.1.6", "js-yaml": "^4.1.0", diff --git a/package.json b/package.json index ca1270c..12ba27e 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "This document attempts to describe data types (primarily aimed at JSON-like structures) in a simple and natural way. Any [valid JSON](https://www.json.org/) could be validated against an **JSON X-Types** definition.", "main": "index.js", "scripts": { - "translate": "redocly bundle applications/resources/openapi.yaml -o=applications/outputs/x-openapi.yaml --force --config=applications/x-inline-refs-config-redocly.yaml && redocly lint applications/outputs/x-openapi.yaml --config=applications/x-inline-refs-config-redocly.yaml", + "refs": "redocly bundle applications/resources/openapi-with-refs.yaml -o=applications/outputs/x-openapi-with-refs.yaml --force --config=applications/x-inline-refs-config-redocly.yaml && redocly lint applications/outputs/x-openapi-with-refs.yaml --config=applications/x-inline-refs-config-redocly.yaml", "lint": "eslint .", "test": "vitest", "coverage": "vitest run --coverage", @@ -26,7 +26,7 @@ }, "homepage": "https://github.com/tatomyr/json-types#readme", "devDependencies": { - "@redocly/cli": "^1.10.6", + "@redocly/cli": "^1.11.0", "@vitest/coverage-v8": "^1.4.0", "eslint": "^8.57.0", "prettier": "^3.2.5",