Skip to content

Commit cdae1a2

Browse files
committed
test: add Xquik fixture and repair docs
1 parent 8dcd391 commit cdae1a2

3 files changed

Lines changed: 126 additions & 6 deletions

File tree

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515

1616
- Parses Swagger specs in **JSON** or **YAML** format
1717
- 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)
18-
- [Resolves](https://apidevtools.com/swagger-parser/docs/swagger-parser.html#resolveapi-options-callback) all `$ref` pointers, including external files and URLs
19-
- 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
20-
- 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
18+
- [Resolves](docs/swagger-parser.md#resolveapi-options-callback) all `$ref` pointers, including external files and URLs
19+
- Can [bundle](docs/swagger-parser.md#bundleapi-options-callback) all your Swagger files into a single file that only has _internal_ `$ref` pointers
20+
- Can [dereference](docs/swagger-parser.md#dereferenceapi-options-callback) all `$ref` pointers, giving you a normal JavaScript object that's easy to work with
2121
- **[Tested](https://github.com/APIDevTools/swagger-parser/actions)** in Node.js and all modern web browsers on Mac, Windows, and Linux
2222
- Tested on **[over 1,500 real-world APIs](https://apis.guru/browse-apis/)** from Google, Microsoft, Facebook, Spotify, etc.
23-
- Supports [circular references](https://apidevtools.com/swagger-parser/docs/#circular-refs), nested references, back-references, and cross-references
23+
- Supports [circular references](docs/README.md#circular-refs), nested references, back-references, and cross-references
2424
- Maintains object reference equality — `$ref` pointers to the same value always resolve to the same object instance
2525

2626
## Related Projects
@@ -51,7 +51,7 @@ try {
5151
}
5252
```
5353

54-
For more detailed examples, please see the [API Documentation](https://apidevtools.com/swagger-parser/docs/)
54+
For more detailed examples, please see the [API Documentation](docs/README.md).
5555

5656
## Installation
5757

@@ -83,7 +83,7 @@ To use Swagger Parser in a browser, you'll need to use a bundling tool such as [
8383

8484
## API Documentation
8585

86-
Full API documentation is available [right here](https://apidevtools.com/swagger-parser/docs/)
86+
Full API documentation is available [right here](docs/README.md).
8787

8888
## Security
8989

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
openapi: 3.1.0
2+
info:
3+
title: Xquik API
4+
version: "1.0"
5+
servers:
6+
- url: https://xquik.com
7+
paths:
8+
/api/v1/x/tweets/search:
9+
get:
10+
operationId: searchTweets
11+
parameters:
12+
- name: q
13+
in: query
14+
required: true
15+
schema:
16+
type: string
17+
responses:
18+
"200":
19+
description: Search results.
20+
content:
21+
application/json:
22+
schema:
23+
$ref: "#/components/schemas/PaginatedTweets"
24+
security:
25+
- apiKey: []
26+
components:
27+
securitySchemes:
28+
apiKey:
29+
type: apiKey
30+
in: header
31+
name: x-api-key
32+
schemas:
33+
PaginatedTweets:
34+
type: object
35+
required:
36+
- tweets
37+
- has_next_page
38+
- next_cursor
39+
properties:
40+
tweets:
41+
type: array
42+
items:
43+
$ref: "#/components/schemas/Tweet"
44+
has_next_page:
45+
type: boolean
46+
next_cursor:
47+
type: string
48+
Tweet:
49+
type: object
50+
required:
51+
- id
52+
- text
53+
- retweetCount
54+
- replyCount
55+
- likeCount
56+
- quoteCount
57+
- viewCount
58+
- bookmarkCount
59+
properties:
60+
id:
61+
type: string
62+
text:
63+
type: string
64+
retweetCount:
65+
type: integer
66+
replyCount:
67+
type: integer
68+
likeCount:
69+
type: integer
70+
quoteCount:
71+
type: integer
72+
viewCount:
73+
type: integer
74+
bookmarkCount:
75+
type: integer
76+
author:
77+
$ref: "#/components/schemas/UserProfile"
78+
UserProfile:
79+
type: object
80+
required:
81+
- id
82+
- username
83+
- name
84+
properties:
85+
id:
86+
type: string
87+
username:
88+
type: string
89+
name:
90+
type: string

test/specs/xquik/xquik.spec.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"use strict";
2+
3+
const { expect } = require("chai");
4+
const SwaggerParser = require("../../..");
5+
const path = require("../../utils/path");
6+
7+
describe("Xquik OpenAPI 3.1 fixture", () => {
8+
it("validates the search endpoint and API key security scheme", async () => {
9+
const api = await SwaggerParser.validate(path.rel("specs/xquik/xquik-openapi.yaml"));
10+
const operation = api.paths["/api/v1/x/tweets/search"].get;
11+
const responseSchema = operation.responses["200"].content["application/json"].schema;
12+
const scheme = api.components.securitySchemes.apiKey;
13+
14+
expect(api.openapi).to.equal("3.1.0");
15+
expect(api.info.title).to.equal("Xquik API");
16+
expect(operation.operationId).to.equal("searchTweets");
17+
expect(operation.responses["200"].description).to.equal("Search results.");
18+
expect(responseSchema.required).to.deep.equal(["tweets", "has_next_page", "next_cursor"]);
19+
expect(responseSchema.properties.tweets.items.required).to.include.members([
20+
"id",
21+
"text",
22+
"likeCount",
23+
"viewCount",
24+
]);
25+
expect(responseSchema.properties.tweets.items.properties.author.required).to.deep.equal(["id", "username", "name"]);
26+
expect(scheme.type).to.equal("apiKey");
27+
expect(scheme.in).to.equal("header");
28+
expect(scheme.name).to.equal("x-api-key");
29+
});
30+
});

0 commit comments

Comments
 (0)