oas 17.2.0 → 17.4.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,9 @@ 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);
47
+ getSummary(): string;
48
+ getDescription(): string;
49
49
  getContentType(): string;
50
50
  isFormUrlEncoded(): boolean;
51
51
  isMultipart(): boolean;
@@ -55,105 +55,114 @@ 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 of security requirement objects.
58
+ * @returns {Array}
59
59
  */
60
- getSecurity(): OpenAPIV3.SecurityRequirementObject[];
60
+ getSecurity(): Array<RMOAS.SecurityRequirementObject>;
61
61
  /**
62
62
  * @see {@link https://swagger.io/docs/specification/authentication/#multiple}
63
63
  * @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
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
67
  * security schemes, the outer array determines or-groups.
68
68
  */
69
- getSecurityWithTypes(filterInvalid?: boolean): (false | (false | {
69
+ getSecurityWithTypes(filterInvalid?: boolean): Array<false | Array<false | {
70
+ security: RMOAS.KeyedSecuritySchemeObject;
70
71
  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
- })[])[];
72
+ }>>;
82
73
  /**
83
74
  * @returns An object where the keys are unique scheme types, and the values are arrays containing each security
84
75
  * scheme of that type.
85
76
  */
86
- prepareSecurity(): Record<SecurityType, RMOAS.KeyedSecuritySchemeObject[]>;
87
- getHeaders(): {
88
- request: string[];
89
- response: string[];
90
- };
77
+ prepareSecurity(): Record<SecurityType, Array<RMOAS.KeyedSecuritySchemeObject>>;
78
+ getHeaders(): Operation['headers'];
91
79
  /**
92
- * @returns If the operation has an `operationId` present in its schema.
80
+ * Determine if the operation has an operation present in its schema.
81
+ *
82
+ * @returns {boolean}
93
83
  */
94
84
  hasOperationId(): boolean;
95
85
  /**
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.
86
+ * Get an `operationId` for this operation. If one is not present (it's not required by the spec!) a hash of the path
87
+ * and method will be returned instead.
98
88
  *
99
- * @returns The found or generated operation ID.
89
+ * @returns {string}
100
90
  */
101
91
  getOperationId(): string;
102
92
  /**
103
- * @returns An array of all tags, and their metadata, that exist on this operation.
93
+ * Return an array of all tags, and their metadata, that exist on this operation.
94
+ *
95
+ * @returns {Array}
104
96
  */
105
- getTags(): OpenAPIV3.TagObject[];
97
+ getTags(): Array<RMOAS.TagObject>;
106
98
  /**
107
- * @returns If the operation is flagged as `deprecated` or not.
99
+ * Return is the operation is flagged as `deprecated` or not.
100
+ *
101
+ * @returns {boolean}
108
102
  */
109
103
  isDeprecated(): boolean;
110
104
  /**
105
+ * Return the parameters (non-request body) on the operation.
106
+ *
111
107
  * @todo This should also pull in common params.
112
- * @returns The parameters (non-request body) on the operation.
108
+ * @returns {Array}
113
109
  */
114
- getParameters(): OpenAPIV3.ParameterObject[];
110
+ getParameters(): Array<RMOAS.ParameterObject>;
115
111
  /**
116
112
  * 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.
113
+ * `globalDefaults` contains an object of user defined parameter defaults used in `constructSchema`.
118
114
  *
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.
115
+ * @param {Object} globalDefaults
116
+ * @returns {Array}
121
117
  */
122
- getParametersAsJsonSchema(globalDefaults?: unknown): array<object>;
118
+ getParametersAsJsonSchema(globalDefaults?: unknown): import("./operation/get-parameters-as-json-schema").SchemaWrapper[];
123
119
  /**
124
120
  * Get a single response for this status code, formatted as JSON schema.
125
121
  *
126
- * @param statusCode Status code to pull a JSON Schema object for.
127
- * @returns A JSON Schema object for the specified response.
122
+ * @param {string|number} statusCode
123
+ * @returns {Array}
128
124
  */
129
125
  getResponseAsJsonSchema(statusCode: string): {
130
- type: any;
131
- schema: any;
126
+ type: string | string[];
127
+ schema: RMOAS.SchemaObject;
132
128
  label: string;
129
+ description?: string;
133
130
  }[];
134
131
  /**
135
- * @returns An array of all valid response status codes for this operation.
132
+ * Get an array of all valid response status codes for this operation.
133
+ *
134
+ * @returns {Array}
136
135
  */
137
- getResponseStatusCodes(): string[];
136
+ getResponseStatusCodes(): Array<string>;
138
137
  /**
139
- * @returns If the operation has a request body.
138
+ * Determine if the operation has a request body.
139
+ *
140
+ * @returns {boolean}
140
141
  */
141
142
  hasRequestBody(): boolean;
142
143
  /**
143
- * @returns An array of request body examples that this operation has.
144
+ * Retrieve an array of request body examples that this operation has.
145
+ *
146
+ * @returns {Array}
144
147
  */
145
148
  getRequestBodyExamples(): RequestBodyExamples;
146
149
  /**
147
- * @param statusCode HTTP status code to get.
148
- * @returns A specific response out of the operation by a given HTTP status code.
150
+ * Return a specific response out of the operation by a given HTTP status code.
151
+ *
152
+ * @param {(string|number)} statusCode
153
+ * @returns {(boolean|object)}
149
154
  */
150
- getResponseByStatusCode(statusCode: string | number): false | OpenAPIV3.ResponseObject | OpenAPIV3_1.ResponseObject;
155
+ getResponseByStatusCode(statusCode: string | number): boolean | RMOAS.ResponseObject;
151
156
  /**
152
- * @returns An array of response examples that this operation has.
157
+ * Retrieve an array of response examples that this operation has.
158
+ *
159
+ * @returns {Array}
153
160
  */
154
161
  getResponseExamples(): ResponseExamples;
155
162
  /**
156
- * @returns If the operation has callbacks.
163
+ * Determine if the operation has callbacks.
164
+ *
165
+ * @returns {boolean}
157
166
  */
158
167
  hasCallbacks(): boolean;
159
168
  /**
@@ -164,15 +173,19 @@ export default class Operation {
164
173
  * @param identifier Callback identifier to look for.
165
174
  * @param expression Callback expression to look for.
166
175
  * @param method HTTP Method on the callback to look for.
167
- * @returns The found callback.
176
+ * @returns {(false|Callback)}
168
177
  */
169
178
  getCallback(identifier: string, expression: string, method: RMOAS.HttpMethods): false | Callback;
170
179
  /**
171
- * @returns An array of operations created from each callback.
180
+ * Retrieve an array of operations created from each callback.
181
+ *
182
+ * @returns {Array}
172
183
  */
173
- getCallbacks(): false | (false | Callback)[];
184
+ getCallbacks(): false | Array<false | Callback>;
174
185
  /**
175
- * @returns An array of callback examples that this operation has.
186
+ * Retrieve an array of callback examples that this operation has.
187
+ *
188
+ * @returns {Array}
176
189
  */
177
190
  getCallbackExamples(): CallbackExamples;
178
191
  /**
@@ -195,12 +208,17 @@ export default class Operation {
195
208
  getExtension(extension: string): unknown;
196
209
  }
197
210
  export declare class Callback extends Operation {
211
+ /**
212
+ * The identifier that this callback is set to.
213
+ */
198
214
  identifier: string;
199
- constructor(api: RMOAS.OASDocument, path: string, method: RMOAS.HttpMethods, operation: RMOAS.OperationObject, identifier: string);
215
+ constructor(oas: RMOAS.OASDocument, path: string, method: RMOAS.HttpMethods, operation: RMOAS.OperationObject, identifier: string);
200
216
  /**
217
+ * Return the primary identifier for this callback.
218
+ *
201
219
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#callback-object}
202
220
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#callbackObject}
203
- * @returns The primary identifier for this callback.
221
+ * @returns {string}
204
222
  */
205
223
  getIdentifier(): string;
206
224
  }
@@ -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,29 @@
1
+ ## 17.4.0 (2021-12-17)
2
+
3
+ * feat: adding accessors for operation summary and description (#562) ([1dd6a9f](https://github.com/readmeio/oas/commit/1dd6a9f)), closes [#562](https://github.com/readmeio/oas/issues/562)
4
+
5
+
6
+
7
+ ## <small>17.3.2 (2021-12-14)</small>
8
+
9
+ * fix: exclude readonly params from deprecatedProps (#561) ([3342bf2](https://github.com/readmeio/oas/commit/3342bf2)), closes [#561](https://github.com/readmeio/oas/issues/561)
10
+ * test: adding a regression case for the enum typescript quirk (#560) ([fabf01b](https://github.com/readmeio/oas/commit/fabf01b)), closes [#560](https://github.com/readmeio/oas/issues/560)
11
+
12
+
13
+
14
+ ## <small>17.3.1 (2021-12-08)</small>
15
+
16
+ * fix: upgrading oas-normalize to fix a rare npm installation issue (#558) ([ce6123d](https://github.com/readmeio/oas/commit/ce6123d)), closes [#558](https://github.com/readmeio/oas/issues/558)
17
+ * fix(jsonschema): move the version identifier to a better location (#557) ([1b52aec](https://github.com/readmeio/oas/commit/1b52aec)), closes [#557](https://github.com/readmeio/oas/issues/557)
18
+
19
+
20
+
21
+ ## 17.3.0 (2021-12-06)
22
+
23
+ * 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)
24
+
25
+
26
+
1
27
  ## 17.2.0 (2021-12-02)
2
28
 
3
29
  * 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)