oas 17.4.2 → 17.7.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.
Files changed (52) hide show
  1. package/@types/index.d.ts +9 -22
  2. package/@types/lib/dedupe-common-parameters.d.ts +9 -0
  3. package/@types/lib/find-schema-definition.d.ts +2 -1
  4. package/@types/lib/get-auth.d.ts +1 -4
  5. package/@types/lib/get-mediatype-examples.d.ts +1 -2
  6. package/@types/lib/get-schema.d.ts +4 -4
  7. package/@types/lib/get-user-variable.d.ts +0 -1
  8. package/@types/lib/openapi-to-json-schema.d.ts +18 -21
  9. package/@types/operation/get-callback-examples.d.ts +1 -2
  10. package/@types/operation/get-parameters-as-json-schema.d.ts +12 -8
  11. package/@types/operation/get-requestbody-examples.d.ts +2 -1
  12. package/@types/operation/get-response-as-json-schema.d.ts +0 -1
  13. package/@types/operation/get-response-examples.d.ts +2 -1
  14. package/@types/operation.d.ts +42 -35
  15. package/@types/rmoas.types.d.ts +12 -2
  16. package/CHANGELOG.md +30 -0
  17. package/dist/index.js +9 -41
  18. package/dist/lib/dedupe-common-parameters.js +43 -0
  19. package/dist/lib/find-schema-definition.js +2 -1
  20. package/dist/lib/get-auth.js +1 -5
  21. package/dist/lib/get-mediatype-examples.js +1 -2
  22. package/dist/lib/get-schema.js +4 -4
  23. package/dist/lib/get-user-variable.js +0 -1
  24. package/dist/lib/matches-mimetype.js +0 -5
  25. package/dist/lib/openapi-to-json-schema.js +96 -69
  26. package/dist/operation/get-callback-examples.js +1 -2
  27. package/dist/operation/get-parameters-as-json-schema.js +48 -95
  28. package/dist/operation/get-requestbody-examples.js +2 -1
  29. package/dist/operation/get-response-as-json-schema.js +0 -6
  30. package/dist/operation/get-response-examples.js +20 -5
  31. package/dist/operation.js +116 -43
  32. package/dist/samples/index.js +18 -13
  33. package/dist/samples/utils.js +0 -1
  34. package/package.json +4 -4
  35. package/src/index.ts +9 -41
  36. package/src/lib/dedupe-common-parameters.ts +25 -0
  37. package/src/lib/find-schema-definition.ts +2 -1
  38. package/src/lib/get-auth.ts +1 -4
  39. package/src/lib/get-mediatype-examples.ts +1 -2
  40. package/src/lib/get-schema.ts +4 -4
  41. package/src/lib/get-user-variable.ts +0 -1
  42. package/src/lib/matches-mimetype.ts +0 -5
  43. package/src/lib/openapi-to-json-schema.ts +90 -71
  44. package/src/operation/get-callback-examples.ts +1 -2
  45. package/src/operation/get-parameters-as-json-schema.ts +51 -102
  46. package/src/operation/get-requestbody-examples.ts +2 -1
  47. package/src/operation/get-response-as-json-schema.ts +0 -6
  48. package/src/operation/get-response-examples.ts +10 -1
  49. package/src/operation.ts +130 -44
  50. package/src/rmoas.types.ts +19 -3
  51. package/src/samples/index.ts +18 -13
  52. 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
- * @returns The OpenAPI version that this API definition is targeted for.
65
+ * Retrieve the OpenAPI version that this API definition is targeted for.
67
66
  */
68
67
  getVersion(): string;
69
68
  /**
70
- * @returns The current OpenAPI API Definition.
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[] | [string, ...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 `url`
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 an appropriate API key from the current OAS definition.
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 {boolean} setIfMissing If a tag is not present on an operation that operations path will be added into the
206
- * list of tags returned.
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
  }
@@ -0,0 +1,9 @@
1
+ import * as RMOAS from '../rmoas.types';
2
+ /**
3
+ * With an array of common parameters filter down them to what isn't already present in a list of non-common
4
+ * parameters.
5
+ *
6
+ * @param parameters
7
+ * @param commonParameters
8
+ */
9
+ export default function dedupeCommonParameters(parameters: RMOAS.ParameterObject[], commonParameters: RMOAS.ParameterObject[]): import("openapi-types").OpenAPIV3.ParameterObject[];
@@ -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;
@@ -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, // eslint-disable-line default-param-last
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 an array of examples from an OpenAPI Media Type Object. The example will either come from the `example`
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,15 @@
1
1
  import type * as RMOAS from '../rmoas.types';
2
2
  /**
3
- * Gets the schema of the first media type defined in the `content` of the path operation or returns the ref if there's
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 ref looks like a `requestBodies` reference, then do a lookup for the actual schema.
6
+ * If the reference pointer looks like a `requestBodies` reference, then we also do a lookup for the actual schema.
7
7
  *
8
+ * @deprecated
8
9
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#fixed-fields-8}
9
10
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#fixed-fields-8}
10
11
  * @param operation Operation to look for a primary requestBody schema in.
11
12
  * @param api The API definition that this operation exists within.
12
- * @returns The found requestBody schema.
13
13
  */
14
14
  export default function getSchema(operation: RMOAS.OperationObject, api?: RMOAS.OASDocument | {
15
15
  [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`, or `type` missing completely on a schema.
28
- * 3. Additionally due to OpenAPI 3.0.x not supporting JSON Schema, in order to support the `example` keyword that OAS
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
- * 4. Though OpenAPI 3.1 does support full JSON Schema, this library should be able to handle it without any problems.
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 they've got.
36
+ * quirks, typos, and missing declarations that might be present.
38
37
  *
39
- * @see {@link https://json-schema.org/draft/2019-09/json-schema-validation.html{}
40
- * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md}
41
- * @param {Object} data
42
- * @param {Object} opts
43
- * @param {string} opts.currentLocation - Current location within the schema -- this is a JSON pointer.
44
- * @param {Object} opts.globalDefaults - Object containing a global set of defaults that we should apply to schemas that match it.
45
- * @param {boolean} opts.isPolymorphicAllOfChild - Is this schema the child of a polymorphic `allOf` schema?
46
- * @param {Object[]} opts.prevSchemas - Array of parent schemas to utilize when attempting to path together examples.
47
- * @param {Function} opts.refLogger - A function that's called anytime a (circular) `$ref` is found.
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 | RMOAS.RequestBodyObject, opts?: toJsonSchemaOptions): 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 an array of examples for any callbacks that may be present.
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;
@@ -1,4 +1,5 @@
1
- import type { OASDocument, OperationObject, SchemaObject } from '../rmoas.types';
1
+ import type { OASDocument, SchemaObject } from '../rmoas.types';
2
+ import type Operation from '../operation';
2
3
  import * as RMOAS from '../rmoas.types';
3
4
  export declare type SchemaWrapper = {
4
5
  $schema?: string;
@@ -7,15 +8,18 @@ export declare type SchemaWrapper = {
7
8
  schema: SchemaObject;
8
9
  deprecatedProps?: SchemaWrapper;
9
10
  };
11
+ /**
12
+ * The order of this object determines how they will be sorted in the compiled JSON Schema representation.
13
+ *
14
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#parameterObject}
15
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameterObject}
16
+ */
10
17
  export declare const types: {
11
18
  [key: keyof RMOAS.OASDocument]: string;
12
19
  };
13
- declare const _default: (path: string, operation: OperationObject, api: OASDocument, globalDefaults?: {}) => SchemaWrapper[];
14
20
  /**
15
- * @param {string} path
16
- * @param {Operation} operation
17
- * @param {OpenAPI.Document} api
18
- * @param {Object} globalDefaults
19
- * @returns {Array<object>}
21
+ * @param operation
22
+ * @param api
23
+ * @param globalDefaults
20
24
  */
21
- export default _default;
25
+ export default function getParametersAsJsonSchema(operation: Operation, 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;
@@ -55,74 +55,73 @@ export default class Operation {
55
55
  * Returns an array of all security requirements associated wtih this operation. If none are defined at the operation
56
56
  * level, the securities for the entire API definition are returned (with an empty array as a final fallback).
57
57
  *
58
- * @returns {Array}
59
58
  */
60
59
  getSecurity(): Array<RMOAS.SecurityRequirementObject>;
61
60
  /**
61
+ * Retrieve a collection of grouped security schemes. The inner array determines and-grouped security schemes, the
62
+ * outer array determines or-groups.
63
+ *
62
64
  * @see {@link https://swagger.io/docs/specification/authentication/#multiple}
63
65
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#security-requirement-object}
64
- * @param {boolean} filterInvalid Optional flag that, when set to `true`, filters out invalid/nonexistent security
65
- * schemes, rather than returning `false`.
66
- * @returns {Array} An array of arrays of objects of grouped security schemes. The inner array determines and-grouped
67
- * security schemes, the outer array determines or-groups.
66
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#securityRequirementObject}
67
+ * @param filterInvalid Optional flag that, when set to `true`, filters out invalid/nonexistent security schemes,
68
+ * rather than returning `false`.
68
69
  */
69
70
  getSecurityWithTypes(filterInvalid?: boolean): Array<false | Array<false | {
70
71
  security: RMOAS.KeyedSecuritySchemeObject;
71
72
  type: SecurityType;
72
73
  }>>;
73
74
  /**
74
- * @returns An object where the keys are unique scheme types, and the values are arrays containing each security
75
- * scheme of that type.
75
+ * Retrieve an object where the keys are unique scheme types, and the values are arrays containing each security
76
+ * scheme of that type.
77
+ *
76
78
  */
77
79
  prepareSecurity(): Record<SecurityType, Array<RMOAS.KeyedSecuritySchemeObject>>;
78
80
  getHeaders(): Operation['headers'];
79
81
  /**
80
82
  * Determine if the operation has an operation present in its schema.
81
83
  *
82
- * @returns {boolean}
83
84
  */
84
85
  hasOperationId(): boolean;
85
86
  /**
86
87
  * Get an `operationId` for this operation. If one is not present (it's not required by the spec!) a hash of the path
87
88
  * and method will be returned instead.
88
89
  *
89
- * @returns {string}
90
90
  */
91
91
  getOperationId(): string;
92
92
  /**
93
93
  * Return an array of all tags, and their metadata, that exist on this operation.
94
94
  *
95
- * @returns {Array}
96
95
  */
97
96
  getTags(): Array<RMOAS.TagObject>;
98
97
  /**
99
98
  * Return is the operation is flagged as `deprecated` or not.
100
99
  *
101
- * @returns {boolean}
102
100
  */
103
101
  isDeprecated(): boolean;
102
+ /**
103
+ * Determine if the operation has any (non-request body) parameters.
104
+ *
105
+ */
106
+ hasParameters(): boolean;
104
107
  /**
105
108
  * Return the parameters (non-request body) on the operation.
106
109
  *
107
- * @todo This should also pull in common params.
108
- * @returns {Array}
109
110
  */
110
111
  getParameters(): Array<RMOAS.ParameterObject>;
111
112
  /**
112
- * Convert the operation into an array of JSON Schema for each available type of parameter available on the operation.
113
- * `globalDefaults` contains an object of user defined parameter defaults used in `constructSchema`.
113
+ * Convert the operation into an array of JSON Schema schemas for each available type of parameter available on the
114
+ * operation.
114
115
  *
115
- * @param {Object} globalDefaults
116
- * @returns {Array}
116
+ * @param globalDefaults Contains an object of user defined schema defaults.
117
117
  */
118
- getParametersAsJsonSchema(globalDefaults?: unknown): import("./operation/get-parameters-as-json-schema").SchemaWrapper[];
118
+ getParametersAsJsonSchema(globalDefaults?: Record<string, unknown>): import("./operation/get-parameters-as-json-schema").SchemaWrapper[];
119
119
  /**
120
120
  * Get a single response for this status code, formatted as JSON schema.
121
121
  *
122
- * @param {string|number} statusCode
123
- * @returns {Array}
122
+ * @param statusCode
124
123
  */
125
- getResponseAsJsonSchema(statusCode: string): {
124
+ getResponseAsJsonSchema(statusCode: string | number): {
126
125
  type: string | string[];
127
126
  schema: RMOAS.SchemaObject;
128
127
  label: string;
@@ -131,38 +130,51 @@ export default class Operation {
131
130
  /**
132
131
  * Get an array of all valid response status codes for this operation.
133
132
  *
134
- * @returns {Array}
135
133
  */
136
134
  getResponseStatusCodes(): Array<string>;
137
135
  /**
138
- * Determine if the operation has a request body.
136
+ * Determine if the operation has any request bodies.
139
137
  *
140
- * @returns {boolean}
141
138
  */
142
139
  hasRequestBody(): boolean;
140
+ /**
141
+ * Retrieve the list of all available media types that the operations request body can accept.
142
+ *
143
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#mediaTypeObject}
144
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#mediaTypeObject}
145
+ */
146
+ getRequestBodyMediaTypes(): string[];
147
+ /**
148
+ * Retrieve a specific request body content schema off this operation.
149
+ *
150
+ * If no media type is supplied this will return either the first available JSON-like request body, or the first
151
+ * available if there are no JSON-like media types present. When this return comes back it's in the form of an array
152
+ * with the first key being the selected media type, followed by the media type object in question.
153
+ *
154
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#mediaTypeObject}
155
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#mediaTypeObject}
156
+ * @param mediaType Specific request body media type to retrieve if present.
157
+ */
158
+ getRequestBody(mediaType?: string): false | RMOAS.MediaTypeObject | [string, RMOAS.MediaTypeObject];
143
159
  /**
144
160
  * Retrieve an array of request body examples that this operation has.
145
161
  *
146
- * @returns {Array}
147
162
  */
148
163
  getRequestBodyExamples(): RequestBodyExamples;
149
164
  /**
150
165
  * Return a specific response out of the operation by a given HTTP status code.
151
166
  *
152
- * @param {(string|number)} statusCode
153
- * @returns {(boolean|object)}
167
+ * @param statusCode
154
168
  */
155
169
  getResponseByStatusCode(statusCode: string | number): boolean | RMOAS.ResponseObject;
156
170
  /**
157
171
  * Retrieve an array of response examples that this operation has.
158
172
  *
159
- * @returns {Array}
160
173
  */
161
174
  getResponseExamples(): ResponseExamples;
162
175
  /**
163
176
  * Determine if the operation has callbacks.
164
177
  *
165
- * @returns {boolean}
166
178
  */
167
179
  hasCallbacks(): boolean;
168
180
  /**
@@ -173,19 +185,16 @@ export default class Operation {
173
185
  * @param identifier Callback identifier to look for.
174
186
  * @param expression Callback expression to look for.
175
187
  * @param method HTTP Method on the callback to look for.
176
- * @returns {(false|Callback)}
177
188
  */
178
189
  getCallback(identifier: string, expression: string, method: RMOAS.HttpMethods): false | Callback;
179
190
  /**
180
191
  * Retrieve an array of operations created from each callback.
181
192
  *
182
- * @returns {Array}
183
193
  */
184
194
  getCallbacks(): false | Array<false | Callback>;
185
195
  /**
186
196
  * Retrieve an array of callback examples that this operation has.
187
197
  *
188
- * @returns {Array}
189
198
  */
190
199
  getCallbackExamples(): CallbackExamples;
191
200
  /**
@@ -194,7 +203,6 @@ export default class Operation {
194
203
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specificationExtensions}
195
204
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#specificationExtensions}
196
205
  * @param extension Specification extension to lookup.
197
- * @returns The extension exists.
198
206
  */
199
207
  hasExtension(extension: string): boolean;
200
208
  /**
@@ -203,7 +211,6 @@ export default class Operation {
203
211
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specificationExtensions}
204
212
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#specificationExtensions}
205
213
  * @param extension Specification extension to lookup.
206
- * @returns The extension contents if it was found.
207
214
  */
208
215
  getExtension(extension: string): unknown;
209
216
  }
@@ -222,11 +229,11 @@ export declare class Callback extends Operation {
222
229
  *
223
230
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#callback-object}
224
231
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#callbackObject}
225
- * @returns {string}
226
232
  */
227
233
  getIdentifier(): string;
228
234
  getSummary(): string;
229
235
  getDescription(): string;
236
+ getParameters(): Array<RMOAS.ParameterObject>;
230
237
  }
231
238
  export declare class Webhook extends Operation {
232
239
  }
@@ -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.
@@ -40,6 +41,15 @@ export declare type ServerVariableObject = OpenAPIV3.ServerVariableObject | Open
40
41
  export declare type ServerVariablesObject = {
41
42
  [variable: string]: ServerVariableObject;
42
43
  };
44
+ export declare type ServerVariable = Record<string, string | number | Array<{
45
+ default?: string | number;
46
+ }> | {
47
+ default?: string | number;
48
+ } | Record<string, never>>;
49
+ export declare type Servers = {
50
+ selected: number;
51
+ variables: ServerVariable;
52
+ };
43
53
  /**
44
54
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#componentsObject}
45
55
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#componentsObject}
@@ -106,17 +116,17 @@ export declare type HeaderObject = OpenAPIV3.HeaderObject | OpenAPIV3_1.HeaderOb
106
116
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schemaObject}
107
117
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schemaObject}
108
118
  */
109
- export declare type SchemaObject = (OpenAPIV3.SchemaObject | OpenAPIV3_1.SchemaObject | (JSONSchema4 | JSONSchema6 | JSONSchema7)) & {
119
+ export declare type SchemaObject = (OpenAPIV3.SchemaObject | OpenAPIV3_1.SchemaObject | JSONSchema) & {
110
120
  deprecated?: boolean;
111
121
  readOnly?: boolean;
112
122
  writeOnly?: boolean;
113
- 'x-readme-ref-name'?: string;
114
123
  example?: unknown;
115
124
  examples?: Array<unknown>;
116
125
  nullable?: boolean;
117
126
  xml?: unknown;
118
127
  externalDocs?: unknown;
119
128
  components?: OpenAPIV3_1.ComponentsObject;
129
+ 'x-readme-ref-name'?: string;
120
130
  };
121
131
  /**
122
132
  * @param check JSON Schema object to determine if it's a non-polymorphic schema.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,33 @@
1
+ ## 17.7.0 (2022-01-27)
2
+
3
+ * fix: show response headers w/o mediaType content (#584) ([a9bccd1](https://github.com/readmeio/oas/commit/a9bccd1)), closes [#584](https://github.com/readmeio/oas/issues/584)
4
+
5
+
6
+
7
+ ## 17.6.0 (2022-01-26)
8
+
9
+ * chore: add server variable typescript types (#586) ([0868626](https://github.com/readmeio/oas/commit/0868626)), closes [#586](https://github.com/readmeio/oas/issues/586)
10
+ * chore(deps): bumping node-fetch ([0f7dbe1](https://github.com/readmeio/oas/commit/0f7dbe1))
11
+ * fix: funky typing with how we extract examples during JSON Schema generation (#585) ([15ece60](https://github.com/readmeio/oas/commit/15ece60)), closes [#585](https://github.com/readmeio/oas/issues/585)
12
+ * refactor: cleaning up the messy `getSchema` library and other improvements (#581) ([f3f0e43](https://github.com/readmeio/oas/commit/f3f0e43)), closes [#581](https://github.com/readmeio/oas/issues/581)
13
+ * refactor: use default for samples over generic type (#582) ([c1b1c66](https://github.com/readmeio/oas/commit/c1b1c66)), closes [#582](https://github.com/readmeio/oas/issues/582)
14
+
15
+
16
+
17
+ ## 17.5.0 (2022-01-12)
18
+
19
+ * feat: addition of a getRequestBody accessor (#580) ([88b0b33](https://github.com/readmeio/oas/commit/88b0b33)), closes [#580](https://github.com/readmeio/oas/issues/580)
20
+ * 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)
21
+ * 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)
22
+
23
+
24
+
25
+ ## <small>17.4.3 (2022-01-05)</small>
26
+
27
+ * fix(operation): support operations without responses (#576) ([67ec319](https://github.com/readmeio/oas/commit/67ec319)), closes [#576](https://github.com/readmeio/oas/issues/576)
28
+
29
+
30
+
1
31
  ## <small>17.4.2 (2022-01-05)</small>
2
32
 
3
33
  * fix: callbacks not having path-level data to retrieve common summaries (#575) ([c7d1144](https://github.com/readmeio/oas/commit/c7d1144)), closes [#575](https://github.com/readmeio/oas/issues/575)