oas 17.2.0 → 17.3.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.
@@ -1,4 +1,18 @@
1
- export = toJSONSchema;
1
+ import * as RMOAS from '../rmoas.types';
2
+ declare type PrevSchemasType = Array<RMOAS.SchemaObject>;
3
+ export declare type toJsonSchemaOptions = {
4
+ currentLocation?: string;
5
+ globalDefaults?: {
6
+ [key: string]: unknown;
7
+ };
8
+ isPolymorphicAllOfChild?: boolean;
9
+ prevSchemas?: PrevSchemasType;
10
+ refLogger?: (ref: string) => void;
11
+ };
12
+ /**
13
+ * @param val
14
+ */
15
+ export declare function isPrimitive(val: unknown): boolean;
2
16
  /**
3
17
  * Given an OpenAPI-flavored JSON Schema, make an effort to modify it so it's shaped more towards stock JSON Schema.
4
18
  *
@@ -26,26 +40,15 @@ export = toJSONSchema;
26
40
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md}
27
41
  * @param {Object} data
28
42
  * @param {Object} opts
29
- * @param {String} opts.currentLocation - Current location within the schema -- this is a JSON pointer.
43
+ * @param {string} opts.currentLocation - Current location within the schema -- this is a JSON pointer.
30
44
  * @param {Object} opts.globalDefaults - Object containing a global set of defaults that we should apply to schemas that match it.
31
- * @param {Boolean} opts.isPolymorphicAllOfChild - Is this schema the child of a polymorphic `allOf` schema?
45
+ * @param {boolean} opts.isPolymorphicAllOfChild - Is this schema the child of a polymorphic `allOf` schema?
32
46
  * @param {Object[]} opts.prevSchemas - Array of parent schemas to utilize when attempting to path together examples.
33
47
  * @param {Function} opts.refLogger - A function that's called anytime a (circular) `$ref` is found.
34
48
  */
35
- declare function toJSONSchema(data: Object, opts?: {
36
- currentLocation: string;
37
- globalDefaults: Object;
38
- isPolymorphicAllOfChild: boolean;
39
- prevSchemas: Object[];
40
- refLogger: Function;
41
- }): {
42
- constructor: Function;
43
- toString(): string;
44
- toLocaleString(): string;
45
- valueOf(): Object;
46
- hasOwnProperty(v: PropertyKey): boolean;
47
- isPrototypeOf(v: Object): boolean;
48
- propertyIsEnumerable(v: PropertyKey): boolean;
49
- } | {
50
- $ref: any;
51
- };
49
+ /**
50
+ * @param data
51
+ * @param opts
52
+ */
53
+ export default function toJSONSchema(data: RMOAS.SchemaObject | RMOAS.RequestBodyObject, opts?: toJsonSchemaOptions): RMOAS.SchemaObject;
54
+ export {};
@@ -1,10 +1,10 @@
1
1
  import type * as RMOAS from '../rmoas.types';
2
- export declare type CallbackExamples = {
2
+ export declare type CallbackExamples = Array<{
3
3
  identifier: string;
4
4
  expression: string;
5
5
  method: string;
6
6
  example: unknown;
7
- }[];
7
+ }>;
8
8
  /**
9
9
  * With an OpenAPI Operation Object return back an array of examples for any callbacks that may be present.
10
10
  *
@@ -1,13 +1,21 @@
1
- declare function _exports(path: string, operation: Operation, api: OpenAPI.Document, globalDefaults?: Object): array<object>;
2
- declare namespace _exports {
3
- export { types };
4
- }
5
- export = _exports;
6
- declare namespace types {
7
- const path: string;
8
- const query: string;
9
- const body: string;
10
- const cookie: string;
11
- const formData: string;
12
- const header: string;
13
- }
1
+ import type { OASDocument, OperationObject, SchemaObject } from '../rmoas.types';
2
+ import * as RMOAS from '../rmoas.types';
3
+ export declare type SchemaWrapper = {
4
+ $schema?: string;
5
+ type: string;
6
+ label?: string;
7
+ schema: SchemaObject;
8
+ deprecatedProps?: SchemaWrapper;
9
+ };
10
+ export declare const types: {
11
+ [key: keyof RMOAS.OASDocument]: string;
12
+ };
13
+ declare const _default: (path: string, operation: OperationObject, api: OASDocument, globalDefaults?: {}) => SchemaWrapper[];
14
+ /**
15
+ * @param {string} path
16
+ * @param {Operation} operation
17
+ * @param {OpenAPI.Document} api
18
+ * @param {Object} globalDefaults
19
+ * @returns {Array<object>}
20
+ */
21
+ export default _default;
@@ -1,8 +1,8 @@
1
1
  import type * as RMOAS from '../rmoas.types';
2
- export declare type RequestBodyExamples = {
2
+ export declare type RequestBodyExamples = Array<{
3
3
  mediaType: string;
4
4
  examples: any;
5
- }[];
5
+ }>;
6
6
  /**
7
7
  * @param operation Operation to retrieve requestBody examples for.
8
8
  * @returns An object of response examples keyed by their media type.
@@ -1,6 +1,18 @@
1
- declare function _exports(operation: any, api: any, statusCode: any): {
2
- type: any;
3
- schema: any;
1
+ import type { OASDocument, SchemaObject } from 'rmoas.types';
2
+ import type Operation from 'operation';
3
+ /**
4
+ * Extract all the response schemas, matching the format of get-parameters-as-json-schema.
5
+ *
6
+ * Note: This expects a dereferenced schema.
7
+ *
8
+ * @param operation Operation to construct a response JSON Schema for.
9
+ * @param api The OpenAPI definition that this operation originates.
10
+ * @param statusCode The response status code to generate a schema for.
11
+ * @returns Array<{schema: Object, type: string, label: string}>
12
+ */
13
+ export default function getResponseAsJsonSchema(operation: Operation, api: OASDocument, statusCode: string | number): {
14
+ type: string | Array<string>;
15
+ schema: SchemaObject;
4
16
  label: string;
17
+ description?: string;
5
18
  }[];
6
- export = _exports;
@@ -1,8 +1,8 @@
1
1
  import type * as RMOAS from '../rmoas.types';
2
- export declare type ResponseExamples = {
2
+ export declare type ResponseExamples = Array<{
3
3
  status: string;
4
4
  mediaTypes: Record<string, RMOAS.MediaTypeObject>;
5
- }[];
5
+ }>;
6
6
  /**
7
7
  * @param operation Operation to retrieve response examples for.
8
8
  * @returns An object of response examples keyed by their media type.
@@ -1,13 +1,11 @@
1
- import type * as RMOAS from './rmoas.types';
2
- import type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';
3
1
  import type { RequestBodyExamples } from './operation/get-requestbody-examples';
4
2
  import type { CallbackExamples } from './operation/get-callback-examples';
5
3
  import type { ResponseExamples } from './operation/get-response-examples';
6
- import Oas from '.';
4
+ import * as RMOAS from './rmoas.types';
7
5
  declare type SecurityType = 'Basic' | 'Bearer' | 'Query' | 'Header' | 'Cookie' | 'OAuth2' | 'http' | 'apiKey';
8
6
  export default class Operation {
9
7
  /**
10
- * Schema of the operation from the API Definiton.
8
+ * Schema of the operation from the API Definition.
11
9
  */
12
10
  schema: RMOAS.OperationObject;
13
11
  /**
@@ -45,7 +43,7 @@ export default class Operation {
45
43
  request: Array<string>;
46
44
  response: Array<string>;
47
45
  };
48
- constructor(api: Oas | RMOAS.OASDocument, path: string, method: RMOAS.HttpMethods, operation: RMOAS.OperationObject);
46
+ constructor(api: RMOAS.OASDocument, path: string, method: RMOAS.HttpMethods, operation: RMOAS.OperationObject);
49
47
  getContentType(): string;
50
48
  isFormUrlEncoded(): boolean;
51
49
  isMultipart(): boolean;
@@ -55,105 +53,114 @@ export default class Operation {
55
53
  * Returns an array of all security requirements associated wtih this operation. If none are defined at the operation
56
54
  * level, the securities for the entire API definition are returned (with an empty array as a final fallback).
57
55
  *
58
- * @returns Array of security requirement objects.
56
+ * @returns {Array}
59
57
  */
60
- getSecurity(): OpenAPIV3.SecurityRequirementObject[];
58
+ getSecurity(): Array<RMOAS.SecurityRequirementObject>;
61
59
  /**
62
60
  * @see {@link https://swagger.io/docs/specification/authentication/#multiple}
63
61
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#security-requirement-object}
64
- * @param filterInvalid Optional flag that, when set to `true`, filters out invalid/nonexistent security schemes,
65
- * rather than returning `false`.
66
- * @returns An array of arrays of objects of grouped security schemes. The inner array determines and-grouped
62
+ * @param {boolean} filterInvalid Optional flag that, when set to `true`, filters out invalid/nonexistent security
63
+ * schemes, rather than returning `false`.
64
+ * @returns {Array} An array of arrays of objects of grouped security schemes. The inner array determines and-grouped
67
65
  * security schemes, the outer array determines or-groups.
68
66
  */
69
- getSecurityWithTypes(filterInvalid?: boolean): (false | (false | {
67
+ getSecurityWithTypes(filterInvalid?: boolean): Array<false | Array<false | {
68
+ security: RMOAS.KeyedSecuritySchemeObject;
70
69
  type: SecurityType;
71
- security: ({
72
- _key: string;
73
- 'x-default'?: string | number;
74
- } & OpenAPIV3.HttpSecurityScheme) | ({
75
- _key: string;
76
- 'x-default'?: string | number;
77
- } & OpenAPIV3.ApiKeySecurityScheme) | ({
78
- _key: string;
79
- 'x-default'?: string | number;
80
- } & OpenAPIV3.OAuth2SecurityScheme);
81
- })[])[];
70
+ }>>;
82
71
  /**
83
72
  * @returns An object where the keys are unique scheme types, and the values are arrays containing each security
84
73
  * scheme of that type.
85
74
  */
86
- prepareSecurity(): Record<SecurityType, RMOAS.KeyedSecuritySchemeObject[]>;
87
- getHeaders(): {
88
- request: string[];
89
- response: string[];
90
- };
75
+ prepareSecurity(): Record<SecurityType, Array<RMOAS.KeyedSecuritySchemeObject>>;
76
+ getHeaders(): Operation['headers'];
91
77
  /**
92
- * @returns If the operation has an `operationId` present in its schema.
78
+ * Determine if the operation has an operation present in its schema.
79
+ *
80
+ * @returns {boolean}
93
81
  */
94
82
  hasOperationId(): boolean;
95
83
  /**
96
- * Retrieve an operation ID for this operation. If one is not present (it's not required by the spec!) a hash of the
97
- * path and method will be returned instead.
84
+ * Get an `operationId` for this operation. If one is not present (it's not required by the spec!) a hash of the path
85
+ * and method will be returned instead.
98
86
  *
99
- * @returns The found or generated operation ID.
87
+ * @returns {string}
100
88
  */
101
89
  getOperationId(): string;
102
90
  /**
103
- * @returns An array of all tags, and their metadata, that exist on this operation.
91
+ * Return an array of all tags, and their metadata, that exist on this operation.
92
+ *
93
+ * @returns {Array}
104
94
  */
105
- getTags(): OpenAPIV3.TagObject[];
95
+ getTags(): Array<RMOAS.TagObject>;
106
96
  /**
107
- * @returns If the operation is flagged as `deprecated` or not.
97
+ * Return is the operation is flagged as `deprecated` or not.
98
+ *
99
+ * @returns {boolean}
108
100
  */
109
101
  isDeprecated(): boolean;
110
102
  /**
103
+ * Return the parameters (non-request body) on the operation.
104
+ *
111
105
  * @todo This should also pull in common params.
112
- * @returns The parameters (non-request body) on the operation.
106
+ * @returns {Array}
113
107
  */
114
- getParameters(): OpenAPIV3.ParameterObject[];
108
+ getParameters(): Array<RMOAS.ParameterObject>;
115
109
  /**
116
110
  * Convert the operation into an array of JSON Schema for each available type of parameter available on the operation.
117
- * `globalDefaults` contains an object of user defined parameter defaults used.
111
+ * `globalDefaults` contains an object of user defined parameter defaults used in `constructSchema`.
118
112
  *
119
- * @param globalDefaults An object of global defaults to apply as a `default` in the returned JSON Schema.
120
- * @returns An array of JSON Schema objects.
113
+ * @param {Object} globalDefaults
114
+ * @returns {Array}
121
115
  */
122
- getParametersAsJsonSchema(globalDefaults?: unknown): array<object>;
116
+ getParametersAsJsonSchema(globalDefaults?: unknown): import("./operation/get-parameters-as-json-schema").SchemaWrapper[];
123
117
  /**
124
118
  * Get a single response for this status code, formatted as JSON schema.
125
119
  *
126
- * @param statusCode Status code to pull a JSON Schema object for.
127
- * @returns A JSON Schema object for the specified response.
120
+ * @param {string|number} statusCode
121
+ * @returns {Array}
128
122
  */
129
123
  getResponseAsJsonSchema(statusCode: string): {
130
- type: any;
131
- schema: any;
124
+ type: string | string[];
125
+ schema: RMOAS.SchemaObject;
132
126
  label: string;
127
+ description?: string;
133
128
  }[];
134
129
  /**
135
- * @returns An array of all valid response status codes for this operation.
130
+ * Get an array of all valid response status codes for this operation.
131
+ *
132
+ * @returns {Array}
136
133
  */
137
- getResponseStatusCodes(): string[];
134
+ getResponseStatusCodes(): Array<string>;
138
135
  /**
139
- * @returns If the operation has a request body.
136
+ * Determine if the operation has a request body.
137
+ *
138
+ * @returns {boolean}
140
139
  */
141
140
  hasRequestBody(): boolean;
142
141
  /**
143
- * @returns An array of request body examples that this operation has.
142
+ * Retrieve an array of request body examples that this operation has.
143
+ *
144
+ * @returns {Array}
144
145
  */
145
146
  getRequestBodyExamples(): RequestBodyExamples;
146
147
  /**
147
- * @param statusCode HTTP status code to get.
148
- * @returns A specific response out of the operation by a given HTTP status code.
148
+ * Return a specific response out of the operation by a given HTTP status code.
149
+ *
150
+ * @param {(string|number)} statusCode
151
+ * @returns {(boolean|object)}
149
152
  */
150
- getResponseByStatusCode(statusCode: string | number): false | OpenAPIV3.ResponseObject | OpenAPIV3_1.ResponseObject;
153
+ getResponseByStatusCode(statusCode: string | number): boolean | RMOAS.ResponseObject;
151
154
  /**
152
- * @returns An array of response examples that this operation has.
155
+ * Retrieve an array of response examples that this operation has.
156
+ *
157
+ * @returns {Array}
153
158
  */
154
159
  getResponseExamples(): ResponseExamples;
155
160
  /**
156
- * @returns If the operation has callbacks.
161
+ * Determine if the operation has callbacks.
162
+ *
163
+ * @returns {boolean}
157
164
  */
158
165
  hasCallbacks(): boolean;
159
166
  /**
@@ -164,15 +171,19 @@ export default class Operation {
164
171
  * @param identifier Callback identifier to look for.
165
172
  * @param expression Callback expression to look for.
166
173
  * @param method HTTP Method on the callback to look for.
167
- * @returns The found callback.
174
+ * @returns {(false|Callback)}
168
175
  */
169
176
  getCallback(identifier: string, expression: string, method: RMOAS.HttpMethods): false | Callback;
170
177
  /**
171
- * @returns An array of operations created from each callback.
178
+ * Retrieve an array of operations created from each callback.
179
+ *
180
+ * @returns {Array}
172
181
  */
173
- getCallbacks(): false | (false | Callback)[];
182
+ getCallbacks(): false | Array<false | Callback>;
174
183
  /**
175
- * @returns An array of callback examples that this operation has.
184
+ * Retrieve an array of callback examples that this operation has.
185
+ *
186
+ * @returns {Array}
176
187
  */
177
188
  getCallbackExamples(): CallbackExamples;
178
189
  /**
@@ -195,12 +206,17 @@ export default class Operation {
195
206
  getExtension(extension: string): unknown;
196
207
  }
197
208
  export declare class Callback extends Operation {
209
+ /**
210
+ * The identifier that this callback is set to.
211
+ */
198
212
  identifier: string;
199
- constructor(api: RMOAS.OASDocument, path: string, method: RMOAS.HttpMethods, operation: RMOAS.OperationObject, identifier: string);
213
+ constructor(oas: RMOAS.OASDocument, path: string, method: RMOAS.HttpMethods, operation: RMOAS.OperationObject, identifier: string);
200
214
  /**
215
+ * Return the primary identifier for this callback.
216
+ *
201
217
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#callback-object}
202
218
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#callbackObject}
203
- * @returns The primary identifier for this callback.
219
+ * @returns {string}
204
220
  */
205
221
  getIdentifier(): string;
206
222
  }
@@ -5,6 +5,11 @@ import type { JSONSchema4, JSONSchema6, JSONSchema7 } from 'json-schema';
5
5
  * @returns If the supplied data has a `$ref` pointer.
6
6
  */
7
7
  export declare function isRef(check: unknown): check is OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject;
8
+ /**
9
+ * @param check API definition to determine if it's a 3.1 definition.
10
+ * @returns If the definition is a 3.1 definition.
11
+ */
12
+ export declare function isOAS31(check: OpenAPIV3.Document | OpenAPIV3_1.Document): check is OpenAPIV3_1.Document;
8
13
  export interface User {
9
14
  [key: string]: unknown;
10
15
  keys?: Array<{
@@ -92,6 +97,11 @@ export declare type ExampleObject = OpenAPIV3.ExampleObject | OpenAPIV3_1.Exampl
92
97
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#tagObject}
93
98
  */
94
99
  export declare type TagObject = OpenAPIV3.TagObject | OpenAPIV3_1.TagObject;
100
+ /**
101
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#headerObject}
102
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#headerObject}
103
+ */
104
+ export declare type HeaderObject = OpenAPIV3.HeaderObject | OpenAPIV3_1.HeaderObject;
95
105
  /**
96
106
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schemaObject}
97
107
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schemaObject}
@@ -101,7 +111,19 @@ export declare type SchemaObject = (OpenAPIV3.SchemaObject | OpenAPIV3_1.SchemaO
101
111
  readOnly?: boolean;
102
112
  writeOnly?: boolean;
103
113
  'x-readme-ref-name'?: string;
114
+ example?: unknown;
115
+ examples?: Array<unknown>;
116
+ nullable?: boolean;
117
+ xml?: unknown;
118
+ externalDocs?: unknown;
119
+ components?: OpenAPIV3_1.ComponentsObject;
104
120
  };
121
+ /**
122
+ * @param check JSON Schema object to determine if it's a non-polymorphic schema.
123
+ * @param isPolymorphicAllOfChild If this JSON Schema object is the child of a polymorphic `allOf`.
124
+ * @returns If the JSON Schema object is a JSON Schema object.
125
+ */
126
+ export declare function isSchema(check: unknown, isPolymorphicAllOfChild?: boolean): check is SchemaObject;
105
127
  /**
106
128
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#securitySchemeObject}
107
129
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#securitySchemeObject}
package/@types/utils.d.ts CHANGED
@@ -4,12 +4,8 @@ declare const _default: {
4
4
  findSchemaDefinition: typeof findSchemaDefinition;
5
5
  getSchema: typeof getSchema;
6
6
  jsonSchemaTypes: {
7
- path: string;
8
- query: string;
9
- body: string;
10
- cookie: string;
11
- formData: string;
12
- header: string;
7
+ [key: string]: string;
8
+ [key: number]: string;
13
9
  };
14
10
  matchesMimeType: {
15
11
  formUrlEncoded: (mimeType: string) => boolean;
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 17.3.0 (2021-12-06)
2
+
3
+ * feat: OAS 3.1 for JSON Schemas (#530) ([91475da](https://github.com/readmeio/oas/commit/91475da)), closes [#530](https://github.com/readmeio/oas/issues/530)
4
+
5
+
6
+
1
7
  ## 17.2.0 (2021-12-02)
2
8
 
3
9
  * chore(deps-dev): bump @commitlint/cli from 14.1.0 to 15.0.0 (#552) ([b03dbd3](https://github.com/readmeio/oas/commit/b03dbd3)), closes [#552](https://github.com/readmeio/oas/issues/552)