From 4a82aa3b3263027e84b8ea875b387a3332b56dbd Mon Sep 17 00:00:00 2001 From: Luke Hagar Date: Tue, 30 Sep 2025 20:20:10 +0000 Subject: [PATCH] Refactor OpenAPI schema files by removing redundant type definitions for better clarity. Update bun.lock and package.json to include ajv as a new dependency. Add GitHub Actions workflow for automated testing of OpenAPI schemas across versions 2.0, 3.0, and 3.1. --- .github/workflows/test.yml | 32 + build.ts | 2 +- bun.lock | 11 + package.json | 1 + schemas/2.0/index.ts | 2 - schemas/3.0/index.ts | 2 - schemas/3.1/index.ts | 2 - schemas/3.2/index.ts | 2 - tests/2.0/api-with-examples.ts | 288 ++++----- tests/2.0/petstore-expanded.ts | 400 ++++++------ tests/2.0/petstore-minimal.ts | 116 ++-- tests/2.0/petstore-simple.ts | 418 ++++++------- tests/2.0/petstore-with-external-docs.ts | 440 +++++++------- tests/2.0/petstore.ts | 268 ++++---- tests/2.0/uber.ts | 738 +++++++++++------------ tests/3.0/api-with-examples.ts | 382 ++++++------ tests/3.0/callback-example.ts | 170 +++--- tests/3.0/link-example.ts | 636 +++++++++---------- tests/3.0/petstore-expanded.ts | 474 +++++++-------- tests/3.0/petstore.ts | 352 +++++------ tests/3.0/uspto.ts | 508 ++++++++-------- tests/3.1/non-oauth-scopes.ts | 62 +- tests/3.1/tictactoe.ts | 526 ++++++++-------- tests/3.1/webhook-example.ts | 94 +-- tests/openapi-3.0-schemas.test.ts | 171 ++++++ tests/openapi-3.1-schemas.test.ts | 217 +++++++ tests/swagger-schemas.test.ts | 136 +++++ tests/validate-schema.ts | 92 --- 28 files changed, 3506 insertions(+), 3036 deletions(-) create mode 100644 .github/workflows/test.yml create mode 100644 tests/openapi-3.0-schemas.test.ts create mode 100644 tests/openapi-3.1-schemas.test.ts create mode 100755 tests/swagger-schemas.test.ts delete mode 100755 tests/validate-schema.ts diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..637813b --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,32 @@ +name: Test + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Bun + uses: oven-sh/setup-bun@v1 + with: + bun-version: latest + + - name: Install dependencies + run: bun install + + - name: Run tests + run: bun test + + - name: Run type check + run: bun run type-check + + - name: Run linting + run: bun run lint diff --git a/build.ts b/build.ts index 75b0085..3f6a230 100755 --- a/build.ts +++ b/build.ts @@ -291,7 +291,7 @@ async function generateIndexFiles(): Promise { indexContent += ` ${component},\n`; } - indexContent += `} as const;\n\n// Type definitions for better TypeScript support\nexport type SchemaName = keyof typeof schemas;\n`; + indexContent += `} as const;\n\n`; writeFileSync(indexPath, indexContent); console.log(`✅ Generated index.ts for ${version}`); diff --git a/bun.lock b/bun.lock index 6b645ec..2ad44e0 100644 --- a/bun.lock +++ b/bun.lock @@ -4,6 +4,7 @@ "": { "name": "openapi-types", "dependencies": { + "ajv": "^8.17.1", "rimraf": "^6.0.1", "spdx-license-list": "^6.10.0", }, @@ -76,6 +77,8 @@ "@types/react": ["@types/react@19.1.13", "", { "dependencies": { "csstype": "^3.0.2" } }, "sha512-hHkbU/eoO3EG5/MZkuFSKmYqPbSVk5byPFa3e7y/8TybHiLMACgI8seVYlicwk7H5K/rI2px9xrQp/C+AUDTiQ=="], + "ajv": ["ajv@8.17.1", "", { "dependencies": { "fast-deep-equal": "^3.1.3", "fast-uri": "^3.0.1", "json-schema-traverse": "^1.0.0", "require-from-string": "^2.0.2" } }, "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g=="], + "ansi-escapes": ["ansi-escapes@4.3.2", "", { "dependencies": { "type-fest": "^0.21.3" } }, "sha512-gKXj5ALrKWQLsYG9jlTRmR/xKluxHV+Z9QEwNIgCfM1/uwPMCuzVVnh5mwTd+OuBZcwSIMbqssNWRm1lE51QaQ=="], "ansi-regex": ["ansi-regex@5.0.1", "", {}, "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ=="], @@ -124,8 +127,12 @@ "eslint-rule-docs": ["eslint-rule-docs@1.1.235", "", {}, "sha512-+TQ+x4JdTnDoFEXXb3fDvfGOwnyNV7duH8fXWTPD1ieaBmB8omj7Gw/pMBBu4uI2uJCCU8APDaQJzWuXnTsH4A=="], + "fast-deep-equal": ["fast-deep-equal@3.1.3", "", {}, "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q=="], + "fast-glob": ["fast-glob@3.3.3", "", { "dependencies": { "@nodelib/fs.stat": "^2.0.2", "@nodelib/fs.walk": "^1.2.3", "glob-parent": "^5.1.2", "merge2": "^1.3.0", "micromatch": "^4.0.8" } }, "sha512-7MptL8U0cqcFdzIzwOTHoilX9x5BrNqye7Z/LuC7kCMRio1EMSyqRK3BEAUD7sXRq4iT4AzTVuZdhgQ2TCvYLg=="], + "fast-uri": ["fast-uri@3.1.0", "", {}, "sha512-iPeeDKJSWf4IEOasVVrknXpaBV0IApz/gp7S2bb7Z4Lljbl2MGJRqInZiUrQwV16cpzw/D3S5j5Julj/gT52AA=="], + "fastq": ["fastq@1.19.1", "", { "dependencies": { "reusify": "^1.0.4" } }, "sha512-GwLTyxkCXjXbxqIhTsMI2Nui8huMPtnxg7krajPJAjnEG/iiOS7i+zCtWGZR9G0NBKbXKh6X9m9UIsYX/N6vvQ=="], "fill-range": ["fill-range@7.1.1", "", { "dependencies": { "to-regex-range": "^5.0.1" } }, "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg=="], @@ -184,6 +191,8 @@ "json-parse-even-better-errors": ["json-parse-even-better-errors@2.3.1", "", {}, "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w=="], + "json-schema-traverse": ["json-schema-traverse@1.0.0", "", {}, "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug=="], + "json5": ["json5@2.2.3", "", { "bin": { "json5": "lib/cli.js" } }, "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg=="], "kind-of": ["kind-of@6.0.3", "", {}, "sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw=="], @@ -256,6 +265,8 @@ "redent": ["redent@3.0.0", "", { "dependencies": { "indent-string": "^4.0.0", "strip-indent": "^3.0.0" } }, "sha512-6tDA8g98We0zd0GvVeMT9arEOnTw9qM03L9cJXaCjrip1OO764RDBLBfrB4cwzNGDj5OA5ioymC9GkizgWJDUg=="], + "require-from-string": ["require-from-string@2.0.2", "", {}, "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw=="], + "resolve": ["resolve@1.22.10", "", { "dependencies": { "is-core-module": "^2.16.0", "path-parse": "^1.0.7", "supports-preserve-symlinks-flag": "^1.0.0" }, "bin": { "resolve": "bin/resolve" } }, "sha512-NPRy+/ncIMeDlTAsuqwKIiferiawhefFJtkNSW0qZJEqMEb+qBt/77B/jGeeek+F0uOeN05CDa6HXbbIgtVX4w=="], "reusify": ["reusify@1.1.0", "", {}, "sha512-g6QUff04oZpHs0eG5p83rFLhHeV00ug/Yf9nZM6fLeUrPguBTkTQOdpAWWspMh55TZfVQDPaN3NQJfbVRAxdIw=="], diff --git a/package.json b/package.json index d0533eb..67be56b 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "schemas:validate": "echo 'Schema validation not yet implemented'" }, "dependencies": { + "ajv": "^8.17.1", "rimraf": "^6.0.1", "spdx-license-list": "^6.10.0" }, diff --git a/schemas/2.0/index.ts b/schemas/2.0/index.ts index 786f7c0..a4ab6f3 100644 --- a/schemas/2.0/index.ts +++ b/schemas/2.0/index.ts @@ -29,5 +29,3 @@ export const schemas = { pathitem, } as const; -// Type definitions for better TypeScript support -export type SchemaName = keyof typeof schemas; diff --git a/schemas/3.0/index.ts b/schemas/3.0/index.ts index 7020586..875a7d7 100644 --- a/schemas/3.0/index.ts +++ b/schemas/3.0/index.ts @@ -44,5 +44,3 @@ export const schemas = { callback, } as const; -// Type definitions for better TypeScript support -export type SchemaName = keyof typeof schemas; diff --git a/schemas/3.1/index.ts b/schemas/3.1/index.ts index b080877..65702f2 100644 --- a/schemas/3.1/index.ts +++ b/schemas/3.1/index.ts @@ -47,5 +47,3 @@ export const schemas = { pathitem, } as const; -// Type definitions for better TypeScript support -export type SchemaName = keyof typeof schemas; diff --git a/schemas/3.2/index.ts b/schemas/3.2/index.ts index d11cd71..9014445 100644 --- a/schemas/3.2/index.ts +++ b/schemas/3.2/index.ts @@ -50,5 +50,3 @@ export const schemas = { pathitem, } as const; -// Type definitions for better TypeScript support -export type SchemaName = keyof typeof schemas; diff --git a/tests/2.0/api-with-examples.ts b/tests/2.0/api-with-examples.ts index 847bc5f..8e915a7 100644 --- a/tests/2.0/api-with-examples.ts +++ b/tests/2.0/api-with-examples.ts @@ -1,147 +1,147 @@ import type { Specification } from "../../2.0"; -const _apiWithExamples: Specification = { - swagger: "2.0", - info: { - title: "Simple API overview", - version: "v2", - }, - paths: { - "/": { - get: { - operationId: "listVersionsv2", - summary: "List API versions", - produces: ["application/json"], - responses: { - "200": { - description: "200 300 response", - examples: { - "application/json": { - versions: [ - { - status: "CURRENT", - updated: "2011-01-21T11:33:21Z", - id: "v2.0", - links: [{ href: "http://127.0.0.1:8774/v2/", rel: "self" }], - }, - { - status: "EXPERIMENTAL", - updated: "2013-07-23T11:33:21Z", - id: "v3.0", - links: [{ href: "http://127.0.0.1:8774/v3/", rel: "self" }], - }, - ], - }, - }, - }, - "300": { - description: "200 300 response", - examples: { - "application/json": { - versions: [ - { - status: "CURRENT", - updated: "2011-01-21T11:33:21Z", - id: "v2.0", - links: [{ href: "http://127.0.0.1:8774/v2/", rel: "self" }], - }, - { - status: "EXPERIMENTAL", - updated: "2013-07-23T11:33:21Z", - id: "v3.0", - links: [{ href: "http://127.0.0.1:8774/v3/", rel: "self" }], - }, - ], - }, - }, - }, - }, - }, - }, - "/v2": { - get: { - operationId: "getVersionDetailsv2", - summary: "Show API version details", - produces: ["application/json"], - responses: { - "200": { - description: "200 203 response", - examples: { - "application/json": { - version: { - status: "CURRENT", - updated: "2011-01 - 21T11: 33: 21Z", - "media - types": [ - { - base: "application / xml", - type: "application / vnd.openstack.compute + xml; version=2", - }, - { - base: "application / json", - type: "application / vnd.openstack.compute + json; version=2", - }, - ], - id: "v2.0", - links: [ - { href: "http://127.0.0.1:8774/v2/", rel: "self" }, - { - href: "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf", - type: "application/pdf", - rel: "describedby", - }, - { - href: "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl", - type: "application/vnd.sun.wadl+xml", - rel: "describedby", - }, - { - href: "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl", - type: "application/vnd.sun.wadl+xml", - rel: "describedby", - }, - ], - }, - }, - }, - }, - "203": { - description: "200 203 response", - examples: { - "application/json": { - version: { - status: "CURRENT", - updated: "2011-01 - 21T11: 33: 21Z", - "media - types": [ - { - base: "application / xml", - type: "application / vnd.openstack.compute + xml; version=2", - }, - { - base: "application / json", - type: "application / vnd.openstack.compute + json; version=2", - }, - ], - id: "v2.0", - links: [ - { href: "http://23.253.228.211:8774/v2/", rel: "self" }, - { - href: "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf", - type: "application/pdf", - rel: "describedby", - }, - { - href: "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl", - type: "application/vnd.sun.wadl+xml", - rel: "describedby", - }, - ], - }, - }, - }, - }, - }, - }, - }, - }, - consumes: ["application/json"], +export const apiWithExamples: Specification = { + swagger: "2.0", + info: { + title: "Simple API overview", + version: "v2", + }, + paths: { + "/": { + get: { + operationId: "listVersionsv2", + summary: "List API versions", + produces: ["application/json"], + responses: { + "200": { + description: "200 300 response", + examples: { + "application/json": { + versions: [ + { + status: "CURRENT", + updated: "2011-01-21T11:33:21Z", + id: "v2.0", + links: [{ href: "http://127.0.0.1:8774/v2/", rel: "self" }], + }, + { + status: "EXPERIMENTAL", + updated: "2013-07-23T11:33:21Z", + id: "v3.0", + links: [{ href: "http://127.0.0.1:8774/v3/", rel: "self" }], + }, + ], + }, + }, + }, + "300": { + description: "200 300 response", + examples: { + "application/json": { + versions: [ + { + status: "CURRENT", + updated: "2011-01-21T11:33:21Z", + id: "v2.0", + links: [{ href: "http://127.0.0.1:8774/v2/", rel: "self" }], + }, + { + status: "EXPERIMENTAL", + updated: "2013-07-23T11:33:21Z", + id: "v3.0", + links: [{ href: "http://127.0.0.1:8774/v3/", rel: "self" }], + }, + ], + }, + }, + }, + }, + }, + }, + "/v2": { + get: { + operationId: "getVersionDetailsv2", + summary: "Show API version details", + produces: ["application/json"], + responses: { + "200": { + description: "200 203 response", + examples: { + "application/json": { + version: { + status: "CURRENT", + updated: "2011-01 - 21T11: 33: 21Z", + "media - types": [ + { + base: "application / xml", + type: "application / vnd.openstack.compute + xml; version=2", + }, + { + base: "application / json", + type: "application / vnd.openstack.compute + json; version=2", + }, + ], + id: "v2.0", + links: [ + { href: "http://127.0.0.1:8774/v2/", rel: "self" }, + { + href: "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf", + type: "application/pdf", + rel: "describedby", + }, + { + href: "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl", + type: "application/vnd.sun.wadl+xml", + rel: "describedby", + }, + { + href: "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl", + type: "application/vnd.sun.wadl+xml", + rel: "describedby", + }, + ], + }, + }, + }, + }, + "203": { + description: "200 203 response", + examples: { + "application/json": { + version: { + status: "CURRENT", + updated: "2011-01 - 21T11: 33: 21Z", + "media - types": [ + { + base: "application / xml", + type: "application / vnd.openstack.compute + xml; version=2", + }, + { + base: "application / json", + type: "application / vnd.openstack.compute + json; version=2", + }, + ], + id: "v2.0", + links: [ + { href: "http://23.253.228.211:8774/v2/", rel: "self" }, + { + href: "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf", + type: "application/pdf", + rel: "describedby", + }, + { + href: "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl", + type: "application/vnd.sun.wadl+xml", + rel: "describedby", + }, + ], + }, + }, + }, + }, + }, + }, + }, + }, + consumes: ["application/json"], }; diff --git a/tests/2.0/petstore-expanded.ts b/tests/2.0/petstore-expanded.ts index bbdd693..ed20b81 100644 --- a/tests/2.0/petstore-expanded.ts +++ b/tests/2.0/petstore-expanded.ts @@ -1,202 +1,204 @@ import type { Specification } from "../../2.0"; -const _petstoreExpanded: Specification = { - swagger: "2.0", - info: { - version: "1.0.0", - title: "Swagger Petstore", - description: - "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", - termsOfService: "http://swagger.io/terms/", - contact: { - name: "Swagger API Team", - email: "apiteam@swagger.io", - url: "http://swagger.io", - }, - license: { - name: "Apache 2.0", - url: "https://www.apache.org/licenses/LICENSE-2.0.html", - }, - }, - host: "petstore.swagger.io", - basePath: "/api", - schemes: ["http"], - consumes: ["application/json"], - produces: ["application/json"], - paths: { - "/pets": { - get: { - description: - "Returns all pets from the system that the user has access to\nNam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia.\n\nSed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien.\n", - operationId: "findPets", - parameters: [ - { - name: "tags", - in: "query", - description: "tags to filter by", - required: false, - type: "array", - collectionFormat: "csv", - items: { - type: "string", - }, - }, - { - name: "limit", - in: "query", - description: "maximum number of results to return", - required: false, - type: "integer", - format: "int32", - }, - ], - responses: { - 200: { - description: "pet response", - schema: { - type: "array", - items: { - $ref: "#/definitions/Pet", - }, - }, - }, - default: { - description: "unexpected error", - schema: { - $ref: "#/definitions/Error", - }, - }, - }, - }, - post: { - description: "Creates a new pet in the store. Duplicates are allowed", - operationId: "addPet", - parameters: [ - { - name: "pet", - in: "body", - description: "Pet to add to the store", - required: true, - schema: { - $ref: "#/definitions/NewPet", - }, - }, - ], - responses: { - 200: { - description: "pet response", - schema: { - $ref: "#/definitions/Pet", - }, - }, - default: { - description: "unexpected error", - schema: { - $ref: "#/definitions/Error", - }, - }, - }, - }, - }, - "/pets/{id}": { - get: { - description: - "Returns a user based on a single ID, if the user does not have access to the pet", - operationId: "find pet by id", - parameters: [ - { - name: "id", - in: "path", - description: "ID of pet to fetch", - required: true, - type: "integer", - format: "int64", - }, - ], - responses: { - 200: { - description: "pet response", - schema: { - $ref: "#/definitions/Pet", - }, - }, - default: { - description: "unexpected error", - schema: { - $ref: "#/definitions/Error", - }, - }, - }, - }, - delete: { - description: "deletes a single pet based on the ID supplied", - operationId: "deletePet", - parameters: [ - { - name: "id", - in: "path", - description: "ID of pet to delete", - required: true, - type: "integer", - format: "int64", - }, - ], - responses: { - 204: { - description: "pet deleted", - }, - default: { - description: "unexpected error", - schema: { - $ref: "#/definitions/Error", - }, - }, - }, - }, - }, - }, - definitions: { - Pet: { - type: "object", - allOf: [ - { - $ref: "#/definitions/NewPet", - }, - { - required: ["id"], - properties: { - id: { - type: "integer", - format: "int64", - }, - }, - }, - ], - }, - NewPet: { - type: "object", - required: ["name"], - properties: { - name: { - type: "string", - }, - tag: { - type: "string", - }, - }, - }, - Error: { - type: "object", - required: ["code", "message"], - properties: { - code: { - type: "integer", - format: "int32", - }, - message: { - type: "string", - }, - }, - }, - }, +const petstoreExpanded: Specification = { + swagger: "2.0", + info: { + version: "1.0.0", + title: "Swagger Petstore", + description: + "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", + termsOfService: "http://swagger.io/terms/", + contact: { + name: "Swagger API Team", + email: "apiteam@swagger.io", + url: "http://swagger.io", + }, + license: { + name: "Apache 2.0", + url: "https://www.apache.org/licenses/LICENSE-2.0.html", + }, + }, + host: "petstore.swagger.io", + basePath: "/api", + schemes: ["http"], + consumes: ["application/json"], + produces: ["application/json"], + paths: { + "/pets": { + get: { + description: + "Returns all pets from the system that the user has access to\nNam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia.\n\nSed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien.\n", + operationId: "findPets", + parameters: [ + { + name: "tags", + in: "query", + description: "tags to filter by", + required: false, + type: "array", + collectionFormat: "csv", + items: { + type: "string", + }, + }, + { + name: "limit", + in: "query", + description: "maximum number of results to return", + required: false, + type: "integer", + format: "int32", + }, + ], + responses: { + 200: { + description: "pet response", + schema: { + type: "array", + items: { + $ref: "#/definitions/Pet", + }, + }, + }, + default: { + description: "unexpected error", + schema: { + $ref: "#/definitions/Error", + }, + }, + }, + }, + post: { + description: "Creates a new pet in the store. Duplicates are allowed", + operationId: "addPet", + parameters: [ + { + name: "pet", + in: "body", + description: "Pet to add to the store", + required: true, + schema: { + $ref: "#/definitions/NewPet", + }, + }, + ], + responses: { + 200: { + description: "pet response", + schema: { + $ref: "#/definitions/Pet", + }, + }, + default: { + description: "unexpected error", + schema: { + $ref: "#/definitions/Error", + }, + }, + }, + }, + }, + "/pets/{id}": { + get: { + description: + "Returns a user based on a single ID, if the user does not have access to the pet", + operationId: "find pet by id", + parameters: [ + { + name: "id", + in: "path", + description: "ID of pet to fetch", + required: true, + type: "integer", + format: "int64", + }, + ], + responses: { + 200: { + description: "pet response", + schema: { + $ref: "#/definitions/Pet", + }, + }, + default: { + description: "unexpected error", + schema: { + $ref: "#/definitions/Error", + }, + }, + }, + }, + delete: { + description: "deletes a single pet based on the ID supplied", + operationId: "deletePet", + parameters: [ + { + name: "id", + in: "path", + description: "ID of pet to delete", + required: true, + type: "integer", + format: "int64", + }, + ], + responses: { + 204: { + description: "pet deleted", + }, + default: { + description: "unexpected error", + schema: { + $ref: "#/definitions/Error", + }, + }, + }, + }, + }, + }, + definitions: { + Pet: { + type: "object", + allOf: [ + { + $ref: "#/definitions/NewPet", + }, + { + required: ["id"], + properties: { + id: { + type: "integer", + format: "int64", + }, + }, + }, + ], + }, + NewPet: { + type: "object", + required: ["name"], + properties: { + name: { + type: "string", + }, + tag: { + type: "string", + }, + }, + }, + Error: { + type: "object", + required: ["code", "message"], + properties: { + code: { + type: "integer", + format: "int32", + }, + message: { + type: "string", + }, + }, + }, + }, }; + +export { petstoreExpanded }; diff --git a/tests/2.0/petstore-minimal.ts b/tests/2.0/petstore-minimal.ts index 5252816..12da18d 100644 --- a/tests/2.0/petstore-minimal.ts +++ b/tests/2.0/petstore-minimal.ts @@ -1,61 +1,61 @@ import type { Specification } from "../../2.0"; -const _petstoreMinimal: Specification = { - swagger: "2.0", - info: { - version: "1.0.0", - title: "Swagger Petstore", - description: - "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", - termsOfService: "http://swagger.io/terms/", - contact: { - name: "Swagger API Team", - }, - license: { - name: "MIT", - }, - }, - host: "petstore.swagger.io", - basePath: "/api", - schemes: ["http"], - consumes: ["application/json"], - produces: ["application/json"], - paths: { - "/pets": { - get: { - description: - "Returns all pets from the system that the user has access to", - produces: ["application/json"], - responses: { - 200: { - description: "A list of pets.", - schema: { - type: "array", - items: { - $ref: "#/definitions/Pet", - }, - }, - }, - }, - }, - }, - }, - definitions: { - Pet: { - type: "object", - required: ["id", "name"], - properties: { - id: { - type: "integer", - format: "int64", - }, - name: { - type: "string", - }, - tag: { - type: "string", - }, - }, - }, - }, +export const petstoreMinimal: Specification = { + swagger: "2.0", + info: { + version: "1.0.0", + title: "Swagger Petstore", + description: + "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", + termsOfService: "http://swagger.io/terms/", + contact: { + name: "Swagger API Team", + }, + license: { + name: "MIT", + }, + }, + host: "petstore.swagger.io", + basePath: "/api", + schemes: ["http"], + consumes: ["application/json"], + produces: ["application/json"], + paths: { + "/pets": { + get: { + description: + "Returns all pets from the system that the user has access to", + produces: ["application/json"], + responses: { + 200: { + description: "A list of pets.", + schema: { + type: "array", + items: { + $ref: "#/definitions/Pet", + }, + }, + }, + }, + }, + }, + }, + definitions: { + Pet: { + type: "object", + required: ["id", "name"], + properties: { + id: { + type: "integer", + format: "int64", + }, + name: { + type: "string", + }, + tag: { + type: "string", + }, + }, + }, + }, }; diff --git a/tests/2.0/petstore-simple.ts b/tests/2.0/petstore-simple.ts index 981b141..53f7971 100644 --- a/tests/2.0/petstore-simple.ts +++ b/tests/2.0/petstore-simple.ts @@ -1,212 +1,212 @@ import type { Specification } from "../../2.0"; -const _petstoreSimple: Specification = { - swagger: "2.0", - info: { - version: "1.0.0", - title: "Swagger Petstore", - description: - "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", - termsOfService: "http://swagger.io/terms/", - contact: { - name: "Swagger API Team", - }, - license: { - name: "MIT", - }, - }, - host: "petstore.swagger.io", - basePath: "/api", - schemes: ["http"], - consumes: ["application/json"], - produces: ["application/json"], - paths: { - "/pets": { - get: { - description: - "Returns all pets from the system that the user has access to", - operationId: "findPets", - produces: [ - "application/json", - "application/xml", - "text/xml", - "text/html", - ], - parameters: [ - { - name: "tags", - in: "query", - description: "tags to filter by", - required: false, - type: "array", - items: { - type: "string", - }, - collectionFormat: "csv", - }, - { - name: "limit", - in: "query", - description: "maximum number of results to return", - required: false, - type: "integer", - format: "int32", - }, - ], - responses: { - 200: { - description: "pet response", - schema: { - type: "array", - items: { - $ref: "#/definitions/Pet", - }, - }, - }, - default: { - description: "unexpected error", - schema: { - $ref: "#/definitions/ErrorModel", - }, - }, - }, - }, - post: { - description: "Creates a new pet in the store. Duplicates are allowed", - operationId: "addPet", - produces: ["application/json"], - parameters: [ - { - name: "pet", - in: "body", - description: "Pet to add to the store", - required: true, - schema: { - $ref: "#/definitions/NewPet", - }, - }, - ], - responses: { - 200: { - description: "pet response", - schema: { - $ref: "#/definitions/Pet", - }, - }, - default: { - description: "unexpected error", - schema: { - $ref: "#/definitions/ErrorModel", - }, - }, - }, - }, - }, - "/pets/{id}": { - get: { - description: - "Returns a user based on a single ID, if the user does not have access to the pet", - operationId: "findPetById", - produces: [ - "application/json", - "application/xml", - "text/xml", - "text/html", - ], - parameters: [ - { - name: "id", - in: "path", - description: "ID of pet to fetch", - required: true, - type: "integer", - format: "int64", - }, - ], - responses: { - 200: { - description: "pet response", - schema: { - $ref: "#/definitions/Pet", - }, - }, - default: { - description: "unexpected error", - schema: { - $ref: "#/definitions/ErrorModel", - }, - }, - }, - }, - delete: { - description: "deletes a single pet based on the ID supplied", - operationId: "deletePet", - parameters: [ - { - name: "id", - in: "path", - description: "ID of pet to delete", - required: true, - type: "integer", - format: "int64", - }, - ], - responses: { - 204: { - description: "pet deleted", - }, - default: { - description: "unexpected error", - schema: { - $ref: "#/definitions/ErrorModel", - }, - }, - }, - }, - }, - }, - definitions: { - Pet: { - type: "object", - allOf: [ - { - $ref: "#/definitions/NewPet", - }, - { - required: ["id"], - properties: { - id: { - type: "integer", - format: "int64", - }, - }, - }, - ], - }, - NewPet: { - type: "object", - required: ["name"], - properties: { - name: { - type: "string", - }, - tag: { - type: "string", - }, - }, - }, - ErrorModel: { - type: "object", - required: ["code", "message"], - properties: { - code: { - type: "integer", - format: "int32", - }, - message: { - type: "string", - }, - }, - }, - }, +export const petstoreSimple: Specification = { + swagger: "2.0", + info: { + version: "1.0.0", + title: "Swagger Petstore", + description: + "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", + termsOfService: "http://swagger.io/terms/", + contact: { + name: "Swagger API Team", + }, + license: { + name: "MIT", + }, + }, + host: "petstore.swagger.io", + basePath: "/api", + schemes: ["http"], + consumes: ["application/json"], + produces: ["application/json"], + paths: { + "/pets": { + get: { + description: + "Returns all pets from the system that the user has access to", + operationId: "findPets", + produces: [ + "application/json", + "application/xml", + "text/xml", + "text/html", + ], + parameters: [ + { + name: "tags", + in: "query", + description: "tags to filter by", + required: false, + type: "array", + items: { + type: "string", + }, + collectionFormat: "csv", + }, + { + name: "limit", + in: "query", + description: "maximum number of results to return", + required: false, + type: "integer", + format: "int32", + }, + ], + responses: { + 200: { + description: "pet response", + schema: { + type: "array", + items: { + $ref: "#/definitions/Pet", + }, + }, + }, + default: { + description: "unexpected error", + schema: { + $ref: "#/definitions/ErrorModel", + }, + }, + }, + }, + post: { + description: "Creates a new pet in the store. Duplicates are allowed", + operationId: "addPet", + produces: ["application/json"], + parameters: [ + { + name: "pet", + in: "body", + description: "Pet to add to the store", + required: true, + schema: { + $ref: "#/definitions/NewPet", + }, + }, + ], + responses: { + 200: { + description: "pet response", + schema: { + $ref: "#/definitions/Pet", + }, + }, + default: { + description: "unexpected error", + schema: { + $ref: "#/definitions/ErrorModel", + }, + }, + }, + }, + }, + "/pets/{id}": { + get: { + description: + "Returns a user based on a single ID, if the user does not have access to the pet", + operationId: "findPetById", + produces: [ + "application/json", + "application/xml", + "text/xml", + "text/html", + ], + parameters: [ + { + name: "id", + in: "path", + description: "ID of pet to fetch", + required: true, + type: "integer", + format: "int64", + }, + ], + responses: { + 200: { + description: "pet response", + schema: { + $ref: "#/definitions/Pet", + }, + }, + default: { + description: "unexpected error", + schema: { + $ref: "#/definitions/ErrorModel", + }, + }, + }, + }, + delete: { + description: "deletes a single pet based on the ID supplied", + operationId: "deletePet", + parameters: [ + { + name: "id", + in: "path", + description: "ID of pet to delete", + required: true, + type: "integer", + format: "int64", + }, + ], + responses: { + 204: { + description: "pet deleted", + }, + default: { + description: "unexpected error", + schema: { + $ref: "#/definitions/ErrorModel", + }, + }, + }, + }, + }, + }, + definitions: { + Pet: { + type: "object", + allOf: [ + { + $ref: "#/definitions/NewPet", + }, + { + required: ["id"], + properties: { + id: { + type: "integer", + format: "int64", + }, + }, + }, + ], + }, + NewPet: { + type: "object", + required: ["name"], + properties: { + name: { + type: "string", + }, + tag: { + type: "string", + }, + }, + }, + ErrorModel: { + type: "object", + required: ["code", "message"], + properties: { + code: { + type: "integer", + format: "int32", + }, + message: { + type: "string", + }, + }, + }, + }, }; diff --git a/tests/2.0/petstore-with-external-docs.ts b/tests/2.0/petstore-with-external-docs.ts index c00e399..7c77cb5 100644 --- a/tests/2.0/petstore-with-external-docs.ts +++ b/tests/2.0/petstore-with-external-docs.ts @@ -1,223 +1,223 @@ import type { Specification } from "../../2.0"; -const _petstoreWithExternalDocs: Specification = { - swagger: "2.0", - info: { - version: "1.0.0", - title: "Swagger Petstore", - description: - "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", - termsOfService: "http://swagger.io/terms/", - contact: { - name: "Swagger API Team", - email: "apiteam@swagger.io", - url: "http://swagger.io", - }, - license: { - name: "Apache 2.0", - url: "https://www.apache.org/licenses/LICENSE-2.0.html", - }, - }, - externalDocs: { - description: "find more info here", - url: "https://swagger.io/about", - }, - host: "petstore.swagger.io", - basePath: "/api", - schemes: ["http"], - consumes: ["application/json"], - produces: ["application/json"], - paths: { - "/pets": { - get: { - description: - "Returns all pets from the system that the user has access to", - operationId: "findPets", - externalDocs: { - description: "find more info here", - url: "https://swagger.io/about", - }, - produces: [ - "application/json", - "application/xml", - "text/xml", - "text/html", - ], - parameters: [ - { - name: "tags", - in: "query", - description: "tags to filter by", - required: false, - type: "array", - items: { - type: "string", - }, - collectionFormat: "csv", - }, - { - name: "limit", - in: "query", - description: "maximum number of results to return", - required: false, - type: "integer", - format: "int32", - }, - ], - responses: { - 200: { - description: "pet response", - schema: { - type: "array", - items: { - $ref: "#/definitions/Pet", - }, - }, - }, - default: { - description: "unexpected error", - schema: { - $ref: "#/definitions/ErrorModel", - }, - }, - }, - }, - post: { - description: "Creates a new pet in the store. Duplicates are allowed", - operationId: "addPet", - produces: ["application/json"], - parameters: [ - { - name: "pet", - in: "body", - description: "Pet to add to the store", - required: true, - schema: { - $ref: "#/definitions/NewPet", - }, - }, - ], - responses: { - 200: { - description: "pet response", - schema: { - $ref: "#/definitions/Pet", - }, - }, - default: { - description: "unexpected error", - schema: { - $ref: "#/definitions/ErrorModel", - }, - }, - }, - }, - }, - "/pets/{id}": { - get: { - description: - "Returns a user based on a single ID, if the user does not have access to the pet", - operationId: "findPetById", - produces: [ - "application/json", - "application/xml", - "text/xml", - "text/html", - ], - parameters: [ - { - name: "id", - in: "path", - description: "ID of pet to fetch", - required: true, - type: "integer", - format: "int64", - }, - ], - responses: { - 200: { - description: "pet response", - schema: { - $ref: "#/definitions/Pet", - }, - }, - default: { - description: "unexpected error", - schema: { - $ref: "#/definitions/ErrorModel", - }, - }, - }, - }, - delete: { - description: "deletes a single pet based on the ID supplied", - operationId: "deletePet", - parameters: [ - { - name: "id", - in: "path", - description: "ID of pet to delete", - required: true, - type: "integer", - format: "int64", - }, - ], - responses: { - 204: { - description: "pet deleted", - }, - default: { - description: "unexpected error", - schema: { - $ref: "#/definitions/ErrorModel", - }, - }, - }, - }, - }, - }, - definitions: { - Pet: { - type: "object", - allOf: [ - { - $ref: "#/definitions/NewPet", - }, - { - required: ["id"], - properties: { - id: { - type: "integer", - format: "int64", - }, - }, - }, - ], - }, - NewPet: { - type: "object", - required: ["name"], - properties: { - name: { - type: "string", - }, - tag: { - type: "string", - }, - }, - }, - ErrorModel: { - type: "object", - required: ["code", "message"], - properties: { - code: { - type: "integer", - format: "int32", - }, - message: { - type: "string", - }, - }, - }, - }, +export const petstoreWithExternalDocs: Specification = { + swagger: "2.0", + info: { + version: "1.0.0", + title: "Swagger Petstore", + description: + "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", + termsOfService: "http://swagger.io/terms/", + contact: { + name: "Swagger API Team", + email: "apiteam@swagger.io", + url: "http://swagger.io", + }, + license: { + name: "Apache 2.0", + url: "https://www.apache.org/licenses/LICENSE-2.0.html", + }, + }, + externalDocs: { + description: "find more info here", + url: "https://swagger.io/about", + }, + host: "petstore.swagger.io", + basePath: "/api", + schemes: ["http"], + consumes: ["application/json"], + produces: ["application/json"], + paths: { + "/pets": { + get: { + description: + "Returns all pets from the system that the user has access to", + operationId: "findPets", + externalDocs: { + description: "find more info here", + url: "https://swagger.io/about", + }, + produces: [ + "application/json", + "application/xml", + "text/xml", + "text/html", + ], + parameters: [ + { + name: "tags", + in: "query", + description: "tags to filter by", + required: false, + type: "array", + items: { + type: "string", + }, + collectionFormat: "csv", + }, + { + name: "limit", + in: "query", + description: "maximum number of results to return", + required: false, + type: "integer", + format: "int32", + }, + ], + responses: { + 200: { + description: "pet response", + schema: { + type: "array", + items: { + $ref: "#/definitions/Pet", + }, + }, + }, + default: { + description: "unexpected error", + schema: { + $ref: "#/definitions/ErrorModel", + }, + }, + }, + }, + post: { + description: "Creates a new pet in the store. Duplicates are allowed", + operationId: "addPet", + produces: ["application/json"], + parameters: [ + { + name: "pet", + in: "body", + description: "Pet to add to the store", + required: true, + schema: { + $ref: "#/definitions/NewPet", + }, + }, + ], + responses: { + 200: { + description: "pet response", + schema: { + $ref: "#/definitions/Pet", + }, + }, + default: { + description: "unexpected error", + schema: { + $ref: "#/definitions/ErrorModel", + }, + }, + }, + }, + }, + "/pets/{id}": { + get: { + description: + "Returns a user based on a single ID, if the user does not have access to the pet", + operationId: "findPetById", + produces: [ + "application/json", + "application/xml", + "text/xml", + "text/html", + ], + parameters: [ + { + name: "id", + in: "path", + description: "ID of pet to fetch", + required: true, + type: "integer", + format: "int64", + }, + ], + responses: { + 200: { + description: "pet response", + schema: { + $ref: "#/definitions/Pet", + }, + }, + default: { + description: "unexpected error", + schema: { + $ref: "#/definitions/ErrorModel", + }, + }, + }, + }, + delete: { + description: "deletes a single pet based on the ID supplied", + operationId: "deletePet", + parameters: [ + { + name: "id", + in: "path", + description: "ID of pet to delete", + required: true, + type: "integer", + format: "int64", + }, + ], + responses: { + 204: { + description: "pet deleted", + }, + default: { + description: "unexpected error", + schema: { + $ref: "#/definitions/ErrorModel", + }, + }, + }, + }, + }, + }, + definitions: { + Pet: { + type: "object", + allOf: [ + { + $ref: "#/definitions/NewPet", + }, + { + required: ["id"], + properties: { + id: { + type: "integer", + format: "int64", + }, + }, + }, + ], + }, + NewPet: { + type: "object", + required: ["name"], + properties: { + name: { + type: "string", + }, + tag: { + type: "string", + }, + }, + }, + ErrorModel: { + type: "object", + required: ["code", "message"], + properties: { + code: { + type: "integer", + format: "int32", + }, + message: { + type: "string", + }, + }, + }, + }, }; diff --git a/tests/2.0/petstore.ts b/tests/2.0/petstore.ts index e0291e5..48bb409 100644 --- a/tests/2.0/petstore.ts +++ b/tests/2.0/petstore.ts @@ -1,137 +1,137 @@ import type { Specification } from "../../2.0"; -const _petstore: Specification = { - swagger: "2.0", - info: { - version: "1.0.0", - title: "Swagger Petstore", - license: { - name: "MIT", - }, - }, - host: "petstore.swagger.io", - basePath: "/v1", - schemes: ["http"], - consumes: ["application/json"], - produces: ["application/json"], - paths: { - "/pets": { - get: { - summary: "List all pets", - operationId: "listPets", - tags: ["pets"], - parameters: [ - { - name: "limit", - in: "query", - description: "How many items to return at one time (max 100)", - required: false, - type: "integer", - format: "int32", - }, - ], - responses: { - 200: { - description: "An paged array of pets", - headers: { - "x-next": { - type: "string", - description: "A link to the next page of responses", - }, - }, - schema: { - $ref: "#/definitions/Pets", - }, - }, - default: { - description: "unexpected error", - schema: { - $ref: "#/definitions/Error", - }, - }, - }, - }, - post: { - summary: "Create a pet", - operationId: "createPets", - tags: ["pets"], - responses: { - 201: { - description: "Null response", - }, - default: { - description: "unexpected error", - schema: { - $ref: "#/definitions/Error", - }, - }, - }, - }, - }, - "/pets/{petId}": { - get: { - summary: "Info for a specific pet", - operationId: "showPetById", - tags: ["pets"], - parameters: [ - { - name: "petId", - in: "path", - required: true, - description: "The id of the pet to retrieve", - type: "string", - }, - ], - responses: { - 200: { - description: "Expected response to a valid request", - schema: { - $ref: "#/definitions/Pets", - }, - }, - default: { - description: "unexpected error", - schema: { - $ref: "#/definitions/Error", - }, - }, - }, - }, - }, - }, - definitions: { - Pet: { - required: ["id", "name"], - properties: { - id: { - type: "integer", - format: "int64", - }, - name: { - type: "string", - }, - tag: { - type: "string", - }, - }, - }, - Pets: { - type: "array", - items: { - $ref: "#/definitions/Pet", - }, - }, - Error: { - required: ["code", "message"], - properties: { - code: { - type: "integer", - format: "int32", - }, - message: { - type: "string", - }, - }, - }, - }, +export const petstore: Specification = { + swagger: "2.0", + info: { + version: "1.0.0", + title: "Swagger Petstore", + license: { + name: "MIT", + }, + }, + host: "petstore.swagger.io", + basePath: "/v1", + schemes: ["http"], + consumes: ["application/json"], + produces: ["application/json"], + paths: { + "/pets": { + get: { + summary: "List all pets", + operationId: "listPets", + tags: ["pets"], + parameters: [ + { + name: "limit", + in: "query", + description: "How many items to return at one time (max 100)", + required: false, + type: "integer", + format: "int32", + }, + ], + responses: { + 200: { + description: "An paged array of pets", + headers: { + "x-next": { + type: "string", + description: "A link to the next page of responses", + }, + }, + schema: { + $ref: "#/definitions/Pets", + }, + }, + default: { + description: "unexpected error", + schema: { + $ref: "#/definitions/Error", + }, + }, + }, + }, + post: { + summary: "Create a pet", + operationId: "createPets", + tags: ["pets"], + responses: { + 201: { + description: "Null response", + }, + default: { + description: "unexpected error", + schema: { + $ref: "#/definitions/Error", + }, + }, + }, + }, + }, + "/pets/{petId}": { + get: { + summary: "Info for a specific pet", + operationId: "showPetById", + tags: ["pets"], + parameters: [ + { + name: "petId", + in: "path", + required: true, + description: "The id of the pet to retrieve", + type: "string", + }, + ], + responses: { + 200: { + description: "Expected response to a valid request", + schema: { + $ref: "#/definitions/Pets", + }, + }, + default: { + description: "unexpected error", + schema: { + $ref: "#/definitions/Error", + }, + }, + }, + }, + }, + }, + definitions: { + Pet: { + required: ["id", "name"], + properties: { + id: { + type: "integer", + format: "int64", + }, + name: { + type: "string", + }, + tag: { + type: "string", + }, + }, + }, + Pets: { + type: "array", + items: { + $ref: "#/definitions/Pet", + }, + }, + Error: { + required: ["code", "message"], + properties: { + code: { + type: "integer", + format: "int32", + }, + message: { + type: "string", + }, + }, + }, + }, }; diff --git a/tests/2.0/uber.ts b/tests/2.0/uber.ts index f6534ef..5e9ee71 100644 --- a/tests/2.0/uber.ts +++ b/tests/2.0/uber.ts @@ -1,372 +1,372 @@ import type { Specification } from "../../2.0"; -const _uber: Specification = { - swagger: "2.0", - info: { - title: "Uber API", - description: "Move your app forward with the Uber API", - version: "1.0.0", - }, - host: "api.uber.com", - schemes: ["https"], - basePath: "/v1", - produces: ["application/json"], - paths: { - "/products": { - get: { - summary: "Product Types", - description: - "The Products endpoint returns information about the Uber products offered at a given location. The response includes the display name and other details about each product, and lists the products in the proper display order.", - parameters: [ - { - name: "latitude", - in: "query", - description: "Latitude component of location.", - required: true, - type: "number", - format: "double", - }, - { - name: "longitude", - in: "query", - description: "Longitude component of location.", - required: true, - type: "number", - format: "double", - }, - ], - tags: ["Products"], - responses: { - 200: { - description: "An array of products", - schema: { - type: "array", - items: { - $ref: "#/definitions/Product", - }, - }, - }, - default: { - description: "Unexpected error", - schema: { - $ref: "#/definitions/Error", - }, - }, - }, - }, - }, - "/estimates/price": { - get: { - summary: "Price Estimates", - description: - "The Price Estimates endpoint returns an estimated price range for each product offered at a given location. The price estimate is provided as a formatted string with the full price range and the localized currency symbol.

The response also includes low and high estimates, and the [ISO 4217](http://en.wikipedia.org/wiki/ISO_4217) currency code for situations requiring currency conversion. When surge is active for a particular product, its surge_multiplier will be greater than 1, but the price estimate already factors in this multiplier.", - parameters: [ - { - name: "start_latitude", - in: "query", - description: "Latitude component of start location.", - required: true, - type: "number", - format: "double", - }, - { - name: "start_longitude", - in: "query", - description: "Longitude component of start location.", - required: true, - type: "number", - format: "double", - }, - { - name: "end_latitude", - in: "query", - description: "Latitude component of end location.", - required: true, - type: "number", - format: "double", - }, - { - name: "end_longitude", - in: "query", - description: "Longitude component of end location.", - required: true, - type: "number", - format: "double", - }, - ], - tags: ["Estimates"], - responses: { - 200: { - description: "An array of price estimates by product", - schema: { - type: "array", - items: { - $ref: "#/definitions/PriceEstimate", - }, - }, - }, - default: { - description: "Unexpected error", - schema: { - $ref: "#/definitions/Error", - }, - }, - }, - }, - }, - "/estimates/time": { - get: { - summary: "Time Estimates", - description: - "The Time Estimates endpoint returns ETAs for all products offered at a given location, with the responses expressed as integers in seconds. We recommend that this endpoint be called every minute to provide the most accurate, up-to-date ETAs.", - parameters: [ - { - name: "start_latitude", - in: "query", - description: "Latitude component of start location.", - required: true, - type: "number", - format: "double", - }, - { - name: "start_longitude", - in: "query", - description: "Longitude component of start location.", - required: true, - type: "number", - format: "double", - }, - { - name: "customer_uuid", - in: "query", - type: "string", - format: "uuid", - description: - "Unique customer identifier to be used for experience customization.", - }, - { - name: "product_id", - in: "query", - type: "string", - description: - "Unique identifier representing a specific product for a given latitude & longitude.", - }, - ], - tags: ["Estimates"], - responses: { - 200: { - description: "An array of products", - schema: { - type: "array", - items: { - $ref: "#/definitions/Product", - }, - }, - }, - default: { - description: "Unexpected error", - schema: { - $ref: "#/definitions/Error", - }, - }, - }, - }, - }, - "/me": { - get: { - summary: "User Profile", - description: - "The User Profile endpoint returns information about the Uber user that has authorized with the application.", - tags: ["User"], - responses: { - 200: { - description: "Profile information for a user", - schema: { - $ref: "#/definitions/Profile", - }, - }, - default: { - description: "Unexpected error", - schema: { - $ref: "#/definitions/Error", - }, - }, - }, - }, - }, - "/history": { - get: { - summary: "User Activity", - description: - "The User Activity endpoint returns data about a user's lifetime activity with Uber. The response will include pickup locations and times, dropoff locations and times, the distance of past requests, and information about which products were requested.

The history array in the response will have a maximum length based on the limit parameter. The response value count may exceed limit, therefore subsequent API requests may be necessary.", - parameters: [ - { - name: "offset", - in: "query", - type: "integer", - format: "int32", - description: - "Offset the list of returned results by this amount. Default is zero.", - }, - { - name: "limit", - in: "query", - type: "integer", - format: "int32", - description: - "Number of items to retrieve. Default is 5, maximum is 100.", - }, - ], - tags: ["User"], - responses: { - 200: { - description: "History information for the given user", - schema: { - $ref: "#/definitions/Activities", - }, - }, - default: { - description: "Unexpected error", - schema: { - $ref: "#/definitions/Error", - }, - }, - }, - }, - }, - }, - definitions: { - Product: { - properties: { - product_id: { - type: "string", - description: - "Unique identifier representing a specific product for a given latitude & longitude. For example, uberX in San Francisco will have a different product_id than uberX in Los Angeles.", - }, - description: { - type: "string", - description: "Description of product.", - }, - display_name: { - type: "string", - description: "Display name of product.", - }, - capacity: { - type: "string", - description: "Capacity of product. For example, 4 people.", - }, - image: { - type: "string", - description: "Image URL representing the product.", - }, - }, - }, - PriceEstimate: { - properties: { - product_id: { - type: "string", - description: - "Unique identifier representing a specific product for a given latitude & longitude. For example, uberX in San Francisco will have a different product_id than uberX in Los Angeles", - }, - currency_code: { - type: "string", - description: - "[ISO 4217](http://en.wikipedia.org/wiki/ISO_4217) currency code.", - }, - display_name: { - type: "string", - description: "Display name of product.", - }, - estimate: { - type: "string", - description: - 'Formatted string of estimate in local currency of the start location. Estimate could be a range, a single number (flat rate) or "Metered" for TAXI.', - }, - low_estimate: { - type: "number", - description: "Lower bound of the estimated price.", - }, - high_estimate: { - type: "number", - description: "Upper bound of the estimated price.", - }, - surge_multiplier: { - type: "number", - description: - "Expected surge multiplier. Surge is active if surge_multiplier is greater than 1. Price estimate already factors in the surge multiplier.", - }, - }, - }, - Profile: { - properties: { - first_name: { - type: "string", - description: "First name of the Uber user.", - }, - last_name: { - type: "string", - description: "Last name of the Uber user.", - }, - email: { - type: "string", - description: "Email address of the Uber user", - }, - picture: { - type: "string", - description: "Image URL of the Uber user.", - }, - promo_code: { - type: "string", - description: "Promo code of the Uber user.", - }, - }, - }, - Activity: { - properties: { - uuid: { - type: "string", - description: "Unique identifier for the activity", - }, - }, - }, - Activities: { - properties: { - offset: { - type: "integer", - format: "int32", - description: "Position in pagination.", - }, - limit: { - type: "integer", - format: "int32", - description: "Number of items to retrieve (100 max).", - }, - count: { - type: "integer", - format: "int32", - description: "Total number of items available.", - }, - history: { - type: "array", - items: { - $ref: "#/definitions/Activity", - }, - }, - }, - }, - Error: { - properties: { - code: { - type: "integer", - format: "int32", - }, - message: { - type: "string", - }, - fields: { - type: "string", - }, - }, - }, - }, +export const uber: Specification = { + swagger: "2.0", + info: { + title: "Uber API", + description: "Move your app forward with the Uber API", + version: "1.0.0", + }, + host: "api.uber.com", + schemes: ["https"], + basePath: "/v1", + produces: ["application/json"], + paths: { + "/products": { + get: { + summary: "Product Types", + description: + "The Products endpoint returns information about the Uber products offered at a given location. The response includes the display name and other details about each product, and lists the products in the proper display order.", + parameters: [ + { + name: "latitude", + in: "query", + description: "Latitude component of location.", + required: true, + type: "number", + format: "double", + }, + { + name: "longitude", + in: "query", + description: "Longitude component of location.", + required: true, + type: "number", + format: "double", + }, + ], + tags: ["Products"], + responses: { + 200: { + description: "An array of products", + schema: { + type: "array", + items: { + $ref: "#/definitions/Product", + }, + }, + }, + default: { + description: "Unexpected error", + schema: { + $ref: "#/definitions/Error", + }, + }, + }, + }, + }, + "/estimates/price": { + get: { + summary: "Price Estimates", + description: + "The Price Estimates endpoint returns an estimated price range for each product offered at a given location. The price estimate is provided as a formatted string with the full price range and the localized currency symbol.

The response also includes low and high estimates, and the [ISO 4217](http://en.wikipedia.org/wiki/ISO_4217) currency code for situations requiring currency conversion. When surge is active for a particular product, its surge_multiplier will be greater than 1, but the price estimate already factors in this multiplier.", + parameters: [ + { + name: "start_latitude", + in: "query", + description: "Latitude component of start location.", + required: true, + type: "number", + format: "double", + }, + { + name: "start_longitude", + in: "query", + description: "Longitude component of start location.", + required: true, + type: "number", + format: "double", + }, + { + name: "end_latitude", + in: "query", + description: "Latitude component of end location.", + required: true, + type: "number", + format: "double", + }, + { + name: "end_longitude", + in: "query", + description: "Longitude component of end location.", + required: true, + type: "number", + format: "double", + }, + ], + tags: ["Estimates"], + responses: { + 200: { + description: "An array of price estimates by product", + schema: { + type: "array", + items: { + $ref: "#/definitions/PriceEstimate", + }, + }, + }, + default: { + description: "Unexpected error", + schema: { + $ref: "#/definitions/Error", + }, + }, + }, + }, + }, + "/estimates/time": { + get: { + summary: "Time Estimates", + description: + "The Time Estimates endpoint returns ETAs for all products offered at a given location, with the responses expressed as integers in seconds. We recommend that this endpoint be called every minute to provide the most accurate, up-to-date ETAs.", + parameters: [ + { + name: "start_latitude", + in: "query", + description: "Latitude component of start location.", + required: true, + type: "number", + format: "double", + }, + { + name: "start_longitude", + in: "query", + description: "Longitude component of start location.", + required: true, + type: "number", + format: "double", + }, + { + name: "customer_uuid", + in: "query", + type: "string", + format: "uuid", + description: + "Unique customer identifier to be used for experience customization.", + }, + { + name: "product_id", + in: "query", + type: "string", + description: + "Unique identifier representing a specific product for a given latitude & longitude.", + }, + ], + tags: ["Estimates"], + responses: { + 200: { + description: "An array of products", + schema: { + type: "array", + items: { + $ref: "#/definitions/Product", + }, + }, + }, + default: { + description: "Unexpected error", + schema: { + $ref: "#/definitions/Error", + }, + }, + }, + }, + }, + "/me": { + get: { + summary: "User Profile", + description: + "The User Profile endpoint returns information about the Uber user that has authorized with the application.", + tags: ["User"], + responses: { + 200: { + description: "Profile information for a user", + schema: { + $ref: "#/definitions/Profile", + }, + }, + default: { + description: "Unexpected error", + schema: { + $ref: "#/definitions/Error", + }, + }, + }, + }, + }, + "/history": { + get: { + summary: "User Activity", + description: + "The User Activity endpoint returns data about a user's lifetime activity with Uber. The response will include pickup locations and times, dropoff locations and times, the distance of past requests, and information about which products were requested.

The history array in the response will have a maximum length based on the limit parameter. The response value count may exceed limit, therefore subsequent API requests may be necessary.", + parameters: [ + { + name: "offset", + in: "query", + type: "integer", + format: "int32", + description: + "Offset the list of returned results by this amount. Default is zero.", + }, + { + name: "limit", + in: "query", + type: "integer", + format: "int32", + description: + "Number of items to retrieve. Default is 5, maximum is 100.", + }, + ], + tags: ["User"], + responses: { + 200: { + description: "History information for the given user", + schema: { + $ref: "#/definitions/Activities", + }, + }, + default: { + description: "Unexpected error", + schema: { + $ref: "#/definitions/Error", + }, + }, + }, + }, + }, + }, + definitions: { + Product: { + properties: { + product_id: { + type: "string", + description: + "Unique identifier representing a specific product for a given latitude & longitude. For example, uberX in San Francisco will have a different product_id than uberX in Los Angeles.", + }, + description: { + type: "string", + description: "Description of product.", + }, + display_name: { + type: "string", + description: "Display name of product.", + }, + capacity: { + type: "string", + description: "Capacity of product. For example, 4 people.", + }, + image: { + type: "string", + description: "Image URL representing the product.", + }, + }, + }, + PriceEstimate: { + properties: { + product_id: { + type: "string", + description: + "Unique identifier representing a specific product for a given latitude & longitude. For example, uberX in San Francisco will have a different product_id than uberX in Los Angeles", + }, + currency_code: { + type: "string", + description: + "[ISO 4217](http://en.wikipedia.org/wiki/ISO_4217) currency code.", + }, + display_name: { + type: "string", + description: "Display name of product.", + }, + estimate: { + type: "string", + description: + 'Formatted string of estimate in local currency of the start location. Estimate could be a range, a single number (flat rate) or "Metered" for TAXI.', + }, + low_estimate: { + type: "number", + description: "Lower bound of the estimated price.", + }, + high_estimate: { + type: "number", + description: "Upper bound of the estimated price.", + }, + surge_multiplier: { + type: "number", + description: + "Expected surge multiplier. Surge is active if surge_multiplier is greater than 1. Price estimate already factors in the surge multiplier.", + }, + }, + }, + Profile: { + properties: { + first_name: { + type: "string", + description: "First name of the Uber user.", + }, + last_name: { + type: "string", + description: "Last name of the Uber user.", + }, + email: { + type: "string", + description: "Email address of the Uber user", + }, + picture: { + type: "string", + description: "Image URL of the Uber user.", + }, + promo_code: { + type: "string", + description: "Promo code of the Uber user.", + }, + }, + }, + Activity: { + properties: { + uuid: { + type: "string", + description: "Unique identifier for the activity", + }, + }, + }, + Activities: { + properties: { + offset: { + type: "integer", + format: "int32", + description: "Position in pagination.", + }, + limit: { + type: "integer", + format: "int32", + description: "Number of items to retrieve (100 max).", + }, + count: { + type: "integer", + format: "int32", + description: "Total number of items available.", + }, + history: { + type: "array", + items: { + $ref: "#/definitions/Activity", + }, + }, + }, + }, + Error: { + properties: { + code: { + type: "integer", + format: "int32", + }, + message: { + type: "string", + }, + fields: { + type: "string", + }, + }, + }, + }, }; diff --git a/tests/3.0/api-with-examples.ts b/tests/3.0/api-with-examples.ts index 1cdf88b..05d5fe1 100644 --- a/tests/3.0/api-with-examples.ts +++ b/tests/3.0/api-with-examples.ts @@ -1,194 +1,194 @@ import type { Specification } from "../../3.0"; -const _apiWithExamples: Specification = { - openapi: "3.0.0", - info: { - title: "Simple API overview", - version: "2.0.0", - }, - paths: { - "/": { - get: { - operationId: "listVersionsv2", - summary: "List API versions", - responses: { - "200": { - description: "200 response", - content: { - "application/json": { - examples: { - foo: { - value: { - versions: [ - { - status: "CURRENT", - updated: "2011-01-21T11:33:21Z", - id: "v2.0", - links: [ - { - href: "http://127.0.0.1:8774/v2/", - rel: "self", - }, - ], - }, - { - status: "EXPERIMENTAL", - updated: "2013-07-23T11:33:21Z", - id: "v3.0", - links: [ - { - href: "http://127.0.0.1:8774/v3/", - rel: "self", - }, - ], - }, - ], - }, - }, - }, - }, - }, - }, - "300": { - description: "300 response", - content: { - "application/json": { - examples: { - foo: { - value: { - versions: [ - { - status: "CURRENT", - updated: "2011-01-21T11:33:21Z", - id: "v2.0", - links: [ - { - href: "http://127.0.0.1:8774/v2/", - rel: "self", - }, - ], - }, - { - status: "EXPERIMENTAL", - updated: "2013-07-23T11:33:21Z", - id: "v3.0", - links: [ - { - href: "http://127.0.0.1:8774/v3/", - rel: "self", - }, - ], - }, - ], - }, - }, - }, - }, - }, - }, - }, - }, - }, - "/v2": { - get: { - operationId: "getVersionDetailsv2", - summary: "Show API version details", - responses: { - "200": { - description: "200 response", - content: { - "application/json": { - examples: { - foo: { - value: { - version: { - status: "CURRENT", - updated: "2011-01-21T11:33:21Z", - "media-types": [ - { - base: "application/xml", - type: "application/vnd.openstack.compute+xml;version=2", - }, - { - base: "application/json", - type: "application/vnd.openstack.compute+json;version=2", - }, - ], - id: "v2.0", - links: [ - { - href: "http://127.0.0.1:8774/v2/", - rel: "self", - }, - { - href: "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf", - type: "application/pdf", - rel: "describedby", - }, - { - href: "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl", - type: "application/vnd.sun.wadl+xml", - rel: "describedby", - }, - { - href: "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl", - type: "application/vnd.sun.wadl+xml", - rel: "describedby", - }, - ], - }, - }, - }, - }, - }, - }, - }, - "203": { - description: "203 response", - content: { - "application/json": { - examples: { - foo: { - value: { - version: { - status: "CURRENT", - updated: "2011-01-21T11:33:21Z", - "media-types": [ - { - base: "application/xml", - type: "application/vnd.openstack.compute+xml;version=2", - }, - { - base: "application/json", - type: "application/vnd.openstack.compute+json;version=2", - }, - ], - id: "v2.0", - links: [ - { - href: "http://23.253.228.211:8774/v2/", - rel: "self", - }, - { - href: "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf", - type: "application/pdf", - rel: "describedby", - }, - { - href: "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl", - type: "application/vnd.sun.wadl+xml", - rel: "describedby", - }, - ], - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, +export const apiWithExamples: Specification = { + openapi: "3.0.0", + info: { + title: "Simple API overview", + version: "2.0.0", + }, + paths: { + "/": { + get: { + operationId: "listVersionsv2", + summary: "List API versions", + responses: { + "200": { + description: "200 response", + content: { + "application/json": { + examples: { + foo: { + value: { + versions: [ + { + status: "CURRENT", + updated: "2011-01-21T11:33:21Z", + id: "v2.0", + links: [ + { + href: "http://127.0.0.1:8774/v2/", + rel: "self", + }, + ], + }, + { + status: "EXPERIMENTAL", + updated: "2013-07-23T11:33:21Z", + id: "v3.0", + links: [ + { + href: "http://127.0.0.1:8774/v3/", + rel: "self", + }, + ], + }, + ], + }, + }, + }, + }, + }, + }, + "300": { + description: "300 response", + content: { + "application/json": { + examples: { + foo: { + value: { + versions: [ + { + status: "CURRENT", + updated: "2011-01-21T11:33:21Z", + id: "v2.0", + links: [ + { + href: "http://127.0.0.1:8774/v2/", + rel: "self", + }, + ], + }, + { + status: "EXPERIMENTAL", + updated: "2013-07-23T11:33:21Z", + id: "v3.0", + links: [ + { + href: "http://127.0.0.1:8774/v3/", + rel: "self", + }, + ], + }, + ], + }, + }, + }, + }, + }, + }, + }, + }, + }, + "/v2": { + get: { + operationId: "getVersionDetailsv2", + summary: "Show API version details", + responses: { + "200": { + description: "200 response", + content: { + "application/json": { + examples: { + foo: { + value: { + version: { + status: "CURRENT", + updated: "2011-01-21T11:33:21Z", + "media-types": [ + { + base: "application/xml", + type: "application/vnd.openstack.compute+xml;version=2", + }, + { + base: "application/json", + type: "application/vnd.openstack.compute+json;version=2", + }, + ], + id: "v2.0", + links: [ + { + href: "http://127.0.0.1:8774/v2/", + rel: "self", + }, + { + href: "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf", + type: "application/pdf", + rel: "describedby", + }, + { + href: "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl", + type: "application/vnd.sun.wadl+xml", + rel: "describedby", + }, + { + href: "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl", + type: "application/vnd.sun.wadl+xml", + rel: "describedby", + }, + ], + }, + }, + }, + }, + }, + }, + }, + "203": { + description: "203 response", + content: { + "application/json": { + examples: { + foo: { + value: { + version: { + status: "CURRENT", + updated: "2011-01-21T11:33:21Z", + "media-types": [ + { + base: "application/xml", + type: "application/vnd.openstack.compute+xml;version=2", + }, + { + base: "application/json", + type: "application/vnd.openstack.compute+json;version=2", + }, + ], + id: "v2.0", + links: [ + { + href: "http://23.253.228.211:8774/v2/", + rel: "self", + }, + { + href: "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf", + type: "application/pdf", + rel: "describedby", + }, + { + href: "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl", + type: "application/vnd.sun.wadl+xml", + rel: "describedby", + }, + ], + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, }; diff --git a/tests/3.0/callback-example.ts b/tests/3.0/callback-example.ts index 48c18e1..83914a3 100644 --- a/tests/3.0/callback-example.ts +++ b/tests/3.0/callback-example.ts @@ -1,88 +1,88 @@ import type { Specification } from "../../3.0"; -const _callbackExample: Specification = { - openapi: "3.0.0", - info: { - title: "Callback Example", - version: "1.0.0", - }, - paths: { - "/streams": { - post: { - description: "subscribes a client to receive out-of-band data", - parameters: [ - { - name: "callbackUrl", - in: "query", - required: true, - description: - "the location where data will be sent. Must be network accessible\nby the source server\n", - schema: { - type: "string", - format: "uri", - example: "https://tonys-server.com", - }, - }, - ], - responses: { - "201": { - description: "subscription successfully created", - content: { - "application/json": { - schema: { - description: "subscription information", - required: ["subscriptionId"], - properties: { - subscriptionId: { - description: - "this unique identifier allows management of the subscription", - type: "string", - example: "2531329f-fb09-4ef7-887e-84e648214436", - }, - }, - }, - }, - }, - }, - }, - callbacks: { - onData: { - "{$request.query.callbackUrl}/data": { - post: { - requestBody: { - description: "subscription payload", - content: { - "application/json": { - schema: { - type: "object", - properties: { - timestamp: { - type: "string", - format: "date-time", - }, - userData: { - type: "string", - }, - }, - }, - }, - }, - }, - responses: { - "202": { - description: - "Your server implementation should return this HTTP status code\nif the data was received successfully\n", - }, - "204": { - description: - "Your server should return this HTTP status code if no longer interested\nin further updates\n", - }, - }, - }, - }, - }, - }, - }, - }, - }, +export const callbackExample: Specification = { + openapi: "3.0.0", + info: { + title: "Callback Example", + version: "1.0.0", + }, + paths: { + "/streams": { + post: { + description: "subscribes a client to receive out-of-band data", + parameters: [ + { + name: "callbackUrl", + in: "query", + required: true, + description: + "the location where data will be sent. Must be network accessible\nby the source server\n", + schema: { + type: "string", + format: "uri", + example: "https://tonys-server.com", + }, + }, + ], + responses: { + "201": { + description: "subscription successfully created", + content: { + "application/json": { + schema: { + description: "subscription information", + required: ["subscriptionId"], + properties: { + subscriptionId: { + description: + "this unique identifier allows management of the subscription", + type: "string", + example: "2531329f-fb09-4ef7-887e-84e648214436", + }, + }, + }, + }, + }, + }, + }, + callbacks: { + onData: { + "{$request.query.callbackUrl}/data": { + post: { + requestBody: { + description: "subscription payload", + content: { + "application/json": { + schema: { + type: "object", + properties: { + timestamp: { + type: "string", + format: "date-time", + }, + userData: { + type: "string", + }, + }, + }, + }, + }, + }, + responses: { + "202": { + description: + "Your server implementation should return this HTTP status code\nif the data was received successfully\n", + }, + "204": { + description: + "Your server should return this HTTP status code if no longer interested\nin further updates\n", + }, + }, + }, + }, + }, + }, + }, + }, + }, }; diff --git a/tests/3.0/link-example.ts b/tests/3.0/link-example.ts index b92f6c7..fac16e4 100644 --- a/tests/3.0/link-example.ts +++ b/tests/3.0/link-example.ts @@ -1,321 +1,321 @@ import type { Specification } from "../../3.0"; -const _linkExample: Specification = { - openapi: "3.0.0", - info: { - title: "Link Example", - version: "1.0.0", - }, - paths: { - "/2.0/users/{username}": { - get: { - operationId: "getUserByName", - parameters: [ - { - name: "username", - in: "path", - required: true, - schema: { - type: "string", - }, - }, - ], - responses: { - "200": { - description: "The User", - content: { - "application/json": { - schema: { - $ref: "#/components/schemas/user", - }, - }, - }, - links: { - userRepositories: { - $ref: "#/components/links/UserRepositories", - }, - }, - }, - }, - }, - }, - "/2.0/repositories/{username}": { - get: { - operationId: "getRepositoriesByOwner", - parameters: [ - { - name: "username", - in: "path", - required: true, - schema: { - type: "string", - }, - }, - ], - responses: { - "200": { - description: "repositories owned by the supplied user", - content: { - "application/json": { - schema: { - type: "array", - items: { - $ref: "#/components/schemas/repository", - }, - }, - }, - }, - links: { - userRepository: { - $ref: "#/components/links/UserRepository", - }, - }, - }, - }, - }, - }, - "/2.0/repositories/{username}/{slug}": { - get: { - operationId: "getRepository", - parameters: [ - { - name: "username", - in: "path", - required: true, - schema: { - type: "string", - }, - }, - { - name: "slug", - in: "path", - required: true, - schema: { - type: "string", - }, - }, - ], - responses: { - "200": { - description: "The repository", - content: { - "application/json": { - schema: { - $ref: "#/components/schemas/repository", - }, - }, - }, - links: { - repositoryPullRequests: { - $ref: "#/components/links/RepositoryPullRequests", - }, - }, - }, - }, - }, - }, - "/2.0/repositories/{username}/{slug}/pullrequests": { - get: { - operationId: "getPullRequestsByRepository", - parameters: [ - { - name: "username", - in: "path", - required: true, - schema: { - type: "string", - }, - }, - { - name: "slug", - in: "path", - required: true, - schema: { - type: "string", - }, - }, - { - name: "state", - in: "query", - schema: { - type: "string", - enum: ["open", "merged", "declined"], - }, - }, - ], - responses: { - "200": { - description: "an array of pull request objects", - content: { - "application/json": { - schema: { - type: "array", - items: { - $ref: "#/components/schemas/pullrequest", - }, - }, - }, - }, - }, - }, - }, - }, - "/2.0/repositories/{username}/{slug}/pullrequests/{pid}": { - get: { - operationId: "getPullRequestsById", - parameters: [ - { - name: "username", - in: "path", - required: true, - schema: { - type: "string", - }, - }, - { - name: "slug", - in: "path", - required: true, - schema: { - type: "string", - }, - }, - { - name: "pid", - in: "path", - required: true, - schema: { - type: "string", - }, - }, - ], - responses: { - "200": { - description: "a pull request object", - content: { - "application/json": { - schema: { - $ref: "#/components/schemas/pullrequest", - }, - }, - }, - links: { - pullRequestMerge: { - $ref: "#/components/links/PullRequestMerge", - }, - }, - }, - }, - }, - }, - "/2.0/repositories/{username}/{slug}/pullrequests/{pid}/merge": { - post: { - operationId: "mergePullRequest", - parameters: [ - { - name: "username", - in: "path", - required: true, - schema: { - type: "string", - }, - }, - { - name: "slug", - in: "path", - required: true, - schema: { - type: "string", - }, - }, - { - name: "pid", - in: "path", - required: true, - schema: { - type: "string", - }, - }, - ], - responses: { - "204": { - description: "the PR was successfully merged", - }, - }, - }, - }, - }, - components: { - links: { - UserRepositories: { - operationId: "getRepositoriesByOwner", - parameters: { - username: "$response.body#/username", - }, - }, - UserRepository: { - operationId: "getRepository", - parameters: { - username: "$response.body#/owner/username", - slug: "$response.body#/slug", - }, - }, - RepositoryPullRequests: { - operationId: "getPullRequestsByRepository", - parameters: { - username: "$response.body#/owner/username", - slug: "$response.body#/slug", - }, - }, - PullRequestMerge: { - operationId: "mergePullRequest", - parameters: { - username: "$response.body#/author/username", - slug: "$response.body#/repository/slug", - pid: "$response.body#/id", - }, - }, - }, - schemas: { - user: { - type: "object", - properties: { - username: { - type: "string", - }, - uuid: { - type: "string", - }, - }, - }, - repository: { - type: "object", - properties: { - slug: { - type: "string", - }, - owner: { - $ref: "#/components/schemas/user", - }, - }, - }, - pullrequest: { - type: "object", - properties: { - id: { - type: "integer", - }, - title: { - type: "string", - }, - repository: { - $ref: "#/components/schemas/repository", - }, - author: { - $ref: "#/components/schemas/user", - }, - }, - }, - }, - }, +export const linkExample: Specification = { + openapi: "3.0.0", + info: { + title: "Link Example", + version: "1.0.0", + }, + paths: { + "/2.0/users/{username}": { + get: { + operationId: "getUserByName", + parameters: [ + { + name: "username", + in: "path", + required: true, + schema: { + type: "string", + }, + }, + ], + responses: { + "200": { + description: "The User", + content: { + "application/json": { + schema: { + $ref: "#/components/schemas/user", + }, + }, + }, + links: { + userRepositories: { + $ref: "#/components/links/UserRepositories", + }, + }, + }, + }, + }, + }, + "/2.0/repositories/{username}": { + get: { + operationId: "getRepositoriesByOwner", + parameters: [ + { + name: "username", + in: "path", + required: true, + schema: { + type: "string", + }, + }, + ], + responses: { + "200": { + description: "repositories owned by the supplied user", + content: { + "application/json": { + schema: { + type: "array", + items: { + $ref: "#/components/schemas/repository", + }, + }, + }, + }, + links: { + userRepository: { + $ref: "#/components/links/UserRepository", + }, + }, + }, + }, + }, + }, + "/2.0/repositories/{username}/{slug}": { + get: { + operationId: "getRepository", + parameters: [ + { + name: "username", + in: "path", + required: true, + schema: { + type: "string", + }, + }, + { + name: "slug", + in: "path", + required: true, + schema: { + type: "string", + }, + }, + ], + responses: { + "200": { + description: "The repository", + content: { + "application/json": { + schema: { + $ref: "#/components/schemas/repository", + }, + }, + }, + links: { + repositoryPullRequests: { + $ref: "#/components/links/RepositoryPullRequests", + }, + }, + }, + }, + }, + }, + "/2.0/repositories/{username}/{slug}/pullrequests": { + get: { + operationId: "getPullRequestsByRepository", + parameters: [ + { + name: "username", + in: "path", + required: true, + schema: { + type: "string", + }, + }, + { + name: "slug", + in: "path", + required: true, + schema: { + type: "string", + }, + }, + { + name: "state", + in: "query", + schema: { + type: "string", + enum: ["open", "merged", "declined"], + }, + }, + ], + responses: { + "200": { + description: "an array of pull request objects", + content: { + "application/json": { + schema: { + type: "array", + items: { + $ref: "#/components/schemas/pullrequest", + }, + }, + }, + }, + }, + }, + }, + }, + "/2.0/repositories/{username}/{slug}/pullrequests/{pid}": { + get: { + operationId: "getPullRequestsById", + parameters: [ + { + name: "username", + in: "path", + required: true, + schema: { + type: "string", + }, + }, + { + name: "slug", + in: "path", + required: true, + schema: { + type: "string", + }, + }, + { + name: "pid", + in: "path", + required: true, + schema: { + type: "string", + }, + }, + ], + responses: { + "200": { + description: "a pull request object", + content: { + "application/json": { + schema: { + $ref: "#/components/schemas/pullrequest", + }, + }, + }, + links: { + pullRequestMerge: { + $ref: "#/components/links/PullRequestMerge", + }, + }, + }, + }, + }, + }, + "/2.0/repositories/{username}/{slug}/pullrequests/{pid}/merge": { + post: { + operationId: "mergePullRequest", + parameters: [ + { + name: "username", + in: "path", + required: true, + schema: { + type: "string", + }, + }, + { + name: "slug", + in: "path", + required: true, + schema: { + type: "string", + }, + }, + { + name: "pid", + in: "path", + required: true, + schema: { + type: "string", + }, + }, + ], + responses: { + "204": { + description: "the PR was successfully merged", + }, + }, + }, + }, + }, + components: { + links: { + UserRepositories: { + operationId: "getRepositoriesByOwner", + parameters: { + username: "$response.body#/username", + }, + }, + UserRepository: { + operationId: "getRepository", + parameters: { + username: "$response.body#/owner/username", + slug: "$response.body#/slug", + }, + }, + RepositoryPullRequests: { + operationId: "getPullRequestsByRepository", + parameters: { + username: "$response.body#/owner/username", + slug: "$response.body#/slug", + }, + }, + PullRequestMerge: { + operationId: "mergePullRequest", + parameters: { + username: "$response.body#/author/username", + slug: "$response.body#/repository/slug", + pid: "$response.body#/id", + }, + }, + }, + schemas: { + user: { + type: "object", + properties: { + username: { + type: "string", + }, + uuid: { + type: "string", + }, + }, + }, + repository: { + type: "object", + properties: { + slug: { + type: "string", + }, + owner: { + $ref: "#/components/schemas/user", + }, + }, + }, + pullrequest: { + type: "object", + properties: { + id: { + type: "integer", + }, + title: { + type: "string", + }, + repository: { + $ref: "#/components/schemas/repository", + }, + author: { + $ref: "#/components/schemas/user", + }, + }, + }, + }, + }, }; diff --git a/tests/3.0/petstore-expanded.ts b/tests/3.0/petstore-expanded.ts index 6b09d84..bde0800 100644 --- a/tests/3.0/petstore-expanded.ts +++ b/tests/3.0/petstore-expanded.ts @@ -1,240 +1,240 @@ import type { Specification } from "../../3.0"; -const _petstoreExpanded: Specification = { - openapi: "3.0.0", - info: { - version: "1.0.0", - title: "Swagger Petstore", - description: - "A sample API that uses a petstore as an example to demonstrate features in the OpenAPI 3.0 specification", - termsOfService: "http://swagger.io/terms/", - contact: { - name: "Swagger API Team", - email: "apiteam@swagger.io", - url: "http://swagger.io", - }, - license: { - name: "Apache 2.0", - url: "https://www.apache.org/licenses/LICENSE-2.0.html", - }, - }, - servers: [ - { - url: "https://petstore.swagger.io/v2", - }, - ], - paths: { - "/pets": { - get: { - description: - "Returns all pets from the system that the user has access to\nNam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia.\n\nSed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien.\n", - operationId: "findPets", - parameters: [ - { - name: "tags", - in: "query", - description: "tags to filter by", - required: false, - style: "form", - schema: { - type: "array", - items: { - type: "string", - }, - }, - }, - { - name: "limit", - in: "query", - description: "maximum number of results to return", - required: false, - schema: { - type: "integer", - format: "int32", - }, - }, - ], - responses: { - "200": { - description: "pet response", - content: { - "application/json": { - schema: { - type: "array", - items: { - $ref: "#/components/schemas/Pet", - }, - }, - }, - }, - }, - default: { - description: "unexpected error", - content: { - "application/json": { - schema: { - $ref: "#/components/schemas/Error", - }, - }, - }, - }, - }, - }, - post: { - description: "Creates a new pet in the store. Duplicates are allowed", - operationId: "addPet", - requestBody: { - description: "Pet to add to the store", - required: true, - content: { - "application/json": { - schema: { - $ref: "#/components/schemas/NewPet", - }, - }, - }, - }, - responses: { - "200": { - description: "pet response", - content: { - "application/json": { - schema: { - $ref: "#/components/schemas/Pet", - }, - }, - }, - }, - default: { - description: "unexpected error", - content: { - "application/json": { - schema: { - $ref: "#/components/schemas/Error", - }, - }, - }, - }, - }, - }, - }, - "/pets/{id}": { - get: { - description: - "Returns a user based on a single ID, if the user does not have access to the pet", - operationId: "find pet by id", - parameters: [ - { - name: "id", - in: "path", - description: "ID of pet to fetch", - required: true, - schema: { - type: "integer", - format: "int64", - }, - }, - ], - responses: { - "200": { - description: "pet response", - content: { - "application/json": { - schema: { - $ref: "#/components/schemas/Pet", - }, - }, - }, - }, - default: { - description: "unexpected error", - content: { - "application/json": { - schema: { - $ref: "#/components/schemas/Error", - }, - }, - }, - }, - }, - }, - delete: { - description: "deletes a single pet based on the ID supplied", - operationId: "deletePet", - parameters: [ - { - name: "id", - in: "path", - description: "ID of pet to delete", - required: true, - schema: { - type: "integer", - format: "int64", - }, - }, - ], - responses: { - "204": { - description: "pet deleted", - }, - default: { - description: "unexpected error", - content: { - "application/json": { - schema: { - $ref: "#/components/schemas/Error", - }, - }, - }, - }, - }, - }, - }, - }, - components: { - schemas: { - Pet: { - allOf: [ - { - $ref: "#/components/schemas/NewPet", - }, - { - type: "object", - required: ["id"], - properties: { - id: { - type: "integer", - format: "int64", - }, - }, - }, - ], - }, - NewPet: { - type: "object", - required: ["name"], - properties: { - name: { - type: "string", - }, - tag: { - type: "string", - }, - }, - }, - Error: { - type: "object", - required: ["code", "message"], - properties: { - code: { - type: "integer", - format: "int32", - }, - message: { - type: "string", - }, - }, - }, - }, - }, +export const petstoreExpanded: Specification = { + openapi: "3.0.0", + info: { + version: "1.0.0", + title: "Swagger Petstore", + description: + "A sample API that uses a petstore as an example to demonstrate features in the OpenAPI 3.0 specification", + termsOfService: "http://swagger.io/terms/", + contact: { + name: "Swagger API Team", + email: "apiteam@swagger.io", + url: "http://swagger.io", + }, + license: { + name: "Apache 2.0", + url: "https://www.apache.org/licenses/LICENSE-2.0.html", + }, + }, + servers: [ + { + url: "https://petstore.swagger.io/v2", + }, + ], + paths: { + "/pets": { + get: { + description: + "Returns all pets from the system that the user has access to\nNam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia.\n\nSed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien.\n", + operationId: "findPets", + parameters: [ + { + name: "tags", + in: "query", + description: "tags to filter by", + required: false, + style: "form", + schema: { + type: "array", + items: { + type: "string", + }, + }, + }, + { + name: "limit", + in: "query", + description: "maximum number of results to return", + required: false, + schema: { + type: "integer", + format: "int32", + }, + }, + ], + responses: { + "200": { + description: "pet response", + content: { + "application/json": { + schema: { + type: "array", + items: { + $ref: "#/components/schemas/Pet", + }, + }, + }, + }, + }, + default: { + description: "unexpected error", + content: { + "application/json": { + schema: { + $ref: "#/components/schemas/Error", + }, + }, + }, + }, + }, + }, + post: { + description: "Creates a new pet in the store. Duplicates are allowed", + operationId: "addPet", + requestBody: { + description: "Pet to add to the store", + required: true, + content: { + "application/json": { + schema: { + $ref: "#/components/schemas/NewPet", + }, + }, + }, + }, + responses: { + "200": { + description: "pet response", + content: { + "application/json": { + schema: { + $ref: "#/components/schemas/Pet", + }, + }, + }, + }, + default: { + description: "unexpected error", + content: { + "application/json": { + schema: { + $ref: "#/components/schemas/Error", + }, + }, + }, + }, + }, + }, + }, + "/pets/{id}": { + get: { + description: + "Returns a user based on a single ID, if the user does not have access to the pet", + operationId: "find pet by id", + parameters: [ + { + name: "id", + in: "path", + description: "ID of pet to fetch", + required: true, + schema: { + type: "integer", + format: "int64", + }, + }, + ], + responses: { + "200": { + description: "pet response", + content: { + "application/json": { + schema: { + $ref: "#/components/schemas/Pet", + }, + }, + }, + }, + default: { + description: "unexpected error", + content: { + "application/json": { + schema: { + $ref: "#/components/schemas/Error", + }, + }, + }, + }, + }, + }, + delete: { + description: "deletes a single pet based on the ID supplied", + operationId: "deletePet", + parameters: [ + { + name: "id", + in: "path", + description: "ID of pet to delete", + required: true, + schema: { + type: "integer", + format: "int64", + }, + }, + ], + responses: { + "204": { + description: "pet deleted", + }, + default: { + description: "unexpected error", + content: { + "application/json": { + schema: { + $ref: "#/components/schemas/Error", + }, + }, + }, + }, + }, + }, + }, + }, + components: { + schemas: { + Pet: { + allOf: [ + { + $ref: "#/components/schemas/NewPet", + }, + { + type: "object", + required: ["id"], + properties: { + id: { + type: "integer", + format: "int64", + }, + }, + }, + ], + }, + NewPet: { + type: "object", + required: ["name"], + properties: { + name: { + type: "string", + }, + tag: { + type: "string", + }, + }, + }, + Error: { + type: "object", + required: ["code", "message"], + properties: { + code: { + type: "integer", + format: "int32", + }, + message: { + type: "string", + }, + }, + }, + }, + }, }; diff --git a/tests/3.0/petstore.ts b/tests/3.0/petstore.ts index edd67f7..d9ed4ec 100644 --- a/tests/3.0/petstore.ts +++ b/tests/3.0/petstore.ts @@ -1,179 +1,179 @@ import type { Specification } from "../../3.0"; -const _petstore: Specification = { - openapi: "3.0.0", - info: { - version: "1.0.0", - title: "Swagger Petstore", - license: { - name: "MIT", - }, - }, - servers: [ - { - url: "http://petstore.swagger.io/v1", - }, - ], - paths: { - "/pets": { - get: { - summary: "List all pets", - operationId: "listPets", - tags: ["pets"], - parameters: [ - { - name: "limit", - in: "query", - description: "How many items to return at one time (max 100)", - required: false, - schema: { - type: "integer", - maximum: 100, - format: "int32", - }, - }, - ], - responses: { - "200": { - description: "A paged array of pets", - headers: { - "x-next": { - description: "A link to the next page of responses", - schema: { - type: "string", - }, - }, - }, - content: { - "application/json": { - schema: { - $ref: "#/components/schemas/Pets", - }, - }, - }, - }, - default: { - description: "unexpected error", - content: { - "application/json": { - schema: { - $ref: "#/components/schemas/Error", - }, - }, - }, - }, - }, - }, - post: { - summary: "Create a pet", - operationId: "createPets", - tags: ["pets"], - requestBody: { - content: { - "application/json": { - schema: { - $ref: "#/components/schemas/Pet", - }, - }, - }, - required: true, - }, - responses: { - "201": { - description: "Null response", - }, - default: { - description: "unexpected error", - content: { - "application/json": { - schema: { - $ref: "#/components/schemas/Error", - }, - }, - }, - }, - }, - }, - }, - "/pets/{petId}": { - get: { - summary: "Info for a specific pet", - operationId: "showPetById", - tags: ["pets"], - parameters: [ - { - name: "petId", - in: "path", - required: true, - description: "The id of the pet to retrieve", - schema: { - type: "string", - }, - }, - ], - responses: { - "200": { - description: "Expected response to a valid request", - content: { - "application/json": { - schema: { - $ref: "#/components/schemas/Pet", - }, - }, - }, - }, - default: { - description: "unexpected error", - content: { - "application/json": { - schema: { - $ref: "#/components/schemas/Error", - }, - }, - }, - }, - }, - }, - }, - }, - components: { - schemas: { - Pet: { - type: "object", - required: ["id", "name"], - properties: { - id: { - type: "integer", - format: "int64", - }, - name: { - type: "string", - }, - tag: { - type: "string", - }, - }, - }, - Pets: { - type: "array", - maxItems: 100, - items: { - $ref: "#/components/schemas/Pet", - }, - }, - Error: { - type: "object", - required: ["code", "message"], - properties: { - code: { - type: "integer", - format: "int32", - }, - message: { - type: "string", - }, - }, - }, - }, - }, +export const petstore: Specification = { + openapi: "3.0.0", + info: { + version: "1.0.0", + title: "Swagger Petstore", + license: { + name: "MIT", + }, + }, + servers: [ + { + url: "http://petstore.swagger.io/v1", + }, + ], + paths: { + "/pets": { + get: { + summary: "List all pets", + operationId: "listPets", + tags: ["pets"], + parameters: [ + { + name: "limit", + in: "query", + description: "How many items to return at one time (max 100)", + required: false, + schema: { + type: "integer", + maximum: 100, + format: "int32", + }, + }, + ], + responses: { + "200": { + description: "A paged array of pets", + headers: { + "x-next": { + description: "A link to the next page of responses", + schema: { + type: "string", + }, + }, + }, + content: { + "application/json": { + schema: { + $ref: "#/components/schemas/Pets", + }, + }, + }, + }, + default: { + description: "unexpected error", + content: { + "application/json": { + schema: { + $ref: "#/components/schemas/Error", + }, + }, + }, + }, + }, + }, + post: { + summary: "Create a pet", + operationId: "createPets", + tags: ["pets"], + requestBody: { + content: { + "application/json": { + schema: { + $ref: "#/components/schemas/Pet", + }, + }, + }, + required: true, + }, + responses: { + "201": { + description: "Null response", + }, + default: { + description: "unexpected error", + content: { + "application/json": { + schema: { + $ref: "#/components/schemas/Error", + }, + }, + }, + }, + }, + }, + }, + "/pets/{petId}": { + get: { + summary: "Info for a specific pet", + operationId: "showPetById", + tags: ["pets"], + parameters: [ + { + name: "petId", + in: "path", + required: true, + description: "The id of the pet to retrieve", + schema: { + type: "string", + }, + }, + ], + responses: { + "200": { + description: "Expected response to a valid request", + content: { + "application/json": { + schema: { + $ref: "#/components/schemas/Pet", + }, + }, + }, + }, + default: { + description: "unexpected error", + content: { + "application/json": { + schema: { + $ref: "#/components/schemas/Error", + }, + }, + }, + }, + }, + }, + }, + }, + components: { + schemas: { + Pet: { + type: "object", + required: ["id", "name"], + properties: { + id: { + type: "integer", + format: "int64", + }, + name: { + type: "string", + }, + tag: { + type: "string", + }, + }, + }, + Pets: { + type: "array", + maxItems: 100, + items: { + $ref: "#/components/schemas/Pet", + }, + }, + Error: { + type: "object", + required: ["code", "message"], + properties: { + code: { + type: "integer", + format: "int32", + }, + message: { + type: "string", + }, + }, + }, + }, + }, }; diff --git a/tests/3.0/uspto.ts b/tests/3.0/uspto.ts index 8e65406..c24cc1b 100644 --- a/tests/3.0/uspto.ts +++ b/tests/3.0/uspto.ts @@ -1,257 +1,257 @@ import type { Specification } from "../../3.0"; -const _uspto: Specification = { - openapi: "3.0.1", - servers: [ - { - url: "{scheme}://developer.uspto.gov/ds-api", - variables: { - scheme: { - description: "The Data Set API is accessible via https and http", - enum: ["https", "http"], - default: "https", - }, - }, - }, - ], - info: { - description: - "The Data Set API (DSAPI) allows the public users to discover and search USPTO exported data sets. This is a generic API that allows USPTO users to make any CSV based data files searchable through API. With the help of GET call, it returns the list of data fields that are searchable. With the help of POST call, data can be fetched based on the filters on the field names. Please note that POST call is used to search the actual data. The reason for the POST call is that it allows users to specify any complex search criteria without worry about the GET size limitations as well as encoding of the input parameters.", - version: "1.0.0", - title: "USPTO Data Set API", - contact: { - name: "Open Data Portal", - url: "https://developer.uspto.gov", - email: "developer@uspto.gov", - }, - }, - tags: [ - { - name: "metadata", - description: "Find out about the data sets", - }, - { - name: "search", - description: "Search a data set", - }, - ], - paths: { - "/": { - get: { - tags: ["metadata"], - operationId: "list-data-sets", - summary: "List available data sets", - responses: { - "200": { - description: "Returns a list of data sets", - content: { - "application/json": { - schema: { - $ref: "#/components/schemas/dataSetList", - }, - example: { - total: 2, - apis: [ - { - apiKey: "oa_citations", - apiVersionNumber: "v1", - apiUrl: - "https://developer.uspto.gov/ds-api/oa_citations/v1/fields", - apiDocumentationUrl: - "https://developer.uspto.gov/ds-api-docs/index.html?url=https://developer.uspto.gov/ds-api/swagger/docs/oa_citations.json", - }, - { - apiKey: "cancer_moonshot", - apiVersionNumber: "v1", - apiUrl: - "https://developer.uspto.gov/ds-api/cancer_moonshot/v1/fields", - apiDocumentationUrl: - "https://developer.uspto.gov/ds-api-docs/index.html?url=https://developer.uspto.gov/ds-api/swagger/docs/cancer_moonshot.json", - }, - ], - }, - }, - }, - }, - }, - }, - }, - "/{dataset}/{version}/fields": { - get: { - tags: ["metadata"], - summary: - "Provides the general information about the API and the list of fields that can be used to query the dataset.", - description: - "This GET API returns the list of all the searchable field names that are in the oa_citations. Please see the 'fields' attribute which returns an array of field names. Each field or a combination of fields can be searched using the syntax options shown below.", - operationId: "list-searchable-fields", - parameters: [ - { - name: "dataset", - in: "path", - description: "Name of the dataset.", - required: true, - example: "oa_citations", - schema: { - type: "string", - }, - }, - { - name: "version", - in: "path", - description: "Version of the dataset.", - required: true, - example: "v1", - schema: { - type: "string", - }, - }, - ], - responses: { - "200": { - description: - "The dataset API for the given version is found and it is accessible to consume.", - content: { - "application/json": { - schema: { - type: "string", - }, - }, - }, - }, - "404": { - description: - "The combination of dataset name and version is not found in the system or it is not published yet to be consumed by public.", - content: { - "application/json": { - schema: { - type: "string", - }, - }, - }, - }, - }, - }, - }, - "/{dataset}/{version}/records": { - post: { - tags: ["search"], - summary: - "Provides search capability for the data set with the given search criteria.", - description: - "This API is based on Solr/Lucene Search. The data is indexed using SOLR. This GET API returns the list of all the searchable field names that are in the Solr Index. Please see the 'fields' attribute which returns an array of field names. Each field or a combination of fields can be searched using the Solr/Lucene Syntax. Please refer https://lucene.apache.org/core/3_6_2/queryparsersyntax.html#Overview for the query syntax. List of field names that are searchable can be determined using above GET api.", - operationId: "perform-search", - parameters: [ - { - name: "version", - in: "path", - description: "Version of the dataset.", - required: true, - schema: { - type: "string", - default: "v1", - }, - }, - { - name: "dataset", - in: "path", - description: - "Name of the dataset. In this case, the default value is oa_citations", - required: true, - schema: { - type: "string", - default: "oa_citations", - }, - }, - ], - responses: { - "200": { - description: "successful operation", - content: { - "application/json": { - schema: { - type: "array", - items: { - type: "object", - additionalProperties: { - type: "object", - }, - }, - }, - }, - }, - }, - "404": { - description: "No matching record found for the given criteria.", - }, - }, - requestBody: { - content: { - "application/x-www-form-urlencoded": { - schema: { - type: "object", - properties: { - criteria: { - description: - "Uses Lucene Query Syntax in the format of propertyName:value, propertyName:[num1 TO num2] and date range format: propertyName:[yyyyMMdd TO yyyyMMdd]. In the response please see the 'docs' element which has the list of record objects. Each record structure would consist of all the fields and their corresponding values.", - type: "string", - default: "*:*", - }, - start: { - description: "Starting record number. Default value is 0.", - type: "integer", - default: 0, - }, - rows: { - description: - "Specify number of rows to be returned. If you run the search with default values, in the response you will see 'numFound' attribute which will tell the number of records available in the dataset.", - type: "integer", - default: 100, - }, - }, - required: ["criteria"], - }, - }, - }, - }, - }, - }, - }, - components: { - schemas: { - dataSetList: { - type: "object", - properties: { - total: { - type: "integer", - }, - apis: { - type: "array", - items: { - type: "object", - properties: { - apiKey: { - type: "string", - description: "To be used as a dataset parameter value", - }, - apiVersionNumber: { - type: "string", - description: "To be used as a version parameter value", - }, - apiUrl: { - type: "string", - format: "uriref", - description: "The URL describing the dataset's fields", - }, - apiDocumentationUrl: { - type: "string", - format: "uriref", - description: "A URL to the API console for each API", - }, - }, - }, - }, - }, - }, - }, - }, +export const uspto: Specification = { + openapi: "3.0.1", + servers: [ + { + url: "{scheme}://developer.uspto.gov/ds-api", + variables: { + scheme: { + description: "The Data Set API is accessible via https and http", + enum: ["https", "http"], + default: "https", + }, + }, + }, + ], + info: { + description: + "The Data Set API (DSAPI) allows the public users to discover and search USPTO exported data sets. This is a generic API that allows USPTO users to make any CSV based data files searchable through API. With the help of GET call, it returns the list of data fields that are searchable. With the help of POST call, data can be fetched based on the filters on the field names. Please note that POST call is used to search the actual data. The reason for the POST call is that it allows users to specify any complex search criteria without worry about the GET size limitations as well as encoding of the input parameters.", + version: "1.0.0", + title: "USPTO Data Set API", + contact: { + name: "Open Data Portal", + url: "https://developer.uspto.gov", + email: "developer@uspto.gov", + }, + }, + tags: [ + { + name: "metadata", + description: "Find out about the data sets", + }, + { + name: "search", + description: "Search a data set", + }, + ], + paths: { + "/": { + get: { + tags: ["metadata"], + operationId: "list-data-sets", + summary: "List available data sets", + responses: { + "200": { + description: "Returns a list of data sets", + content: { + "application/json": { + schema: { + $ref: "#/components/schemas/dataSetList", + }, + example: { + total: 2, + apis: [ + { + apiKey: "oa_citations", + apiVersionNumber: "v1", + apiUrl: + "https://developer.uspto.gov/ds-api/oa_citations/v1/fields", + apiDocumentationUrl: + "https://developer.uspto.gov/ds-api-docs/index.html?url=https://developer.uspto.gov/ds-api/swagger/docs/oa_citations.json", + }, + { + apiKey: "cancer_moonshot", + apiVersionNumber: "v1", + apiUrl: + "https://developer.uspto.gov/ds-api/cancer_moonshot/v1/fields", + apiDocumentationUrl: + "https://developer.uspto.gov/ds-api-docs/index.html?url=https://developer.uspto.gov/ds-api/swagger/docs/cancer_moonshot.json", + }, + ], + }, + }, + }, + }, + }, + }, + }, + "/{dataset}/{version}/fields": { + get: { + tags: ["metadata"], + summary: + "Provides the general information about the API and the list of fields that can be used to query the dataset.", + description: + "This GET API returns the list of all the searchable field names that are in the oa_citations. Please see the 'fields' attribute which returns an array of field names. Each field or a combination of fields can be searched using the syntax options shown below.", + operationId: "list-searchable-fields", + parameters: [ + { + name: "dataset", + in: "path", + description: "Name of the dataset.", + required: true, + example: "oa_citations", + schema: { + type: "string", + }, + }, + { + name: "version", + in: "path", + description: "Version of the dataset.", + required: true, + example: "v1", + schema: { + type: "string", + }, + }, + ], + responses: { + "200": { + description: + "The dataset API for the given version is found and it is accessible to consume.", + content: { + "application/json": { + schema: { + type: "string", + }, + }, + }, + }, + "404": { + description: + "The combination of dataset name and version is not found in the system or it is not published yet to be consumed by public.", + content: { + "application/json": { + schema: { + type: "string", + }, + }, + }, + }, + }, + }, + }, + "/{dataset}/{version}/records": { + post: { + tags: ["search"], + summary: + "Provides search capability for the data set with the given search criteria.", + description: + "This API is based on Solr/Lucene Search. The data is indexed using SOLR. This GET API returns the list of all the searchable field names that are in the Solr Index. Please see the 'fields' attribute which returns an array of field names. Each field or a combination of fields can be searched using the Solr/Lucene Syntax. Please refer https://lucene.apache.org/core/3_6_2/queryparsersyntax.html#Overview for the query syntax. List of field names that are searchable can be determined using above GET api.", + operationId: "perform-search", + parameters: [ + { + name: "version", + in: "path", + description: "Version of the dataset.", + required: true, + schema: { + type: "string", + default: "v1", + }, + }, + { + name: "dataset", + in: "path", + description: + "Name of the dataset. In this case, the default value is oa_citations", + required: true, + schema: { + type: "string", + default: "oa_citations", + }, + }, + ], + responses: { + "200": { + description: "successful operation", + content: { + "application/json": { + schema: { + type: "array", + items: { + type: "object", + additionalProperties: { + type: "object", + }, + }, + }, + }, + }, + }, + "404": { + description: "No matching record found for the given criteria.", + }, + }, + requestBody: { + content: { + "application/x-www-form-urlencoded": { + schema: { + type: "object", + properties: { + criteria: { + description: + "Uses Lucene Query Syntax in the format of propertyName:value, propertyName:[num1 TO num2] and date range format: propertyName:[yyyyMMdd TO yyyyMMdd]. In the response please see the 'docs' element which has the list of record objects. Each record structure would consist of all the fields and their corresponding values.", + type: "string", + default: "*:*", + }, + start: { + description: "Starting record number. Default value is 0.", + type: "integer", + default: 0, + }, + rows: { + description: + "Specify number of rows to be returned. If you run the search with default values, in the response you will see 'numFound' attribute which will tell the number of records available in the dataset.", + type: "integer", + default: 100, + }, + }, + required: ["criteria"], + }, + }, + }, + }, + }, + }, + }, + components: { + schemas: { + dataSetList: { + type: "object", + properties: { + total: { + type: "integer", + }, + apis: { + type: "array", + items: { + type: "object", + properties: { + apiKey: { + type: "string", + description: "To be used as a dataset parameter value", + }, + apiVersionNumber: { + type: "string", + description: "To be used as a version parameter value", + }, + apiUrl: { + type: "string", + format: "uriref", + description: "The URL describing the dataset's fields", + }, + apiDocumentationUrl: { + type: "string", + format: "uriref", + description: "A URL to the API console for each API", + }, + }, + }, + }, + }, + }, + }, + }, }; diff --git a/tests/3.1/non-oauth-scopes.ts b/tests/3.1/non-oauth-scopes.ts index 5f45023..e4e064b 100644 --- a/tests/3.1/non-oauth-scopes.ts +++ b/tests/3.1/non-oauth-scopes.ts @@ -1,34 +1,34 @@ import type { Specification } from "../../3.1"; -const _nonOauthScopes: Specification = { - openapi: "3.1.0", - info: { - title: "Non-oAuth Scopes example", - version: "1.0.0", - }, - paths: { - "/users": { - //@ts-expect-error This is an example specification from OpenAPI, - // it seems to intentionally not conform to the specification, - // as its meant to be a minimal example. - get: { - security: [ - { - bearerAuth: ["read:users", "public"], - }, - ], - }, - }, - }, - components: { - securitySchemes: { - bearerAuth: { - type: "http", - scheme: "bearer", - bearerFormat: "jwt", - description: - "note: non-oauth scopes are not defined at the securityScheme level", - }, - }, - }, +export const nonOauthScopes: Specification = { + openapi: "3.1.0", + info: { + title: "Non-oAuth Scopes example", + version: "1.0.0", + }, + paths: { + "/users": { + //@ts-expect-error This is an example specification from OpenAPI, + // it seems to intentionally not conform to the specification, + // as its meant to be a minimal example. + get: { + security: [ + { + bearerAuth: ["read:users", "public"], + }, + ], + }, + }, + }, + components: { + securitySchemes: { + bearerAuth: { + type: "http", + scheme: "bearer", + bearerFormat: "jwt", + description: + "note: non-oauth scopes are not defined at the securityScheme level", + }, + }, + }, }; diff --git a/tests/3.1/tictactoe.ts b/tests/3.1/tictactoe.ts index 2da7bfa..b9ed504 100644 --- a/tests/3.1/tictactoe.ts +++ b/tests/3.1/tictactoe.ts @@ -1,266 +1,266 @@ import type { Specification } from "../../3.1"; -const _tictactoe: Specification = { - openapi: "3.1.0", - info: { - title: "Tic Tac Toe", - description: - "This API allows writing down marks on a Tic Tac Toe board\nand requesting the state of the board or of individual squares.\n", - version: "1.0.0", - }, - tags: [ - { - name: "Gameplay", - }, - ], - paths: { - "/board": { - get: { - summary: "Get the whole board", - description: "Retrieves the current state of the board and the winner.", - tags: ["Gameplay"], - operationId: "get-board", - responses: { - "200": { - description: "OK", - content: { - "application/json": { - schema: { - $ref: "#/components/schemas/status", - }, - }, - }, - }, - }, - security: [ - { - defaultApiKey: [], - }, - { - app2AppOauth: ["board:read"], - }, - ], - }, - }, - "/board/{row}/{column}": { - parameters: [ - { - $ref: "#/components/parameters/rowParam", - }, - { - $ref: "#/components/parameters/columnParam", - }, - ], - get: { - summary: "Get a single board square", - description: "Retrieves the requested square.", - tags: ["Gameplay"], - operationId: "get-square", - responses: { - "200": { - description: "OK", - content: { - "application/json": { - schema: { - $ref: "#/components/schemas/mark", - }, - }, - }, - }, - "400": { - description: "The provided parameters are incorrect", - content: { - "text/html": { - schema: { - $ref: "#/components/schemas/errorMessage", - }, - example: "Illegal coordinates", - }, - }, - }, - }, - security: [ - { - bearerHttpAuthentication: [], - }, - { - user2AppOauth: ["board:read"], - }, - ], - }, - put: { - summary: "Set a single board square", - description: - "Places a mark on the board and retrieves the whole board and the winner (if any).", - tags: ["Gameplay"], - operationId: "put-square", - requestBody: { - required: true, - content: { - "application/json": { - schema: { - $ref: "#/components/schemas/mark", - }, - }, - }, - }, - responses: { - "200": { - description: "OK", - content: { - "application/json": { - schema: { - $ref: "#/components/schemas/status", - }, - }, - }, - }, - "400": { - description: "The provided parameters are incorrect", - content: { - "text/html": { - schema: { - $ref: "#/components/schemas/errorMessage", - }, - examples: { - illegalCoordinates: { - value: "Illegal coordinates.", - }, - notEmpty: { - value: "Square is not empty.", - }, - invalidMark: { - value: "Invalid Mark (X or O).", - }, - }, - }, - }, - }, - }, - security: [ - { - bearerHttpAuthentication: [], - }, - { - user2AppOauth: ["board:write"], - }, - ], - }, - }, - }, - components: { - parameters: { - rowParam: { - description: "Board row (vertical coordinate)", - name: "row", - in: "path", - required: true, - schema: { - $ref: "#/components/schemas/coordinate", - }, - }, - columnParam: { - description: "Board column (horizontal coordinate)", - name: "column", - in: "path", - required: true, - schema: { - $ref: "#/components/schemas/coordinate", - }, - }, - }, - schemas: { - errorMessage: { - type: "string", - maxLength: 256, - description: "A text message describing an error", - }, - coordinate: { - type: "integer", - minimum: 1, - maximum: 3, - example: 1, - }, - mark: { - type: "string", - enum: [".", "X", "O"], - description: - "Possible values for a board square. `.` means empty square.", - example: ".", - }, - board: { - type: "array", - maxItems: 3, - minItems: 3, - items: { - type: "array", - maxItems: 3, - minItems: 3, - items: { - $ref: "#/components/schemas/mark", - }, - }, - }, - winner: { - type: "string", - enum: [".", "X", "O"], - description: "Winner of the game. `.` means nobody has won yet.", - example: ".", - }, - status: { - type: "object", - properties: { - winner: { - $ref: "#/components/schemas/winner", - }, - board: { - $ref: "#/components/schemas/board", - }, - }, - }, - }, - securitySchemes: { - defaultApiKey: { - description: "API key provided in console", - type: "apiKey", - name: "api-key", - in: "header", - }, - basicHttpAuthentication: { - description: "Basic HTTP Authentication", - type: "http", - scheme: "Basic", - }, - bearerHttpAuthentication: { - description: "Bearer token using a JWT", - type: "http", - scheme: "Bearer", - bearerFormat: "JWT", - }, - app2AppOauth: { - type: "oauth2", - flows: { - clientCredentials: { - tokenUrl: "https://learn.openapis.org/oauth/2.0/token", - scopes: { - "board:read": "Read the board", - }, - }, - }, - }, - user2AppOauth: { - type: "oauth2", - flows: { - authorizationCode: { - authorizationUrl: "https://learn.openapis.org/oauth/2.0/auth", - tokenUrl: "https://learn.openapis.org/oauth/2.0/token", - scopes: { - "board:read": "Read the board", - "board:write": "Write to the board", - }, - }, - }, - }, - }, - }, +export const tictactoe: Specification = { + openapi: "3.1.0", + info: { + title: "Tic Tac Toe", + description: + "This API allows writing down marks on a Tic Tac Toe board\nand requesting the state of the board or of individual squares.\n", + version: "1.0.0", + }, + tags: [ + { + name: "Gameplay", + }, + ], + paths: { + "/board": { + get: { + summary: "Get the whole board", + description: "Retrieves the current state of the board and the winner.", + tags: ["Gameplay"], + operationId: "get-board", + responses: { + "200": { + description: "OK", + content: { + "application/json": { + schema: { + $ref: "#/components/schemas/status", + }, + }, + }, + }, + }, + security: [ + { + defaultApiKey: [], + }, + { + app2AppOauth: ["board:read"], + }, + ], + }, + }, + "/board/{row}/{column}": { + parameters: [ + { + $ref: "#/components/parameters/rowParam", + }, + { + $ref: "#/components/parameters/columnParam", + }, + ], + get: { + summary: "Get a single board square", + description: "Retrieves the requested square.", + tags: ["Gameplay"], + operationId: "get-square", + responses: { + "200": { + description: "OK", + content: { + "application/json": { + schema: { + $ref: "#/components/schemas/mark", + }, + }, + }, + }, + "400": { + description: "The provided parameters are incorrect", + content: { + "text/html": { + schema: { + $ref: "#/components/schemas/errorMessage", + }, + example: "Illegal coordinates", + }, + }, + }, + }, + security: [ + { + bearerHttpAuthentication: [], + }, + { + user2AppOauth: ["board:read"], + }, + ], + }, + put: { + summary: "Set a single board square", + description: + "Places a mark on the board and retrieves the whole board and the winner (if any).", + tags: ["Gameplay"], + operationId: "put-square", + requestBody: { + required: true, + content: { + "application/json": { + schema: { + $ref: "#/components/schemas/mark", + }, + }, + }, + }, + responses: { + "200": { + description: "OK", + content: { + "application/json": { + schema: { + $ref: "#/components/schemas/status", + }, + }, + }, + }, + "400": { + description: "The provided parameters are incorrect", + content: { + "text/html": { + schema: { + $ref: "#/components/schemas/errorMessage", + }, + examples: { + illegalCoordinates: { + value: "Illegal coordinates.", + }, + notEmpty: { + value: "Square is not empty.", + }, + invalidMark: { + value: "Invalid Mark (X or O).", + }, + }, + }, + }, + }, + }, + security: [ + { + bearerHttpAuthentication: [], + }, + { + user2AppOauth: ["board:write"], + }, + ], + }, + }, + }, + components: { + parameters: { + rowParam: { + description: "Board row (vertical coordinate)", + name: "row", + in: "path", + required: true, + schema: { + $ref: "#/components/schemas/coordinate", + }, + }, + columnParam: { + description: "Board column (horizontal coordinate)", + name: "column", + in: "path", + required: true, + schema: { + $ref: "#/components/schemas/coordinate", + }, + }, + }, + schemas: { + errorMessage: { + type: "string", + maxLength: 256, + description: "A text message describing an error", + }, + coordinate: { + type: "integer", + minimum: 1, + maximum: 3, + example: 1, + }, + mark: { + type: "string", + enum: [".", "X", "O"], + description: + "Possible values for a board square. `.` means empty square.", + example: ".", + }, + board: { + type: "array", + maxItems: 3, + minItems: 3, + items: { + type: "array", + maxItems: 3, + minItems: 3, + items: { + $ref: "#/components/schemas/mark", + }, + }, + }, + winner: { + type: "string", + enum: [".", "X", "O"], + description: "Winner of the game. `.` means nobody has won yet.", + example: ".", + }, + status: { + type: "object", + properties: { + winner: { + $ref: "#/components/schemas/winner", + }, + board: { + $ref: "#/components/schemas/board", + }, + }, + }, + }, + securitySchemes: { + defaultApiKey: { + description: "API key provided in console", + type: "apiKey", + name: "api-key", + in: "header", + }, + basicHttpAuthentication: { + description: "Basic HTTP Authentication", + type: "http", + scheme: "Basic", + }, + bearerHttpAuthentication: { + description: "Bearer token using a JWT", + type: "http", + scheme: "Bearer", + bearerFormat: "JWT", + }, + app2AppOauth: { + type: "oauth2", + flows: { + clientCredentials: { + tokenUrl: "https://learn.openapis.org/oauth/2.0/token", + scopes: { + "board:read": "Read the board", + }, + }, + }, + }, + user2AppOauth: { + type: "oauth2", + flows: { + authorizationCode: { + authorizationUrl: "https://learn.openapis.org/oauth/2.0/auth", + tokenUrl: "https://learn.openapis.org/oauth/2.0/token", + scopes: { + "board:read": "Read the board", + "board:write": "Write to the board", + }, + }, + }, + }, + }, + }, }; diff --git a/tests/3.1/webhook-example.ts b/tests/3.1/webhook-example.ts index 00e7164..148998d 100644 --- a/tests/3.1/webhook-example.ts +++ b/tests/3.1/webhook-example.ts @@ -1,50 +1,50 @@ import type { Specification } from "../../3.1"; -const _webhookExample: Specification = { - openapi: "3.1.0", - info: { - title: "Webhook Example", - version: "1.0.0", - }, - webhooks: { - newPet: { - post: { - requestBody: { - description: "Information about a new pet in the system", - content: { - "application/json": { - schema: { - $ref: "#/components/schemas/Pet", - }, - }, - }, - }, - responses: { - "200": { - description: - "Return a 200 status to indicate that the data was received successfully", - }, - }, - }, - }, - }, - components: { - schemas: { - Pet: { - required: ["id", "name"], - properties: { - id: { - type: "integer", - format: "int64", - }, - name: { - type: "string", - }, - tag: { - type: "string", - }, - }, - }, - }, - }, +export const webhookExample: Specification = { + openapi: "3.1.0", + info: { + title: "Webhook Example", + version: "1.0.0", + }, + webhooks: { + newPet: { + post: { + requestBody: { + description: "Information about a new pet in the system", + content: { + "application/json": { + schema: { + $ref: "#/components/schemas/Pet", + }, + }, + }, + }, + responses: { + "200": { + description: + "Return a 200 status to indicate that the data was received successfully", + }, + }, + }, + }, + }, + components: { + schemas: { + Pet: { + required: ["id", "name"], + properties: { + id: { + type: "integer", + format: "int64", + }, + name: { + type: "string", + }, + tag: { + type: "string", + }, + }, + }, + }, + }, }; diff --git a/tests/openapi-3.0-schemas.test.ts b/tests/openapi-3.0-schemas.test.ts new file mode 100644 index 0000000..b476657 --- /dev/null +++ b/tests/openapi-3.0-schemas.test.ts @@ -0,0 +1,171 @@ +import { describe, it, expect } from "bun:test"; +import Ajv, { type JSONSchemaType } from "ajv"; +import type { Specification } from "../3.0"; +import { schemas } from "../schemas/3.0"; + +// Import all specification files from tests/3.0 +import { apiWithExamples } from "./3.0/api-with-examples"; +import { callbackExample } from "./3.0/callback-example"; +import { linkExample } from "./3.0/link-example"; +import { petstore } from "./3.0/petstore"; +import { petstoreExpanded } from "./3.0/petstore-expanded"; +import { uspto } from "./3.0/uspto"; + +const ajv = new Ajv({ + allErrors: true, + verbose: true, + strict: false, +}); + +const schema: JSONSchemaType = JSON.parse( + JSON.stringify(schemas.specification) +); + +// validate is a type guard for Specification - type is inferred from schema type +const validate = ajv.compile(schema); + +// All specification files to test +const specsToTest = [ + { name: "API with Examples", spec: apiWithExamples }, + { name: "Callback Example", spec: callbackExample }, + { name: "Link Example", spec: linkExample }, + { name: "Petstore", spec: petstore }, + { name: "Petstore Expanded", spec: petstoreExpanded }, + { name: "USPTO", spec: uspto }, +]; + +describe("OpenAPI 3.0 Schema Validation", () => { + for (const { name, spec } of specsToTest) { + describe(name, () => { + it("should be a valid OpenAPI 3.0 specification", () => { + const isValid = validate(spec); + + if (!isValid) { + console.error(`Validation errors for ${name}:`, validate.errors); + } + + expect(isValid).toBe(true); + }); + + it("should have required openapi version", () => { + expect(spec.openapi).toMatch(/^3\.0\.\d+$/); + }); + + it("should have required info object", () => { + expect(spec.info).toBeDefined(); + expect(spec.info.title).toBeDefined(); + expect(spec.info.version).toBeDefined(); + }); + + it("should have valid paths object", () => { + if (spec.paths) { + expect(typeof spec.paths).toBe("object"); + expect(spec.paths).not.toBeNull(); + } + }); + + it("should have valid components object", () => { + if (spec.components) { + expect(typeof spec.components).toBe("object"); + expect(spec.components).not.toBeNull(); + } + }); + + it("should have valid servers array when present", () => { + if (spec.servers) { + expect(Array.isArray(spec.servers)).toBe(true); + spec.servers.forEach((server) => { + expect(server.url).toBeDefined(); + expect(typeof server.url).toBe("string"); + }); + } + }); + }); + } + + describe("Schema Validation Details", () => { + it("should validate all specifications against the JSON schema", () => { + const results = specsToTest.map(({ name, spec }) => { + const isValid = validate(spec); + return { name, isValid, errors: validate.errors }; + }); + + const failedSpecs = results.filter((result) => !result.isValid); + + if (failedSpecs.length > 0) { + console.error("Failed specifications:"); + failedSpecs.forEach(({ name, errors }) => { + console.error(`${name}:`, errors); + }); + } + + expect(failedSpecs.length).toBe(0); + }); + + it("should have consistent openapi version across all specs", () => { + const versions = specsToTest.map(({ spec }) => spec.openapi); + const uniqueVersions = [...new Set(versions)]; + + expect(uniqueVersions.length).toBeGreaterThan(0); + uniqueVersions.forEach((version) => { + expect(version).toMatch(/^3\.0\.\d+$/); + }); + }); + + it("should have valid server URLs when present", () => { + specsToTest.forEach(({ name, spec }) => { + if (spec.servers) { + spec.servers.forEach((server) => { + // Server URL should be a valid URL format + expect(server.url).toMatch(/^https?:\/\/|^\/|^\{/); + }); + } + }); + }); + + it("should have valid server variables when present", () => { + specsToTest.forEach(({ name, spec }) => { + if (spec.servers) { + spec.servers.forEach((server) => { + if (server.variables) { + expect(typeof server.variables).toBe("object"); + Object.values(server.variables).forEach((variable) => { + expect(variable).toHaveProperty("default"); + }); + } + }); + } + }); + }); + + it("should have valid tags when present", () => { + specsToTest.forEach(({ name, spec }) => { + if (spec.tags) { + expect(Array.isArray(spec.tags)).toBe(true); + spec.tags.forEach((tag) => { + expect(tag.name).toBeDefined(); + expect(typeof tag.name).toBe("string"); + }); + } + }); + }); + + it("should have valid security schemes when present", () => { + specsToTest.forEach(({ name, spec }) => { + if (spec.components?.securitySchemes) { + expect(typeof spec.components.securitySchemes).toBe("object"); + Object.values(spec.components.securitySchemes).forEach((scheme) => { + // Type guard to check if it's not a Reference + if (!("$ref" in scheme)) { + expect(scheme).toHaveProperty("type"); + expect(scheme.type).toBeDefined(); + expect(["apiKey", "http", "oauth2", "openIdConnect"]).toContain( + scheme.type + ); + } + }); + } + }); + }); + }); +}); diff --git a/tests/openapi-3.1-schemas.test.ts b/tests/openapi-3.1-schemas.test.ts new file mode 100644 index 0000000..a4cb7d2 --- /dev/null +++ b/tests/openapi-3.1-schemas.test.ts @@ -0,0 +1,217 @@ +import { describe, it, expect } from "bun:test"; +import Ajv, { type JSONSchemaType } from "ajv"; +import type { Specification } from "../3.1"; +import { schemas } from "../schemas/3.1"; + +// Import all specification files from tests/3.1 +import { nonOauthScopes } from "./3.1/non-oauth-scopes"; +import { tictactoe } from "./3.1/tictactoe"; +import { webhookExample } from "./3.1/webhook-example"; + +const ajv = new Ajv({ + allErrors: true, + verbose: true, + strict: false, +}); + +const schema: JSONSchemaType = JSON.parse( + JSON.stringify(schemas.specification) +); + +// validate is a type guard for Specification - type is inferred from schema type +const validate = ajv.compile(schema); + +// All specification files to test +const specsToTest = [ + { name: "Non-OAuth Scopes", spec: nonOauthScopes, skipValidation: true }, // Intentionally incomplete example + { name: "Tic Tac Toe", spec: tictactoe }, + { name: "Webhook Example", spec: webhookExample }, +]; + +describe("OpenAPI 3.1 Schema Validation", () => { + for (const { name, spec, skipValidation } of specsToTest) { + describe(name, () => { + it("should be a valid OpenAPI 3.1 specification", () => { + if (skipValidation) { + console.log( + `Skipping validation for ${name} (intentionally incomplete example)` + ); + expect(true).toBe(true); // Pass the test + return; + } + + const isValid = validate(spec); + + if (!isValid) { + console.error(`Validation errors for ${name}:`, validate.errors); + } + + expect(isValid).toBe(true); + }); + + it("should have required openapi version", () => { + expect(spec.openapi).toMatch(/^3\.1\.\d+$/); + }); + + it("should have required info object", () => { + expect(spec.info).toBeDefined(); + expect(spec.info.title).toBeDefined(); + expect(spec.info.version).toBeDefined(); + }); + + it("should have valid paths object", () => { + if (spec.paths) { + expect(typeof spec.paths).toBe("object"); + expect(spec.paths).not.toBeNull(); + } + }); + + it("should have valid components object", () => { + if (spec.components) { + expect(typeof spec.components).toBe("object"); + expect(spec.components).not.toBeNull(); + } + }); + + it("should have valid servers array when present", () => { + if (spec.servers) { + expect(Array.isArray(spec.servers)).toBe(true); + spec.servers.forEach((server) => { + expect(server.url).toBeDefined(); + expect(typeof server.url).toBe("string"); + }); + } + }); + + it("should have valid webhooks object when present", () => { + if (spec.webhooks) { + expect(typeof spec.webhooks).toBe("object"); + expect(spec.webhooks).not.toBeNull(); + } + }); + }); + } + + describe("Schema Validation Details", () => { + it("should validate all specifications against the JSON schema", () => { + const results = specsToTest.map(({ name, spec, skipValidation }) => { + if (skipValidation) { + return { name, isValid: true, errors: null }; + } + const isValid = validate(spec); + return { name, isValid, errors: validate.errors }; + }); + + const failedSpecs = results.filter((result) => !result.isValid); + + if (failedSpecs.length > 0) { + console.error("Failed specifications:"); + failedSpecs.forEach(({ name, errors }) => { + console.error(`${name}:`, errors); + }); + } + + expect(failedSpecs.length).toBe(0); + }); + + it("should have consistent openapi version across all specs", () => { + const versions = specsToTest.map(({ spec }) => spec.openapi); + const uniqueVersions = [...new Set(versions)]; + + expect(uniqueVersions.length).toBeGreaterThan(0); + uniqueVersions.forEach((version) => { + expect(version).toMatch(/^3\.1\.\d+$/); + }); + }); + + it("should have valid server URLs when present", () => { + specsToTest.forEach(({ name, spec }) => { + if (spec.servers) { + spec.servers.forEach((server) => { + // Server URL should be a valid URL format + expect(server.url).toMatch(/^https?:\/\/|^\/|^\{/); + }); + } + }); + }); + + it("should have valid server variables when present", () => { + specsToTest.forEach(({ name, spec }) => { + if (spec.servers) { + spec.servers.forEach((server) => { + if (server.variables) { + expect(typeof server.variables).toBe("object"); + Object.values(server.variables).forEach((variable) => { + expect(variable).toHaveProperty("default"); + }); + } + }); + } + }); + }); + + it("should have valid tags when present", () => { + specsToTest.forEach(({ name, spec }) => { + if (spec.tags) { + expect(Array.isArray(spec.tags)).toBe(true); + spec.tags.forEach((tag) => { + expect(tag.name).toBeDefined(); + expect(typeof tag.name).toBe("string"); + }); + } + }); + }); + + it("should have valid security schemes when present", () => { + specsToTest.forEach(({ name, spec }) => { + if (spec.components?.securitySchemes) { + expect(typeof spec.components.securitySchemes).toBe("object"); + Object.values(spec.components.securitySchemes).forEach((scheme) => { + // Type guard to check if it's not a Reference + if (!("$ref" in scheme)) { + expect(scheme.type).toBeDefined(); + expect(["apiKey", "http", "oauth2", "openIdConnect"]).toContain( + scheme.type + ); + } + }); + } + }); + }); + + it("should have valid webhook operations when present", () => { + specsToTest.forEach(({ name, spec }) => { + if (spec.webhooks) { + Object.values(spec.webhooks).forEach((webhook) => { + // Type guard to check if it's not a Reference + if (!("$ref" in webhook)) { + expect(webhook).toHaveProperty("post"); + expect(typeof webhook.post).toBe("object"); + } + }); + } + }); + }); + + it("should have valid OAuth2 flows when present", () => { + specsToTest.forEach(({ name, spec }) => { + if (spec.components?.securitySchemes) { + Object.values(spec.components.securitySchemes).forEach((scheme) => { + // Type guard to check if it's not a Reference + if ( + !("$ref" in scheme) && + scheme.type === "oauth2" && + scheme.flows + ) { + expect(typeof scheme.flows).toBe("object"); + Object.values(scheme.flows).forEach((flow) => { + expect(flow).toHaveProperty("scopes"); + expect(typeof flow.scopes).toBe("object"); + }); + } + }); + } + }); + }); + }); +}); diff --git a/tests/swagger-schemas.test.ts b/tests/swagger-schemas.test.ts new file mode 100755 index 0000000..903b23b --- /dev/null +++ b/tests/swagger-schemas.test.ts @@ -0,0 +1,136 @@ +import { describe, it, expect } from "bun:test"; +import Ajv, { type JSONSchemaType } from "ajv"; +import type { Specification } from "../2.0"; +import { schemas } from "../schemas/2.0"; + +// Import all specification files from tests/2.0 +import { apiWithExamples } from "./2.0/api-with-examples"; +import { petstore } from "./2.0/petstore"; +import { petstoreWithExternalDocs } from "./2.0/petstore-with-external-docs"; +import { petstoreSimple } from "./2.0/petstore-simple"; +import { petstoreMinimal } from "./2.0/petstore-minimal"; +import { petstoreExpanded } from "./2.0/petstore-expanded"; +import { uber } from "./2.0/uber"; + +const ajv = new Ajv({ + allErrors: true, + verbose: true, + strict: false, +}); + +const schema: JSONSchemaType = JSON.parse( + JSON.stringify(schemas.specification) +); + +// validate is a type guard for Specification - type is inferred from schema type +const validate = ajv.compile(schema); + +// All specification files to test +const specsToTest = [ + { name: "API with Examples", spec: apiWithExamples }, + { name: "Petstore", spec: petstore }, + { name: "Petstore with External Docs", spec: petstoreWithExternalDocs }, + { name: "Petstore Simple", spec: petstoreSimple }, + { name: "Petstore Minimal", spec: petstoreMinimal }, + { name: "Petstore Expanded", spec: petstoreExpanded }, + { name: "Uber API", spec: uber }, +]; + +describe("Swagger 2.0 Schema Validation", () => { + for (const { name, spec } of specsToTest) { + describe(name, () => { + it("should be a valid Swagger 2.0 specification", () => { + const isValid = validate(spec); + + if (!isValid) { + console.error(`Validation errors for ${name}:`, validate.errors); + } + + expect(isValid).toBe(true); + }); + + it("should have required swagger version", () => { + expect(spec.swagger).toBe("2.0"); + }); + + it("should have required info object", () => { + expect(spec.info).toBeDefined(); + expect(spec.info.title).toBeDefined(); + expect(spec.info.version).toBeDefined(); + }); + + it("should have valid paths object", () => { + if (spec.paths) { + expect(typeof spec.paths).toBe("object"); + expect(spec.paths).not.toBeNull(); + } + }); + + it("should have valid definitions object", () => { + if (spec.definitions) { + expect(typeof spec.definitions).toBe("object"); + expect(spec.definitions).not.toBeNull(); + } + }); + }); + } + + describe("Schema Validation Details", () => { + it("should validate all specifications against the JSON schema", () => { + const results = specsToTest.map(({ name, spec }) => { + const isValid = validate(spec); + return { name, isValid, errors: validate.errors }; + }); + + const failedSpecs = results.filter((result) => !result.isValid); + + if (failedSpecs.length > 0) { + console.error("Failed specifications:"); + failedSpecs.forEach(({ name, errors }) => { + console.error(`${name}:`, errors); + }); + } + + expect(failedSpecs.length).toBe(0); + }); + + it("should have consistent swagger version across all specs", () => { + const versions = specsToTest.map(({ spec }) => spec.swagger); + const uniqueVersions = [...new Set(versions)]; + + expect(uniqueVersions).toHaveLength(1); + expect(uniqueVersions[0]).toBe("2.0"); + }); + + it("should have valid host format when present", () => { + specsToTest.forEach(({ name, spec }) => { + if (spec.host) { + // Host should not contain protocol + expect(spec.host).not.toMatch(/^https?:\/\//); + // Host should not contain path + expect(spec.host).not.toContain("/"); + } + }); + }); + + it("should have valid basePath format when present", () => { + specsToTest.forEach(({ name, spec }) => { + if (spec.basePath) { + // BasePath should start with / + expect(spec.basePath).toMatch(/^\//); + } + }); + }); + + it("should have valid schemes when present", () => { + specsToTest.forEach(({ name, spec }) => { + if (spec.schemes) { + expect(Array.isArray(spec.schemes)).toBe(true); + spec.schemes.forEach((scheme: string) => { + expect(["http", "https", "ws", "wss"]).toContain(scheme); + }); + } + }); + }); + }); +}); diff --git a/tests/validate-schema.ts b/tests/validate-schema.ts deleted file mode 100755 index 4ee6615..0000000 --- a/tests/validate-schema.ts +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/env bun - -import { readFileSync } from "fs"; -import { resolve } from "path"; - -// Simple JSON Schema validation function -function validateAgainstSchema( - data: any, - schema: any -): { valid: boolean; errors: string[] } { - const errors: string[] = []; - - // Basic validation logic (simplified) - if (schema.required) { - for (const field of schema.required) { - if (!(field in data)) { - errors.push(`Missing required field: ${field}`); - } - } - } - - if (schema.type) { - if (schema.type === "object" && typeof data !== "object") { - errors.push(`Expected object, got ${typeof data}`); - } else if (schema.type === "string" && typeof data !== "string") { - errors.push(`Expected string, got ${typeof data}`); - } else if (schema.type === "array" && !Array.isArray(data)) { - errors.push(`Expected array, got ${typeof data}`); - } - } - - return { - valid: errors.length === 0, - errors, - }; -} - -async function validateOpenAPIDocument( - filePath: string, - version: string = "3.0" -): Promise { - try { - console.log(`🔍 Validating OpenAPI document: ${filePath}`); - console.log(`📋 Using OpenAPI ${version} schema`); - - // Load the document - const document = JSON.parse(readFileSync(filePath, "utf-8")); - - // Load the appropriate schema - const schemaPath = resolve(`./schemas/${version}/main/specification.json`); - const schema = JSON.parse(readFileSync(schemaPath, "utf-8")); - - // Validate - const result = validateAgainstSchema(document, schema); - - if (result.valid) { - console.log("✅ Document is valid!"); - } else { - console.log("❌ Document has validation errors:"); - result.errors.forEach((error) => console.log(` - ${error}`)); - } - } catch (error) { - console.error("❌ Validation failed:", error); - } -} - -async function main() { - const args = process.argv.slice(2); - - if (args.length === 0) { - console.log( - "Usage: bun run scripts/validate-schema.ts [version]" - ); - console.log( - "Example: bun run scripts/validate-schema.ts ./my-api.json 3.0" - ); - return; - } - - const filePath = args[0]; - const version = args[1] || "3.0"; - - if (!filePath) { - console.error("❌ Error: File path is required"); - return; - } - - await validateOpenAPIDocument(filePath, version); -} - -// Run the script -main().catch(console.error);