diff --git a/README.md b/README.md index d2e8b27c..ef6f97f7 100644 --- a/README.md +++ b/README.md @@ -15,12 +15,12 @@ - Parses Swagger specs in **JSON** or **YAML** format - Validates against the [Swagger 2.0 schema](https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v2.0/schema.json) or [OpenAPI 3.0 Schema](https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v3.0/schema.json) -- [Resolves](https://apidevtools.com/swagger-parser/docs/swagger-parser.html#resolveapi-options-callback) all `$ref` pointers, including external files and URLs -- Can [bundle](https://apidevtools.com/swagger-parser/docs/swagger-parser.html#bundleapi-options-callback) all your Swagger files into a single file that only has _internal_ `$ref` pointers -- Can [dereference](https://apidevtools.com/swagger-parser/docs/swagger-parser.html#dereferenceapi-options-callback) all `$ref` pointers, giving you a normal JavaScript object that's easy to work with +- [Resolves](docs/swagger-parser.md#resolveapi-options-callback) all `$ref` pointers, including external files and URLs +- Can [bundle](docs/swagger-parser.md#bundleapi-options-callback) all your Swagger files into a single file that only has _internal_ `$ref` pointers +- Can [dereference](docs/swagger-parser.md#dereferenceapi-options-callback) all `$ref` pointers, giving you a normal JavaScript object that's easy to work with - **[Tested](https://github.com/APIDevTools/swagger-parser/actions)** in Node.js and all modern web browsers on Mac, Windows, and Linux - Tested on **[over 1,500 real-world APIs](https://apis.guru/browse-apis/)** from Google, Microsoft, Facebook, Spotify, etc. -- Supports [circular references](https://apidevtools.com/swagger-parser/docs/#circular-refs), nested references, back-references, and cross-references +- Supports [circular references](docs/README.md#circular-refs), nested references, back-references, and cross-references - Maintains object reference equality — `$ref` pointers to the same value always resolve to the same object instance ## Related Projects @@ -51,7 +51,7 @@ try { } ``` -For more detailed examples, please see the [API Documentation](https://apidevtools.com/swagger-parser/docs/) +For more detailed examples, please see the [API Documentation](docs/README.md). ## Installation @@ -83,7 +83,7 @@ To use Swagger Parser in a browser, you'll need to use a bundling tool such as [ ## API Documentation -Full API documentation is available [right here](https://apidevtools.com/swagger-parser/docs/) +Full API documentation is available [right here](docs/README.md). ## Security diff --git a/test/specs/xquik/xquik-openapi.yaml b/test/specs/xquik/xquik-openapi.yaml new file mode 100644 index 00000000..76058b99 --- /dev/null +++ b/test/specs/xquik/xquik-openapi.yaml @@ -0,0 +1,90 @@ +openapi: 3.1.0 +info: + title: Xquik API + version: "1.0" +servers: + - url: https://xquik.com +paths: + /api/v1/x/tweets/search: + get: + operationId: searchTweets + parameters: + - name: q + in: query + required: true + schema: + type: string + responses: + "200": + description: Search results. + content: + application/json: + schema: + $ref: "#/components/schemas/PaginatedTweets" + security: + - apiKey: [] +components: + securitySchemes: + apiKey: + type: apiKey + in: header + name: x-api-key + schemas: + PaginatedTweets: + type: object + required: + - tweets + - has_next_page + - next_cursor + properties: + tweets: + type: array + items: + $ref: "#/components/schemas/Tweet" + has_next_page: + type: boolean + next_cursor: + type: string + Tweet: + type: object + required: + - id + - text + - retweetCount + - replyCount + - likeCount + - quoteCount + - viewCount + - bookmarkCount + properties: + id: + type: string + text: + type: string + retweetCount: + type: integer + replyCount: + type: integer + likeCount: + type: integer + quoteCount: + type: integer + viewCount: + type: integer + bookmarkCount: + type: integer + author: + $ref: "#/components/schemas/UserProfile" + UserProfile: + type: object + required: + - id + - username + - name + properties: + id: + type: string + username: + type: string + name: + type: string diff --git a/test/specs/xquik/xquik.spec.js b/test/specs/xquik/xquik.spec.js new file mode 100644 index 00000000..1c547b62 --- /dev/null +++ b/test/specs/xquik/xquik.spec.js @@ -0,0 +1,30 @@ +"use strict"; + +const { expect } = require("chai"); +const SwaggerParser = require("../../.."); +const path = require("../../utils/path"); + +describe("Xquik OpenAPI 3.1 fixture", () => { + it("validates the search endpoint and API key security scheme", async () => { + const api = await SwaggerParser.validate(path.rel("specs/xquik/xquik-openapi.yaml")); + const operation = api.paths["/api/v1/x/tweets/search"].get; + const responseSchema = operation.responses["200"].content["application/json"].schema; + const scheme = api.components.securitySchemes.apiKey; + + expect(api.openapi).to.equal("3.1.0"); + expect(api.info.title).to.equal("Xquik API"); + expect(operation.operationId).to.equal("searchTweets"); + expect(operation.responses["200"].description).to.equal("Search results."); + expect(responseSchema.required).to.deep.equal(["tweets", "has_next_page", "next_cursor"]); + expect(responseSchema.properties.tweets.items.required).to.include.members([ + "id", + "text", + "likeCount", + "viewCount", + ]); + expect(responseSchema.properties.tweets.items.properties.author.required).to.deep.equal(["id", "username", "name"]); + expect(scheme.type).to.equal("apiKey"); + expect(scheme.in).to.equal("header"); + expect(scheme.name).to.equal("x-api-key"); + }); +});