oas 17.4.3 → 17.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@types/index.d.ts +9 -22
- package/@types/lib/find-schema-definition.d.ts +2 -1
- package/@types/lib/get-auth.d.ts +1 -4
- package/@types/lib/get-mediatype-examples.d.ts +1 -2
- package/@types/lib/get-schema.d.ts +3 -4
- package/@types/lib/get-user-variable.d.ts +0 -1
- package/@types/lib/openapi-to-json-schema.d.ts +18 -21
- package/@types/operation/get-callback-examples.d.ts +1 -2
- package/@types/operation/get-parameters-as-json-schema.d.ts +11 -7
- package/@types/operation/get-requestbody-examples.d.ts +2 -1
- package/@types/operation/get-response-as-json-schema.d.ts +0 -1
- package/@types/operation/get-response-examples.d.ts +2 -1
- package/@types/operation.d.ts +26 -34
- package/@types/rmoas.types.d.ts +3 -2
- package/CHANGELOG.md +8 -0
- package/dist/index.js +9 -41
- package/dist/lib/find-schema-definition.js +2 -1
- package/dist/lib/get-auth.js +1 -5
- package/dist/lib/get-mediatype-examples.js +1 -2
- package/dist/lib/get-schema.js +3 -4
- package/dist/lib/get-user-variable.js +0 -1
- package/dist/lib/matches-mimetype.js +0 -5
- package/dist/lib/openapi-to-json-schema.js +89 -58
- package/dist/operation/get-callback-examples.js +1 -2
- package/dist/operation/get-parameters-as-json-schema.js +21 -50
- package/dist/operation/get-requestbody-examples.js +2 -1
- package/dist/operation/get-response-as-json-schema.js +0 -6
- package/dist/operation/get-response-examples.js +2 -1
- package/dist/operation.js +34 -32
- package/dist/samples/utils.js +0 -1
- package/package.json +4 -4
- package/src/index.ts +9 -41
- package/src/lib/find-schema-definition.ts +2 -1
- package/src/lib/get-auth.ts +1 -4
- package/src/lib/get-mediatype-examples.ts +1 -2
- package/src/lib/get-schema.ts +3 -4
- package/src/lib/get-user-variable.ts +0 -1
- package/src/lib/matches-mimetype.ts +0 -5
- package/src/lib/openapi-to-json-schema.ts +83 -59
- package/src/operation/get-callback-examples.ts +1 -2
- package/src/operation/get-parameters-as-json-schema.ts +26 -52
- package/src/operation/get-requestbody-examples.ts +2 -1
- package/src/operation/get-response-as-json-schema.ts +0 -6
- package/src/operation/get-response-examples.ts +2 -1
- package/src/operation.ts +39 -34
- package/src/rmoas.types.ts +10 -3
- package/src/samples/utils.ts +0 -1
package/@types/index.d.ts
CHANGED
|
@@ -59,15 +59,15 @@ export default class Oas {
|
|
|
59
59
|
*
|
|
60
60
|
* @param oas An OpenAPI definition.
|
|
61
61
|
* @param user The information about a user that we should use when pulling auth tokens from security schemes.
|
|
62
|
-
* @returns An instance of the Oas class.
|
|
63
62
|
*/
|
|
64
63
|
static init(oas: Record<string, unknown> | RMOAS.OASDocument, user?: RMOAS.User): Oas;
|
|
65
64
|
/**
|
|
66
|
-
*
|
|
65
|
+
* Retrieve the OpenAPI version that this API definition is targeted for.
|
|
67
66
|
*/
|
|
68
67
|
getVersion(): string;
|
|
69
68
|
/**
|
|
70
|
-
*
|
|
69
|
+
* Retrieve the current OpenAPI API Definition.
|
|
70
|
+
*
|
|
71
71
|
*/
|
|
72
72
|
getDefinition(): RMOAS.OASDocument;
|
|
73
73
|
url(selected?: number, variables?: Variables): string;
|
|
@@ -86,7 +86,7 @@ export default class Oas {
|
|
|
86
86
|
value: string;
|
|
87
87
|
key: string;
|
|
88
88
|
description: string;
|
|
89
|
-
enum: string[]
|
|
89
|
+
enum: string[];
|
|
90
90
|
})[];
|
|
91
91
|
/**
|
|
92
92
|
* With a fully composed server URL, run through our list of known OAS servers and return back which server URL was
|
|
@@ -100,7 +100,6 @@ export default class Oas {
|
|
|
100
100
|
* Re-supplying this data to `oas.url()` should return the same URL you passed into this method.
|
|
101
101
|
*
|
|
102
102
|
* @param baseUrl A given URL to extract server variables out of.
|
|
103
|
-
* @returns The extracted server variables and the configured server that they were matched to.
|
|
104
103
|
*/
|
|
105
104
|
splitVariables(baseUrl: string): false | {
|
|
106
105
|
selected: number;
|
|
@@ -123,7 +122,6 @@ export default class Oas {
|
|
|
123
122
|
*
|
|
124
123
|
* @param url A URL to swap variables into.
|
|
125
124
|
* @param variables An object containing variables to swap into the URL.
|
|
126
|
-
* @returns The new URL with the variables.
|
|
127
125
|
*/
|
|
128
126
|
replaceUrl(url: string, variables?: Variables): string;
|
|
129
127
|
/**
|
|
@@ -133,7 +131,6 @@ export default class Oas {
|
|
|
133
131
|
* @param method HTTP Method to retrieve on the path.
|
|
134
132
|
* @param opts Options
|
|
135
133
|
* @param opts.isWebhook If you prefer to first look for a webhook with this path and method.
|
|
136
|
-
* @returns The found Operation or Webhook.
|
|
137
134
|
*/
|
|
138
135
|
operation(path: string, method: RMOAS.HttpMethods, opts?: {
|
|
139
136
|
isWebhook?: boolean;
|
|
@@ -146,15 +143,13 @@ export default class Oas {
|
|
|
146
143
|
*
|
|
147
144
|
* @param url A full URL to look up.
|
|
148
145
|
* @param method The cooresponding HTTP method to look up.
|
|
149
|
-
* @returns An object containing matches that were discovered in the API definition.
|
|
150
146
|
*/
|
|
151
147
|
findOperation(url: string, method: RMOAS.HttpMethods): PathMatch;
|
|
152
148
|
/**
|
|
153
|
-
* Discover an operation in an OAS from a fully-formed URL without an HTTP method. Will return an object containing a
|
|
154
|
-
* object and another one for `operation`.
|
|
149
|
+
* Discover an operation in an OAS from a fully-formed URL without an HTTP method. Will return an object containing a
|
|
150
|
+
* `url` object and another one for `operation`.
|
|
155
151
|
*
|
|
156
152
|
* @param url A full URL to look up.
|
|
157
|
-
* @returns An object containing matches that were discovered in the API definition.
|
|
158
153
|
*/
|
|
159
154
|
findOperationWithoutMethod(url: string): PathMatch;
|
|
160
155
|
/**
|
|
@@ -163,16 +158,14 @@ export default class Oas {
|
|
|
163
158
|
*
|
|
164
159
|
* @param url A full URL to look up.
|
|
165
160
|
* @param method The cooresponding HTTP method to look up.
|
|
166
|
-
* @returns The found operation or webhook.
|
|
167
161
|
*/
|
|
168
162
|
getOperation(url: string, method: RMOAS.HttpMethods): Operation;
|
|
169
163
|
/**
|
|
170
|
-
* With an object of user information, retrieve
|
|
164
|
+
* With an object of user information, retrieve the appropriate API auth keys from the current OAS definition.
|
|
171
165
|
*
|
|
172
166
|
* @see {@link https://docs.readme.com/docs/passing-data-to-jwt}
|
|
173
167
|
* @param user User
|
|
174
168
|
* @param selectedApp The user app to retrieve an auth key for.
|
|
175
|
-
* @returns Found auth keys for the found security schemes.
|
|
176
169
|
*/
|
|
177
170
|
getAuth(user: RMOAS.User, selectedApp?: string | number): {
|
|
178
171
|
[x: string]: unknown;
|
|
@@ -183,7 +176,6 @@ export default class Oas {
|
|
|
183
176
|
*
|
|
184
177
|
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#oasObject}
|
|
185
178
|
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#openapi-object}
|
|
186
|
-
* @returns The Paths that exist on this API definition.
|
|
187
179
|
*/
|
|
188
180
|
getPaths(): Record<string, Record<RMOAS.HttpMethods, Operation | Webhook>>;
|
|
189
181
|
/**
|
|
@@ -192,7 +184,6 @@ export default class Oas {
|
|
|
192
184
|
*
|
|
193
185
|
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#oasObject}
|
|
194
186
|
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#openapi-object}
|
|
195
|
-
* @returns The Webhooks that exist on this API definition.
|
|
196
187
|
*/
|
|
197
188
|
getWebhooks(): Record<string, Record<RMOAS.HttpMethods, Webhook>>;
|
|
198
189
|
/**
|
|
@@ -202,9 +193,8 @@ export default class Oas {
|
|
|
202
193
|
*
|
|
203
194
|
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#oasObject}
|
|
204
195
|
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#openapi-object}
|
|
205
|
-
* @param
|
|
206
|
-
*
|
|
207
|
-
* @returns An array of tags.
|
|
196
|
+
* @param setIfMissing If a tag is not present on an operation that operations path will be added into the list of
|
|
197
|
+
* tags returned.
|
|
208
198
|
*/
|
|
209
199
|
getTags(setIfMissing?: boolean): unknown[];
|
|
210
200
|
/**
|
|
@@ -213,7 +203,6 @@ export default class Oas {
|
|
|
213
203
|
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specificationExtensions}
|
|
214
204
|
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#specificationExtensions}
|
|
215
205
|
* @param extension Specification extension to lookup.
|
|
216
|
-
* @returns The extension exists.
|
|
217
206
|
*/
|
|
218
207
|
hasExtension(extension: string): boolean;
|
|
219
208
|
/**
|
|
@@ -222,14 +211,12 @@ export default class Oas {
|
|
|
222
211
|
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specificationExtensions}
|
|
223
212
|
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#specificationExtensions}
|
|
224
213
|
* @param extension Specification extension to lookup.
|
|
225
|
-
* @returns The extension contents if it was found.
|
|
226
214
|
*/
|
|
227
215
|
getExtension(extension: string): unknown;
|
|
228
216
|
/**
|
|
229
217
|
* Dereference the current OAS definition so it can be parsed free of worries of `$ref` schemas and circular
|
|
230
218
|
* structures.
|
|
231
219
|
*
|
|
232
|
-
* @returns A post-dereference Promise.
|
|
233
220
|
*/
|
|
234
221
|
dereference(): Promise<unknown>;
|
|
235
222
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* Lookup a reference pointer within an OpenAPI definition and return the schema that it resolves to.
|
|
3
|
+
*
|
|
2
4
|
* @param $ref Reference to look up a schema for.
|
|
3
5
|
* @param definitions OpenAPI definition to look for the `$ref` pointer in.
|
|
4
|
-
* @returns Found schema.
|
|
5
6
|
*/
|
|
6
7
|
export default function findSchemaDefinition($ref: string, definitions?: {}): any;
|
package/@types/lib/get-auth.d.ts
CHANGED
|
@@ -15,17 +15,14 @@ declare type authKey = null | unknown | {
|
|
|
15
15
|
* @param user User
|
|
16
16
|
* @param scheme Security scheme to get auth keys for.
|
|
17
17
|
* @param selectedApp The user app to retrieve an auth key for.
|
|
18
|
-
* @returns The found auth key for this security scheme.
|
|
19
18
|
*/
|
|
20
|
-
export declare function getByScheme(user: RMOAS.User, scheme?: RMOAS.KeyedSecuritySchemeObject,
|
|
21
|
-
selectedApp?: string | number): authKey;
|
|
19
|
+
export declare function getByScheme(user: RMOAS.User, scheme?: RMOAS.KeyedSecuritySchemeObject, selectedApp?: string | number): authKey;
|
|
22
20
|
/**
|
|
23
21
|
* Retrieve auth keys for an API definition from a given user for a specific "app" that they have configured.
|
|
24
22
|
*
|
|
25
23
|
* @param api API definition
|
|
26
24
|
* @param user User
|
|
27
25
|
* @param selectedApp The user app to retrieve an auth key for.
|
|
28
|
-
* @returns Found auth keys for the found security schemes.
|
|
29
26
|
*/
|
|
30
27
|
export default function getAuth(api: OpenAPIV3.Document | OpenAPIV3_1.Document, user: RMOAS.User, selectedApp?: string | number): {
|
|
31
28
|
[x: string]: unknown;
|
|
@@ -6,7 +6,7 @@ export declare type MediaTypeExample = {
|
|
|
6
6
|
value: unknown;
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
9
|
-
* Extracts
|
|
9
|
+
* Extracts a collection of examples from an OpenAPI Media Type Object. The example will either come from the `example`
|
|
10
10
|
* property, the first item in an `examples` array, or if none of those are present it will generate an example based
|
|
11
11
|
* off its schema.
|
|
12
12
|
*
|
|
@@ -17,6 +17,5 @@ export declare type MediaTypeExample = {
|
|
|
17
17
|
* @param opts Options
|
|
18
18
|
* @param opts.includeReadOnly If you wish to include data that's flagged as `readOnly`.
|
|
19
19
|
* @param opts.includeWriteOnly If you wish to include data that's flatted as `writeOnly`.
|
|
20
|
-
* @returns Array of media type examples.
|
|
21
20
|
*/
|
|
22
21
|
export default function getMediaTypeExamples(mediaType: string, mediaTypeObject: RMOAS.MediaTypeObject, opts?: {}): MediaTypeExample[];
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import type * as RMOAS from '../rmoas.types';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* no Request Body Object.
|
|
3
|
+
* Retrieves the schema of the first media type defined in the `content` of the path operation or returns the reference
|
|
4
|
+
* if there's no Request Body Object.
|
|
5
5
|
*
|
|
6
|
-
* If the
|
|
6
|
+
* If the reference pointer looks like a `requestBodies` reference, then we also do a lookup for the actual schema.
|
|
7
7
|
*
|
|
8
8
|
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#fixed-fields-8}
|
|
9
9
|
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#fixed-fields-8}
|
|
10
10
|
* @param operation Operation to look for a primary requestBody schema in.
|
|
11
11
|
* @param api The API definition that this operation exists within.
|
|
12
|
-
* @returns The found requestBody schema.
|
|
13
12
|
*/
|
|
14
13
|
export default function getSchema(operation: RMOAS.OperationObject, api?: RMOAS.OASDocument | {
|
|
15
14
|
[schemaType: string]: {
|
|
@@ -6,6 +6,5 @@ import type * as RMOAS from '../rmoas.types';
|
|
|
6
6
|
* @param user The user to get a user variable for.
|
|
7
7
|
* @param property The name of the variable to retrieve.
|
|
8
8
|
* @param selectedApp The user app to retrieve an auth key for.
|
|
9
|
-
* @returns Found user variable.
|
|
10
9
|
*/
|
|
11
10
|
export default function getUserVariable(user: RMOAS.User, property: string, selectedApp?: string | number): unknown;
|
|
@@ -9,9 +9,6 @@ export declare type toJsonSchemaOptions = {
|
|
|
9
9
|
prevSchemas?: PrevSchemasType;
|
|
10
10
|
refLogger?: (ref: string) => void;
|
|
11
11
|
};
|
|
12
|
-
/**
|
|
13
|
-
* @param val
|
|
14
|
-
*/
|
|
15
12
|
export declare function isPrimitive(val: unknown): boolean;
|
|
16
13
|
/**
|
|
17
14
|
* Given an OpenAPI-flavored JSON Schema, make an effort to modify it so it's shaped more towards stock JSON Schema.
|
|
@@ -24,31 +21,31 @@ export declare function isPrimitive(val: unknown): boolean;
|
|
|
24
21
|
* legacy schemas in ReadMe that were ingested before we had proper validation in place, and as a result have some
|
|
25
22
|
* API definitions that will not pass validation right now. In addition to reshaping OAS-JSON Schema into JSON Schema
|
|
26
23
|
* this library will also fix these improper schemas: things like `type: object` having `items` instead of
|
|
27
|
-
* `properties`, `type: array` missing `items
|
|
28
|
-
* 3.
|
|
24
|
+
* `properties`, or `type: array` missing `items`.
|
|
25
|
+
* 3. To ease the burden of polymorphic handling on our form rendering engine we make an attempt to merge `allOf`
|
|
26
|
+
* schemas here.
|
|
27
|
+
* 4. Additionally due to OpenAPI 3.0.x not supporting JSON Schema, in order to support the `example` keyword that OAS
|
|
29
28
|
* supports, we need to do some work in here to remap it into `examples`. However, since all we care about in respect
|
|
30
29
|
* to examples for usage within `@readme/oas-form`, we're only retaining primitives. This *slightly* deviates from
|
|
31
30
|
* JSON Schema in that JSON Schema allows for any schema to be an example, but since `@readme/oas-form` can only
|
|
32
31
|
* actually **render** primitives, that's what we're retaining.
|
|
33
|
-
*
|
|
32
|
+
* 5. Though OpenAPI 3.1 does support full JSON Schema, this library should be able to handle it without any problems.
|
|
34
33
|
*
|
|
35
34
|
* And why use this over `@openapi-contrib/openapi-schema-to-json-schema`? Fortunately and unfortunately we've got a lot
|
|
36
35
|
* of API definitions in our database that aren't currently valid so we need to have a lot of bespoke handling for odd
|
|
37
|
-
* quirks, typos, and missing declarations that
|
|
36
|
+
* quirks, typos, and missing declarations that might be present.
|
|
38
37
|
*
|
|
39
|
-
* @
|
|
40
|
-
* @see {@link https://
|
|
41
|
-
* @
|
|
42
|
-
* @
|
|
43
|
-
* @param
|
|
44
|
-
* @param
|
|
45
|
-
* @param
|
|
46
|
-
* @param
|
|
47
|
-
* @param
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
* @param data
|
|
51
|
-
* @param opts
|
|
38
|
+
* @todo add support for `schema: false` and `not` cases.
|
|
39
|
+
* @see {@link https://json-schema.org/draft/2019-09/json-schema-validation.html}
|
|
40
|
+
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schemaObject}
|
|
41
|
+
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schemaObject}
|
|
42
|
+
* @param data OpenAPI Schema Object to convert to pure JSON Schema.
|
|
43
|
+
* @param opts Options
|
|
44
|
+
* @param opts.currentLocation Current location within the schema -- this is a JSON pointer.
|
|
45
|
+
* @param opts.globalDefaults Object containing a global set of defaults that we should apply to schemas that match it.
|
|
46
|
+
* @param opts.isPolymorphicAllOfChild Is this schema the child of a polymorphic `allOf` schema?
|
|
47
|
+
* @param opts.prevSchemas Array of parent schemas to utilize when attempting to path together examples.
|
|
48
|
+
* @param opts.refLogger A function that's called anytime a (circular) `$ref` is found.
|
|
52
49
|
*/
|
|
53
|
-
export default function toJSONSchema(data: RMOAS.SchemaObject |
|
|
50
|
+
export default function toJSONSchema(data: RMOAS.SchemaObject | boolean, opts?: toJsonSchemaOptions): RMOAS.SchemaObject;
|
|
54
51
|
export {};
|
|
@@ -6,10 +6,9 @@ export declare type CallbackExamples = Array<{
|
|
|
6
6
|
example: unknown;
|
|
7
7
|
}>;
|
|
8
8
|
/**
|
|
9
|
-
* With an OpenAPI Operation Object return back
|
|
9
|
+
* With an OpenAPI Operation Object return back a collection of examples for any callbacks that may be present.
|
|
10
10
|
*
|
|
11
11
|
* @param operation Operation to retrieve callback examples from.
|
|
12
|
-
* @returns An an array of callback examples.
|
|
13
12
|
*/
|
|
14
13
|
export default function getCallbackExamples(operation: RMOAS.OperationObject): {
|
|
15
14
|
identifier: string;
|
|
@@ -7,15 +7,19 @@ export declare type SchemaWrapper = {
|
|
|
7
7
|
schema: SchemaObject;
|
|
8
8
|
deprecatedProps?: SchemaWrapper;
|
|
9
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* The order of this object determines how they will be sorted in the compiled JSON Schema representation.
|
|
12
|
+
*
|
|
13
|
+
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#parameterObject}
|
|
14
|
+
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameterObject}
|
|
15
|
+
*/
|
|
10
16
|
export declare const types: {
|
|
11
17
|
[key: keyof RMOAS.OASDocument]: string;
|
|
12
18
|
};
|
|
13
|
-
declare const _default: (path: string, operation: OperationObject, api: OASDocument, globalDefaults?: {}) => SchemaWrapper[];
|
|
14
19
|
/**
|
|
15
|
-
* @param
|
|
16
|
-
* @param
|
|
17
|
-
* @param
|
|
18
|
-
* @param
|
|
19
|
-
* @returns {Array<object>}
|
|
20
|
+
* @param path
|
|
21
|
+
* @param operation
|
|
22
|
+
* @param api
|
|
23
|
+
* @param globalDefaults
|
|
20
24
|
*/
|
|
21
|
-
export default
|
|
25
|
+
export default function getParametersAsJsonSchema(path: string, operation: OperationObject, api: OASDocument, globalDefaults?: {}): SchemaWrapper[];
|
|
@@ -4,7 +4,8 @@ export declare type RequestBodyExamples = Array<{
|
|
|
4
4
|
examples: any;
|
|
5
5
|
}>;
|
|
6
6
|
/**
|
|
7
|
+
* Retrieve a collection of request body examples, keyed by their media type.
|
|
8
|
+
*
|
|
7
9
|
* @param operation Operation to retrieve requestBody examples for.
|
|
8
|
-
* @returns An object of response examples keyed by their media type.
|
|
9
10
|
*/
|
|
10
11
|
export default function getRequestBodyExamples(operation: RMOAS.OperationObject): RequestBodyExamples;
|
|
@@ -8,7 +8,6 @@ import type Operation from 'operation';
|
|
|
8
8
|
* @param operation Operation to construct a response JSON Schema for.
|
|
9
9
|
* @param api The OpenAPI definition that this operation originates.
|
|
10
10
|
* @param statusCode The response status code to generate a schema for.
|
|
11
|
-
* @returns Array<{schema: Object, type: string, label: string}>
|
|
12
11
|
*/
|
|
13
12
|
export default function getResponseAsJsonSchema(operation: Operation, api: OASDocument, statusCode: string | number): {
|
|
14
13
|
type: string | Array<string>;
|
|
@@ -4,7 +4,8 @@ export declare type ResponseExamples = Array<{
|
|
|
4
4
|
mediaTypes: Record<string, RMOAS.MediaTypeObject>;
|
|
5
5
|
}>;
|
|
6
6
|
/**
|
|
7
|
+
* Retrieve a collection of response examples keyed, by their media type.
|
|
8
|
+
*
|
|
7
9
|
* @param operation Operation to retrieve response examples for.
|
|
8
|
-
* @returns An object of response examples keyed by their media type.
|
|
9
10
|
*/
|
|
10
11
|
export default function getResponseExamples(operation: RMOAS.OperationObject): ResponseExamples;
|
package/@types/operation.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';
|
|
1
2
|
import type { RequestBodyExamples } from './operation/get-requestbody-examples';
|
|
2
3
|
import type { CallbackExamples } from './operation/get-callback-examples';
|
|
3
4
|
import type { ResponseExamples } from './operation/get-response-examples';
|
|
@@ -55,74 +56,69 @@ export default class Operation {
|
|
|
55
56
|
* Returns an array of all security requirements associated wtih this operation. If none are defined at the operation
|
|
56
57
|
* level, the securities for the entire API definition are returned (with an empty array as a final fallback).
|
|
57
58
|
*
|
|
58
|
-
* @returns {Array}
|
|
59
59
|
*/
|
|
60
60
|
getSecurity(): Array<RMOAS.SecurityRequirementObject>;
|
|
61
61
|
/**
|
|
62
|
+
* Retrieve a collection of grouped security schemes. The inner array determines and-grouped security schemes, the
|
|
63
|
+
* outer array determines or-groups.
|
|
64
|
+
*
|
|
62
65
|
* @see {@link https://swagger.io/docs/specification/authentication/#multiple}
|
|
63
66
|
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#security-requirement-object}
|
|
64
|
-
* @
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* security schemes, the outer array determines or-groups.
|
|
67
|
+
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#securityRequirementObject}
|
|
68
|
+
* @param filterInvalid Optional flag that, when set to `true`, filters out invalid/nonexistent security schemes,
|
|
69
|
+
* rather than returning `false`.
|
|
68
70
|
*/
|
|
69
71
|
getSecurityWithTypes(filterInvalid?: boolean): Array<false | Array<false | {
|
|
70
72
|
security: RMOAS.KeyedSecuritySchemeObject;
|
|
71
73
|
type: SecurityType;
|
|
72
74
|
}>>;
|
|
73
75
|
/**
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
+
* Retrieve an object where the keys are unique scheme types, and the values are arrays containing each security
|
|
77
|
+
* scheme of that type.
|
|
78
|
+
*
|
|
76
79
|
*/
|
|
77
80
|
prepareSecurity(): Record<SecurityType, Array<RMOAS.KeyedSecuritySchemeObject>>;
|
|
78
81
|
getHeaders(): Operation['headers'];
|
|
79
82
|
/**
|
|
80
83
|
* Determine if the operation has an operation present in its schema.
|
|
81
84
|
*
|
|
82
|
-
* @returns {boolean}
|
|
83
85
|
*/
|
|
84
86
|
hasOperationId(): boolean;
|
|
85
87
|
/**
|
|
86
88
|
* Get an `operationId` for this operation. If one is not present (it's not required by the spec!) a hash of the path
|
|
87
89
|
* and method will be returned instead.
|
|
88
90
|
*
|
|
89
|
-
* @returns {string}
|
|
90
91
|
*/
|
|
91
92
|
getOperationId(): string;
|
|
92
93
|
/**
|
|
93
94
|
* Return an array of all tags, and their metadata, that exist on this operation.
|
|
94
95
|
*
|
|
95
|
-
* @returns {Array}
|
|
96
96
|
*/
|
|
97
97
|
getTags(): Array<RMOAS.TagObject>;
|
|
98
98
|
/**
|
|
99
99
|
* Return is the operation is flagged as `deprecated` or not.
|
|
100
100
|
*
|
|
101
|
-
* @returns {boolean}
|
|
102
101
|
*/
|
|
103
102
|
isDeprecated(): boolean;
|
|
104
103
|
/**
|
|
105
104
|
* Return the parameters (non-request body) on the operation.
|
|
106
105
|
*
|
|
107
106
|
* @todo This should also pull in common params.
|
|
108
|
-
* @returns {Array}
|
|
109
107
|
*/
|
|
110
108
|
getParameters(): Array<RMOAS.ParameterObject>;
|
|
111
109
|
/**
|
|
112
|
-
* Convert the operation into an array of JSON Schema for each available type of parameter available on the
|
|
113
|
-
*
|
|
110
|
+
* Convert the operation into an array of JSON Schema schemas for each available type of parameter available on the
|
|
111
|
+
* operation.
|
|
114
112
|
*
|
|
115
|
-
* @param
|
|
116
|
-
* @returns {Array}
|
|
113
|
+
* @param globalDefaults Contains an object of user defined schema defaults.
|
|
117
114
|
*/
|
|
118
|
-
getParametersAsJsonSchema(globalDefaults?: unknown): import("./operation/get-parameters-as-json-schema").SchemaWrapper[];
|
|
115
|
+
getParametersAsJsonSchema(globalDefaults?: Record<string, unknown>): import("./operation/get-parameters-as-json-schema").SchemaWrapper[];
|
|
119
116
|
/**
|
|
120
117
|
* Get a single response for this status code, formatted as JSON schema.
|
|
121
118
|
*
|
|
122
|
-
* @param
|
|
123
|
-
* @returns {Array}
|
|
119
|
+
* @param statusCode
|
|
124
120
|
*/
|
|
125
|
-
getResponseAsJsonSchema(statusCode: string): {
|
|
121
|
+
getResponseAsJsonSchema(statusCode: string | number): {
|
|
126
122
|
type: string | string[];
|
|
127
123
|
schema: RMOAS.SchemaObject;
|
|
128
124
|
label: string;
|
|
@@ -131,38 +127,40 @@ export default class Operation {
|
|
|
131
127
|
/**
|
|
132
128
|
* Get an array of all valid response status codes for this operation.
|
|
133
129
|
*
|
|
134
|
-
* @returns {Array}
|
|
135
130
|
*/
|
|
136
131
|
getResponseStatusCodes(): Array<string>;
|
|
137
132
|
/**
|
|
138
|
-
* Determine if the operation has
|
|
133
|
+
* Determine if the operation has any request bodies.
|
|
139
134
|
*
|
|
140
|
-
* @returns {boolean}
|
|
141
135
|
*/
|
|
142
136
|
hasRequestBody(): boolean;
|
|
137
|
+
/**
|
|
138
|
+
* Retrieve a specific request body content schema off this operation.
|
|
139
|
+
*
|
|
140
|
+
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#mediaTypeObject}
|
|
141
|
+
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#mediaTypeObject}
|
|
142
|
+
* @param mediaType Specific request body media type to retrieve if present.
|
|
143
|
+
*/
|
|
144
|
+
getRequestBody(mediaType: string): false | OpenAPIV3.MediaTypeObject | OpenAPIV3_1.MediaTypeObject;
|
|
143
145
|
/**
|
|
144
146
|
* Retrieve an array of request body examples that this operation has.
|
|
145
147
|
*
|
|
146
|
-
* @returns {Array}
|
|
147
148
|
*/
|
|
148
149
|
getRequestBodyExamples(): RequestBodyExamples;
|
|
149
150
|
/**
|
|
150
151
|
* Return a specific response out of the operation by a given HTTP status code.
|
|
151
152
|
*
|
|
152
|
-
* @param
|
|
153
|
-
* @returns {(boolean|object)}
|
|
153
|
+
* @param statusCode
|
|
154
154
|
*/
|
|
155
155
|
getResponseByStatusCode(statusCode: string | number): boolean | RMOAS.ResponseObject;
|
|
156
156
|
/**
|
|
157
157
|
* Retrieve an array of response examples that this operation has.
|
|
158
158
|
*
|
|
159
|
-
* @returns {Array}
|
|
160
159
|
*/
|
|
161
160
|
getResponseExamples(): ResponseExamples;
|
|
162
161
|
/**
|
|
163
162
|
* Determine if the operation has callbacks.
|
|
164
163
|
*
|
|
165
|
-
* @returns {boolean}
|
|
166
164
|
*/
|
|
167
165
|
hasCallbacks(): boolean;
|
|
168
166
|
/**
|
|
@@ -173,19 +171,16 @@ export default class Operation {
|
|
|
173
171
|
* @param identifier Callback identifier to look for.
|
|
174
172
|
* @param expression Callback expression to look for.
|
|
175
173
|
* @param method HTTP Method on the callback to look for.
|
|
176
|
-
* @returns {(false|Callback)}
|
|
177
174
|
*/
|
|
178
175
|
getCallback(identifier: string, expression: string, method: RMOAS.HttpMethods): false | Callback;
|
|
179
176
|
/**
|
|
180
177
|
* Retrieve an array of operations created from each callback.
|
|
181
178
|
*
|
|
182
|
-
* @returns {Array}
|
|
183
179
|
*/
|
|
184
180
|
getCallbacks(): false | Array<false | Callback>;
|
|
185
181
|
/**
|
|
186
182
|
* Retrieve an array of callback examples that this operation has.
|
|
187
183
|
*
|
|
188
|
-
* @returns {Array}
|
|
189
184
|
*/
|
|
190
185
|
getCallbackExamples(): CallbackExamples;
|
|
191
186
|
/**
|
|
@@ -194,7 +189,6 @@ export default class Operation {
|
|
|
194
189
|
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specificationExtensions}
|
|
195
190
|
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#specificationExtensions}
|
|
196
191
|
* @param extension Specification extension to lookup.
|
|
197
|
-
* @returns The extension exists.
|
|
198
192
|
*/
|
|
199
193
|
hasExtension(extension: string): boolean;
|
|
200
194
|
/**
|
|
@@ -203,7 +197,6 @@ export default class Operation {
|
|
|
203
197
|
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specificationExtensions}
|
|
204
198
|
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#specificationExtensions}
|
|
205
199
|
* @param extension Specification extension to lookup.
|
|
206
|
-
* @returns The extension contents if it was found.
|
|
207
200
|
*/
|
|
208
201
|
getExtension(extension: string): unknown;
|
|
209
202
|
}
|
|
@@ -222,7 +215,6 @@ export declare class Callback extends Operation {
|
|
|
222
215
|
*
|
|
223
216
|
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#callback-object}
|
|
224
217
|
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#callbackObject}
|
|
225
|
-
* @returns {string}
|
|
226
218
|
*/
|
|
227
219
|
getIdentifier(): string;
|
|
228
220
|
getSummary(): string;
|
package/@types/rmoas.types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';
|
|
2
2
|
import type { JSONSchema4, JSONSchema6, JSONSchema7 } from 'json-schema';
|
|
3
|
+
export declare type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;
|
|
3
4
|
/**
|
|
4
5
|
* @param check Data to determine if it contains a ReferenceObject (`$ref` pointer`).
|
|
5
6
|
* @returns If the supplied data has a `$ref` pointer.
|
|
@@ -106,17 +107,17 @@ export declare type HeaderObject = OpenAPIV3.HeaderObject | OpenAPIV3_1.HeaderOb
|
|
|
106
107
|
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schemaObject}
|
|
107
108
|
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schemaObject}
|
|
108
109
|
*/
|
|
109
|
-
export declare type SchemaObject = (OpenAPIV3.SchemaObject | OpenAPIV3_1.SchemaObject |
|
|
110
|
+
export declare type SchemaObject = (OpenAPIV3.SchemaObject | OpenAPIV3_1.SchemaObject | JSONSchema) & {
|
|
110
111
|
deprecated?: boolean;
|
|
111
112
|
readOnly?: boolean;
|
|
112
113
|
writeOnly?: boolean;
|
|
113
|
-
'x-readme-ref-name'?: string;
|
|
114
114
|
example?: unknown;
|
|
115
115
|
examples?: Array<unknown>;
|
|
116
116
|
nullable?: boolean;
|
|
117
117
|
xml?: unknown;
|
|
118
118
|
externalDocs?: unknown;
|
|
119
119
|
components?: OpenAPIV3_1.ComponentsObject;
|
|
120
|
+
'x-readme-ref-name'?: string;
|
|
120
121
|
};
|
|
121
122
|
/**
|
|
122
123
|
* @param check JSON Schema object to determine if it's a non-polymorphic schema.
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## 17.5.0 (2022-01-12)
|
|
2
|
+
|
|
3
|
+
* feat: addition of a getRequestBody accessor (#580) ([88b0b33](https://github.com/readmeio/oas/commit/88b0b33)), closes [#580](https://github.com/readmeio/oas/issues/580)
|
|
4
|
+
* fix: refactoring allOf schemas to be pre-merged when we generate JSON Schema (#579) ([cc16e05](https://github.com/readmeio/oas/commit/cc16e05)), closes [#579](https://github.com/readmeio/oas/issues/579)
|
|
5
|
+
* chore: make our jsdoc eslint rules a bit less obnoxious (#577) ([a6bac91](https://github.com/readmeio/oas/commit/a6bac91)), closes [#577](https://github.com/readmeio/oas/issues/577)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
1
9
|
## <small>17.4.3 (2022-01-05)</small>
|
|
2
10
|
|
|
3
11
|
* fix(operation): support operations without responses (#576) ([67ec319](https://github.com/readmeio/oas/commit/67ec319)), closes [#576](https://github.com/readmeio/oas/issues/576)
|