oas 17.7.2 → 17.8.1

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 (35) hide show
  1. package/@types/index.d.ts +9 -6
  2. package/@types/lib/get-schema.d.ts +1 -5
  3. package/@types/lib/openapi-to-json-schema.d.ts +2 -4
  4. package/@types/operation/get-callback-examples.d.ts +2 -2
  5. package/@types/operation/get-parameters-as-json-schema.d.ts +1 -3
  6. package/@types/operation/get-requestbody-examples.d.ts +2 -2
  7. package/@types/operation/get-response-as-json-schema.d.ts +1 -1
  8. package/@types/operation/get-response-examples.d.ts +2 -2
  9. package/@types/operation.d.ts +34 -15
  10. package/@types/rmoas.types.d.ts +9 -17
  11. package/@types/samples/index.d.ts +1 -1
  12. package/@types/samples/utils.d.ts +1 -1
  13. package/@types/utils.d.ts +1 -4
  14. package/CHANGELOG.md +35 -0
  15. package/dist/index.js +14 -2
  16. package/dist/lib/dedupe-common-parameters.js +5 -1
  17. package/dist/lib/openapi-to-json-schema.js +5 -1
  18. package/dist/operation/get-parameters-as-json-schema.js +5 -1
  19. package/dist/operation.js +62 -7
  20. package/package.json +3 -3
  21. package/src/cli/lib/utils.js +10 -7
  22. package/src/index.ts +18 -10
  23. package/src/lib/get-schema.ts +1 -7
  24. package/src/lib/matches-mimetype.ts +1 -1
  25. package/src/lib/openapi-to-json-schema.ts +8 -10
  26. package/src/operation/get-callback-examples.ts +2 -2
  27. package/src/operation/get-parameters-as-json-schema.ts +11 -11
  28. package/src/operation/get-requestbody-examples.ts +2 -2
  29. package/src/operation/get-response-as-json-schema.ts +1 -1
  30. package/src/operation/get-response-examples.ts +3 -3
  31. package/src/operation.ts +92 -26
  32. package/src/rmoas.types.ts +12 -16
  33. package/src/samples/index.ts +3 -3
  34. package/src/samples/utils.ts +1 -1
  35. package/tsconfig.test.json +0 -9
package/@types/index.d.ts CHANGED
@@ -13,10 +13,10 @@ declare type PathMatch = {
13
13
  operation: RMOAS.PathsObject;
14
14
  match?: MatchResult;
15
15
  };
16
- declare type PathMatches = Array<PathMatch>;
17
- declare type Variables = Record<string, string | number | Array<{
16
+ declare type PathMatches = PathMatch[];
17
+ declare type Variables = Record<string, string | number | {
18
18
  default?: string | number;
19
- }> | {
19
+ }[] | {
20
20
  default?: string | number;
21
21
  }>;
22
22
  export default class Oas {
@@ -35,10 +35,10 @@ export default class Oas {
35
35
  *
36
36
  * @todo These are always `Promise.resolve` and `Promise.reject`. Make these types more specific than `any`.
37
37
  */
38
- protected promises: Array<{
38
+ protected promises: {
39
39
  resolve: any;
40
40
  reject: any;
41
- }>;
41
+ }[];
42
42
  /**
43
43
  * Internal storage array that the library utilizes to keep track of its `dereferencing` state so it doesn't initiate
44
44
  * multiple dereferencing processes.
@@ -217,7 +217,10 @@ export default class Oas {
217
217
  * Dereference the current OAS definition so it can be parsed free of worries of `$ref` schemas and circular
218
218
  * structures.
219
219
  *
220
+ * @param opts
220
221
  */
221
- dereference(): Promise<unknown>;
222
+ dereference(opts?: {
223
+ preserveRefAsJSONSchemaTitle: boolean;
224
+ }): Promise<unknown>;
222
225
  }
223
226
  export { Operation, Callback, Webhook, utils };
@@ -11,11 +11,7 @@ import type * as RMOAS from '../rmoas.types';
11
11
  * @param operation Operation to look for a primary requestBody schema in.
12
12
  * @param api The API definition that this operation exists within.
13
13
  */
14
- export default function getSchema(operation: RMOAS.OperationObject, api?: RMOAS.OASDocument | {
15
- [schemaType: string]: {
16
- [key: string]: RMOAS.SchemaObject;
17
- };
18
- }): {
14
+ export default function getSchema(operation: RMOAS.OperationObject, api?: RMOAS.OASDocument | Record<string, Record<string, RMOAS.SchemaObject>>): {
19
15
  type: string;
20
16
  schema: any;
21
17
  };
@@ -1,10 +1,8 @@
1
1
  import * as RMOAS from '../rmoas.types';
2
- declare type PrevSchemasType = Array<RMOAS.SchemaObject>;
2
+ declare type PrevSchemasType = RMOAS.SchemaObject[];
3
3
  export declare type toJsonSchemaOptions = {
4
4
  currentLocation?: string;
5
- globalDefaults?: {
6
- [key: string]: unknown;
7
- };
5
+ globalDefaults?: Record<string, unknown>;
8
6
  isPolymorphicAllOfChild?: boolean;
9
7
  prevSchemas?: PrevSchemasType;
10
8
  refLogger?: (ref: string) => void;
@@ -1,10 +1,10 @@
1
1
  import type * as RMOAS from '../rmoas.types';
2
- export declare type CallbackExamples = Array<{
2
+ export declare type CallbackExamples = {
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 a collection of examples for any callbacks that may be present.
10
10
  *
@@ -14,9 +14,7 @@ export declare type SchemaWrapper = {
14
14
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#parameterObject}
15
15
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameterObject}
16
16
  */
17
- export declare const types: {
18
- [key: keyof RMOAS.OASDocument]: string;
19
- };
17
+ export declare const types: Record<keyof RMOAS.OASDocument, string>;
20
18
  /**
21
19
  * @param operation
22
20
  * @param api
@@ -1,8 +1,8 @@
1
1
  import type * as RMOAS from '../rmoas.types';
2
- export declare type RequestBodyExamples = Array<{
2
+ export declare type RequestBodyExamples = {
3
3
  mediaType: string;
4
4
  examples: any;
5
- }>;
5
+ }[];
6
6
  /**
7
7
  * Retrieve a collection of request body examples, keyed by their media type.
8
8
  *
@@ -10,7 +10,7 @@ import type Operation from 'operation';
10
10
  * @param statusCode The response status code to generate a schema for.
11
11
  */
12
12
  export default function getResponseAsJsonSchema(operation: Operation, api: OASDocument, statusCode: string | number): {
13
- type: string | Array<string>;
13
+ type: string | string[];
14
14
  schema: SchemaObject;
15
15
  label: string;
16
16
  description?: string;
@@ -1,8 +1,8 @@
1
1
  import type * as RMOAS from '../rmoas.types';
2
- export declare type ResponseExamples = Array<{
2
+ export declare type ResponseExamples = {
3
3
  status: string;
4
4
  mediaTypes: Record<string, RMOAS.MediaTypeObject>;
5
- }>;
5
+ }[];
6
6
  /**
7
7
  * Retrieve a collection of response examples keyed, by their media type.
8
8
  *
@@ -1,6 +1,7 @@
1
1
  import type { RequestBodyExamples } from './operation/get-requestbody-examples';
2
2
  import type { CallbackExamples } from './operation/get-callback-examples';
3
3
  import type { ResponseExamples } from './operation/get-response-examples';
4
+ import type { SchemaWrapper } from './operation/get-parameters-as-json-schema';
4
5
  import * as RMOAS from './rmoas.types';
5
6
  declare type SecurityType = 'Basic' | 'Bearer' | 'Query' | 'Header' | 'Cookie' | 'OAuth2' | 'http' | 'apiKey';
6
7
  export default class Operation {
@@ -40,9 +41,13 @@ export default class Operation {
40
41
  * Flattened out arrays of both request and response headers that are utilized on this operation.
41
42
  */
42
43
  headers: {
43
- request: Array<string>;
44
- response: Array<string>;
44
+ request: string[];
45
+ response: string[];
45
46
  };
47
+ /**
48
+ * All parameters and request bodies converted into JSON Schema.
49
+ */
50
+ parameterJsonSchema: SchemaWrapper[];
46
51
  constructor(api: RMOAS.OASDocument, path: string, method: RMOAS.HttpMethods, operation: RMOAS.OperationObject);
47
52
  getSummary(): string;
48
53
  getDescription(): string;
@@ -56,7 +61,7 @@ export default class Operation {
56
61
  * level, the securities for the entire API definition are returned (with an empty array as a final fallback).
57
62
  *
58
63
  */
59
- getSecurity(): Array<RMOAS.SecurityRequirementObject>;
64
+ getSecurity(): RMOAS.SecurityRequirementObject[];
60
65
  /**
61
66
  * Retrieve a collection of grouped security schemes. The inner array determines and-grouped security schemes, the
62
67
  * outer array determines or-groups.
@@ -67,16 +72,16 @@ export default class Operation {
67
72
  * @param filterInvalid Optional flag that, when set to `true`, filters out invalid/nonexistent security schemes,
68
73
  * rather than returning `false`.
69
74
  */
70
- getSecurityWithTypes(filterInvalid?: boolean): Array<false | Array<false | {
75
+ getSecurityWithTypes(filterInvalid?: boolean): (false | (false | {
71
76
  security: RMOAS.KeyedSecuritySchemeObject;
72
77
  type: SecurityType;
73
- }>>;
78
+ })[])[];
74
79
  /**
75
80
  * Retrieve an object where the keys are unique scheme types, and the values are arrays containing each security
76
81
  * scheme of that type.
77
82
  *
78
83
  */
79
- prepareSecurity(): Record<SecurityType, Array<RMOAS.KeyedSecuritySchemeObject>>;
84
+ prepareSecurity(): Record<SecurityType, RMOAS.KeyedSecuritySchemeObject[]>;
80
85
  getHeaders(): Operation['headers'];
81
86
  /**
82
87
  * Determine if the operation has an operation present in its schema.
@@ -84,16 +89,20 @@ export default class Operation {
84
89
  */
85
90
  hasOperationId(): boolean;
86
91
  /**
87
- * Get an `operationId` for this operation. If one is not present (it's not required by the spec!) a hash of the path
88
- * and method will be returned instead.
92
+ * Get an `operationId` for this operation. If one is not present (it's not required by the spec!)
93
+ * a hash of the path and method will be returned instead.
89
94
  *
95
+ * @param opts
96
+ * @param opts.camelCase Generate a JS method-friendly operation ID when one isn't present.
90
97
  */
91
- getOperationId(): string;
98
+ getOperationId(opts?: {
99
+ camelCase: boolean;
100
+ }): string;
92
101
  /**
93
102
  * Return an array of all tags, and their metadata, that exist on this operation.
94
103
  *
95
104
  */
96
- getTags(): Array<RMOAS.TagObject>;
105
+ getTags(): RMOAS.TagObject[];
97
106
  /**
98
107
  * Return is the operation is flagged as `deprecated` or not.
99
108
  *
@@ -108,14 +117,19 @@ export default class Operation {
108
117
  * Return the parameters (non-request body) on the operation.
109
118
  *
110
119
  */
111
- getParameters(): Array<RMOAS.ParameterObject>;
120
+ getParameters(): RMOAS.ParameterObject[];
121
+ /**
122
+ * Determine if this operation has any required parameters.
123
+ *
124
+ */
125
+ hasRequiredParameters(): boolean;
112
126
  /**
113
127
  * Convert the operation into an array of JSON Schema schemas for each available type of parameter available on the
114
128
  * operation.
115
129
  *
116
130
  * @param globalDefaults Contains an object of user defined schema defaults.
117
131
  */
118
- getParametersAsJsonSchema(globalDefaults?: Record<string, unknown>): import("./operation/get-parameters-as-json-schema").SchemaWrapper[];
132
+ getParametersAsJsonSchema(globalDefaults?: Record<string, unknown>): SchemaWrapper[];
119
133
  /**
120
134
  * Get a single response for this status code, formatted as JSON schema.
121
135
  *
@@ -131,7 +145,7 @@ export default class Operation {
131
145
  * Get an array of all valid response status codes for this operation.
132
146
  *
133
147
  */
134
- getResponseStatusCodes(): Array<string>;
148
+ getResponseStatusCodes(): string[];
135
149
  /**
136
150
  * Determine if the operation has any request bodies.
137
151
  *
@@ -144,6 +158,11 @@ export default class Operation {
144
158
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#mediaTypeObject}
145
159
  */
146
160
  getRequestBodyMediaTypes(): string[];
161
+ /**
162
+ * Determine if this operation has a required request body.
163
+ *
164
+ */
165
+ hasRequiredRequestBody(): boolean;
147
166
  /**
148
167
  * Retrieve a specific request body content schema off this operation.
149
168
  *
@@ -191,7 +210,7 @@ export default class Operation {
191
210
  * Retrieve an array of operations created from each callback.
192
211
  *
193
212
  */
194
- getCallbacks(): false | Array<false | Callback>;
213
+ getCallbacks(): false | (false | Callback)[];
195
214
  /**
196
215
  * Retrieve an array of callback examples that this operation has.
197
216
  *
@@ -233,7 +252,7 @@ export declare class Callback extends Operation {
233
252
  getIdentifier(): string;
234
253
  getSummary(): string;
235
254
  getDescription(): string;
236
- getParameters(): Array<RMOAS.ParameterObject>;
255
+ getParameters(): RMOAS.ParameterObject[];
237
256
  }
238
257
  export declare class Webhook extends Operation {
239
258
  }
@@ -13,21 +13,19 @@ export declare function isRef(check: unknown): check is OpenAPIV3.ReferenceObjec
13
13
  export declare function isOAS31(check: OpenAPIV3.Document | OpenAPIV3_1.Document): check is OpenAPIV3_1.Document;
14
14
  export interface User {
15
15
  [key: string]: unknown;
16
- keys?: Array<{
16
+ keys?: {
17
17
  name: string | number;
18
18
  user?: string | number;
19
19
  pass?: string | number;
20
20
  [key: string]: unknown;
21
- }>;
21
+ }[];
22
22
  }
23
23
  export declare type HttpMethods = (OpenAPIV3.HttpMethods | OpenAPIV3_1.HttpMethods) | ('get' | 'put' | 'post' | 'delete' | 'options' | 'head' | 'patch' | 'trace');
24
24
  /**
25
25
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#oasObject}
26
26
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#oasObject}
27
27
  */
28
- export declare type OASDocument = (OpenAPIV3.Document | OpenAPIV3_1.Document) & {
29
- [extension: string]: unknown;
30
- };
28
+ export declare type OASDocument = (OpenAPIV3.Document | OpenAPIV3_1.Document) & Record<string, unknown>;
31
29
  /**
32
30
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#serverObject}
33
31
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverObject}
@@ -38,12 +36,10 @@ export declare type ServerObject = OpenAPIV3.ServerObject | OpenAPIV3_1.ServerOb
38
36
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverVariableObject}
39
37
  */
40
38
  export declare type ServerVariableObject = OpenAPIV3.ServerVariableObject | OpenAPIV3_1.ServerVariableObject;
41
- export declare type ServerVariablesObject = {
42
- [variable: string]: ServerVariableObject;
43
- };
44
- export declare type ServerVariable = Record<string, string | number | Array<{
39
+ export declare type ServerVariablesObject = Record<string, ServerVariableObject>;
40
+ export declare type ServerVariable = Record<string, string | number | {
45
41
  default?: string | number;
46
- }> | {
42
+ }[] | {
47
43
  default?: string | number;
48
44
  } | Record<string, never>>;
49
45
  export declare type Servers = {
@@ -69,9 +65,7 @@ export declare type PathItemObject = OpenAPIV3.PathItemObject | OpenAPIV3_1.Path
69
65
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#operationObject}
70
66
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#operationObject}
71
67
  */
72
- export declare type OperationObject = (OpenAPIV3.OperationObject | OpenAPIV3_1.OperationObject) & {
73
- [extension: string]: unknown;
74
- };
68
+ export declare type OperationObject = (OpenAPIV3.OperationObject | OpenAPIV3_1.OperationObject) & Record<string, unknown>;
75
69
  /**
76
70
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterObject}
77
71
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameterObject}
@@ -121,7 +115,7 @@ export declare type SchemaObject = (OpenAPIV3.SchemaObject | OpenAPIV3_1.SchemaO
121
115
  readOnly?: boolean;
122
116
  writeOnly?: boolean;
123
117
  example?: unknown;
124
- examples?: Array<unknown>;
118
+ examples?: unknown[];
125
119
  nullable?: boolean;
126
120
  xml?: unknown;
127
121
  externalDocs?: unknown;
@@ -139,9 +133,7 @@ export declare function isSchema(check: unknown, isPolymorphicAllOfChild?: boole
139
133
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#securitySchemeObject}
140
134
  */
141
135
  export declare type SecuritySchemeObject = OpenAPIV3.SecuritySchemeObject | OpenAPIV3_1.SecuritySchemeObject;
142
- export declare type SecuritySchemesObject = {
143
- [key: string]: SecuritySchemeObject;
144
- };
136
+ export declare type SecuritySchemesObject = Record<string, SecuritySchemeObject>;
145
137
  export declare type KeyedSecuritySchemeObject = {
146
138
  _key: string;
147
139
  'x-default'?: string | number;
@@ -19,6 +19,6 @@ import memoize from 'memoizee';
19
19
  declare function sampleFromSchema(schema: RMOAS.SchemaObject, opts?: {
20
20
  includeReadOnly?: boolean;
21
21
  includeWriteOnly?: boolean;
22
- }): string | number | boolean | null | Array<unknown> | Record<string, unknown> | undefined;
22
+ }): string | number | boolean | null | unknown[] | Record<string, unknown> | undefined;
23
23
  declare const _default: typeof sampleFromSchema & memoize.Memoized<typeof sampleFromSchema>;
24
24
  export default _default;
@@ -7,6 +7,6 @@
7
7
  import type * as RMOAS from '../rmoas.types';
8
8
  export declare function usesPolymorphism(schema: RMOAS.SchemaObject): false | "oneOf" | "anyOf" | "allOf";
9
9
  export declare function objectify(thing: unknown | Record<string, unknown>): Record<string, any>;
10
- export declare function normalizeArray(arr: string | number | Array<string | number>): (string | number)[];
10
+ export declare function normalizeArray(arr: string | number | (string | number)[]): (string | number)[];
11
11
  export declare function isFunc(thing: unknown): thing is Function;
12
12
  export declare function deeplyStripKey(input: unknown, keyToStrip: string, predicate?: (obj: unknown, key?: string) => boolean): any | RMOAS.SchemaObject;
package/@types/utils.d.ts CHANGED
@@ -4,10 +4,7 @@ declare const supportedMethods: Set<string>;
4
4
  declare const _default: {
5
5
  findSchemaDefinition: typeof findSchemaDefinition;
6
6
  getSchema: typeof getSchema;
7
- jsonSchemaTypes: {
8
- [key: string]: string;
9
- [key: number]: string;
10
- };
7
+ jsonSchemaTypes: Record<string, string>;
11
8
  matchesMimeType: {
12
9
  formUrlEncoded: (mimeType: string) => boolean;
13
10
  json: (contentType: string) => boolean;
package/CHANGELOG.md CHANGED
@@ -1,3 +1,38 @@
1
+ ## <small>17.8.1 (2022-03-04)</small>
2
+
3
+ * fix: typo in the `--pattern` option ([42db80a](https://github.com/readmeio/oas/commit/42db80a))
4
+ * feat: adding new accessors for determining if an operation has required params (#615) ([c081d92](https://github.com/readmeio/oas/commit/c081d92)), closes [#615](https://github.com/readmeio/oas/issues/615)
5
+ * feat: optionally generate friendlier operationIds (#602) ([6826164](https://github.com/readmeio/oas/commit/6826164)), closes [#602](https://github.com/readmeio/oas/issues/602)
6
+
7
+
8
+
9
+ ## 17.8.0 (2022-03-02)
10
+
11
+ * chore(deps-dev): bump @commitlint/cli from 16.1.0 to 16.2.1 (#612) ([e7364dd](https://github.com/readmeio/oas/commit/e7364dd)), closes [#612](https://github.com/readmeio/oas/issues/612)
12
+ * chore(deps-dev): bump @commitlint/config-conventional (#607) ([5451921](https://github.com/readmeio/oas/commit/5451921)), closes [#607](https://github.com/readmeio/oas/issues/607)
13
+ * chore(deps-dev): bump @readme/eslint-config from 8.4.1 to 8.4.4 (#609) ([7d097f3](https://github.com/readmeio/oas/commit/7d097f3)), closes [#609](https://github.com/readmeio/oas/issues/609)
14
+ * chore(deps-dev): bump @types/jest from 27.4.0 to 27.4.1 (#611) ([ed2b0a3](https://github.com/readmeio/oas/commit/ed2b0a3)), closes [#611](https://github.com/readmeio/oas/issues/611)
15
+ * chore(deps-dev): bump eslint from 8.8.0 to 8.10.0 (#610) ([2382b87](https://github.com/readmeio/oas/commit/2382b87)), closes [#610](https://github.com/readmeio/oas/issues/610)
16
+ * chore(deps-dev): bump eslint-plugin-jsdoc from 37.7.1 to 37.9.5 (#613) ([456bc79](https://github.com/readmeio/oas/commit/456bc79)), closes [#613](https://github.com/readmeio/oas/issues/613)
17
+ * chore(deps-dev): bump jest from 27.4.7 to 27.5.1 (#608) ([41c09f6](https://github.com/readmeio/oas/commit/41c09f6)), closes [#608](https://github.com/readmeio/oas/issues/608)
18
+ * chore(deps-dev): bump typescript from 4.5.5 to 4.6.2 (#605) ([93216ea](https://github.com/readmeio/oas/commit/93216ea)), closes [#605](https://github.com/readmeio/oas/issues/605)
19
+ * chore(deps): bump actions/checkout from 2.4.0 to 3 (#606) ([ea8a28a](https://github.com/readmeio/oas/commit/ea8a28a)), closes [#606](https://github.com/readmeio/oas/issues/606)
20
+ * chore(deps): bump actions/setup-node from 2.5.1 to 3 (#604) ([a463050](https://github.com/readmeio/oas/commit/a463050)), closes [#604](https://github.com/readmeio/oas/issues/604)
21
+ * chore(style): upgrading our core typescript code standards (#598) ([f12d472](https://github.com/readmeio/oas/commit/f12d472)), closes [#598](https://github.com/readmeio/oas/issues/598)
22
+ * feat: adding a dereference option to preserve ref pointers as titles (#601) ([161aebf](https://github.com/readmeio/oas/commit/161aebf)), closes [#601](https://github.com/readmeio/oas/issues/601)
23
+ * feat: upgrading swagger-inline and adding new `pathGlob` and `pattern` options (#614) ([a7dbe6a](https://github.com/readmeio/oas/commit/a7dbe6a)), closes [#614](https://github.com/readmeio/oas/issues/614)
24
+ * build: 17.7.3 release ([0c9974c](https://github.com/readmeio/oas/commit/0c9974c))
25
+ * test: colocating the testing tsconfig with the tests (#599) ([8919177](https://github.com/readmeio/oas/commit/8919177)), closes [#599](https://github.com/readmeio/oas/issues/599)
26
+
27
+
28
+
29
+ ## <small>17.7.3 (2022-02-15)</small>
30
+
31
+ * feat: adding a dereference option to preserve ref pointers as titles (#601) ([161aebf](https://github.com/readmeio/oas/commit/161aebf)), closes [#601](https://github.com/readmeio/oas/issues/601)
32
+ * chore(style): upgrading our core typescript code standards (#598) ([f12d472](https://github.com/readmeio/oas/commit/f12d472)), closes [#598](https://github.com/readmeio/oas/issues/598)
33
+
34
+
35
+
1
36
  ## <small>17.7.2 (2022-02-02)</small>
2
37
 
3
38
  * chore(deps-dev): bump @commitlint/cli from 16.0.1 to 16.1.0 (#591) ([a46f0ab](https://github.com/readmeio/oas/commit/a46f0ab)), closes [#591](https://github.com/readmeio/oas/issues/591)
package/dist/index.js CHANGED
@@ -12,7 +12,11 @@ var __assign = (this && this.__assign) || function () {
12
12
  };
13
13
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
14
  if (k2 === undefined) k2 = k;
15
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
16
20
  }) : (function(o, m, k, k2) {
17
21
  if (k2 === undefined) k2 = k;
18
22
  o[k2] = m[k];
@@ -667,8 +671,10 @@ var Oas = /** @class */ (function () {
667
671
  * Dereference the current OAS definition so it can be parsed free of worries of `$ref` schemas and circular
668
672
  * structures.
669
673
  *
674
+ * @param opts
670
675
  */
671
- Oas.prototype.dereference = function () {
676
+ Oas.prototype.dereference = function (opts) {
677
+ if (opts === void 0) { opts = { preserveRefAsJSONSchemaTitle: false }; }
672
678
  return __awaiter(this, void 0, void 0, function () {
673
679
  var _a, api, promises;
674
680
  var _this = this;
@@ -690,6 +696,12 @@ var Oas = /** @class */ (function () {
690
696
  // dereferencing happens below those names will be preserved.
691
697
  if (api && api.components && api.components.schemas && typeof api.components.schemas === 'object') {
692
698
  Object.keys(api.components.schemas).forEach(function (schemaName) {
699
+ if (opts.preserveRefAsJSONSchemaTitle) {
700
+ // This may result in some data loss if there's already a `title` present, but in the case
701
+ // where we want to generate code for the API definition (see http://npm.im/api), we'd
702
+ // prefer to retain original reference name as a title for any generated types.
703
+ api.components.schemas[schemaName].title = schemaName;
704
+ }
693
705
  api.components.schemas[schemaName]['x-readme-ref-name'] = schemaName;
694
706
  });
695
707
  }
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -12,7 +12,11 @@ var __assign = (this && this.__assign) || function () {
12
12
  };
13
13
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
14
  if (k2 === undefined) k2 = k;
15
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
16
20
  }) : (function(o, m, k, k2) {
17
21
  if (k2 === undefined) k2 = k;
18
22
  o[k2] = m[k];
@@ -12,7 +12,11 @@ var __assign = (this && this.__assign) || function () {
12
12
  };
13
13
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
14
  if (k2 === undefined) k2 = k;
15
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
16
20
  }) : (function(o, m, k, k2) {
17
21
  if (k2 === undefined) k2 = k;
18
22
  o[k2] = m[k];
package/dist/operation.js CHANGED
@@ -16,7 +16,11 @@ var __extends = (this && this.__extends) || (function () {
16
16
  })();
17
17
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
18
  if (k2 === undefined) k2 = k;
19
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
19
+ var desc = Object.getOwnPropertyDescriptor(m, k);
20
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
+ desc = { enumerable: true, get: function() { return m[k]; } };
22
+ }
23
+ Object.defineProperty(o, k2, desc);
20
24
  }) : (function(o, m, k, k2) {
21
25
  if (k2 === undefined) k2 = k;
22
26
  o[k2] = m[k];
@@ -282,20 +286,33 @@ var Operation = /** @class */ (function () {
282
286
  return 'operationId' in this.schema;
283
287
  };
284
288
  /**
285
- * Get an `operationId` for this operation. If one is not present (it's not required by the spec!) a hash of the path
286
- * and method will be returned instead.
289
+ * Get an `operationId` for this operation. If one is not present (it's not required by the spec!)
290
+ * a hash of the path and method will be returned instead.
287
291
  *
292
+ * @param opts
293
+ * @param opts.camelCase Generate a JS method-friendly operation ID when one isn't present.
288
294
  */
289
- Operation.prototype.getOperationId = function () {
295
+ Operation.prototype.getOperationId = function (opts) {
290
296
  if ('operationId' in this.schema) {
291
297
  return this.schema.operationId;
292
298
  }
293
- var url = this.path
299
+ var method = this.method.toLowerCase();
300
+ var operationId = this.path
294
301
  .replace(/[^a-zA-Z0-9]/g, '-') // Remove weird characters
295
302
  .replace(/^-|-$/g, '') // Don't start or end with -
296
303
  .replace(/--+/g, '-') // Remove double --'s
297
304
  .toLowerCase();
298
- return "".concat(this.method.toLowerCase(), "_").concat(url);
305
+ if (opts === null || opts === void 0 ? void 0 : opts.camelCase) {
306
+ operationId = operationId.replace(/[^a-zA-Z0-9]+(.)/g, function (_, chr) { return chr.toUpperCase(); });
307
+ // If the generated operationId already starts with the method (eg. `getPets`) we don't want
308
+ // to double it up into `getGetPets`.
309
+ if (operationId.startsWith(method)) {
310
+ return operationId;
311
+ }
312
+ operationId = operationId.charAt(0).toUpperCase() + operationId.slice(1);
313
+ return "".concat(method).concat(operationId);
314
+ }
315
+ return "".concat(method, "_").concat(operationId);
299
316
  };
300
317
  /**
301
318
  * Return an array of all tags, and their metadata, that exist on this operation.
@@ -354,6 +371,13 @@ var Operation = /** @class */ (function () {
354
371
  }
355
372
  return parameters;
356
373
  };
374
+ /**
375
+ * Determine if this operation has any required parameters.
376
+ *
377
+ */
378
+ Operation.prototype.hasRequiredParameters = function () {
379
+ return this.getParameters().some(function (param) { return 'required' in param && param.required; });
380
+ };
357
381
  /**
358
382
  * Convert the operation into an array of JSON Schema schemas for each available type of parameter available on the
359
383
  * operation.
@@ -361,7 +385,11 @@ var Operation = /** @class */ (function () {
361
385
  * @param globalDefaults Contains an object of user defined schema defaults.
362
386
  */
363
387
  Operation.prototype.getParametersAsJsonSchema = function (globalDefaults) {
364
- return (0, get_parameters_as_json_schema_1["default"])(this, this.api, globalDefaults);
388
+ if (this.parameterJsonSchema) {
389
+ return this.parameterJsonSchema;
390
+ }
391
+ this.parameterJsonSchema = (0, get_parameters_as_json_schema_1["default"])(this, this.api, globalDefaults);
392
+ return this.parameterJsonSchema;
365
393
  };
366
394
  /**
367
395
  * Get a single response for this status code, formatted as JSON schema.
@@ -403,6 +431,33 @@ var Operation = /** @class */ (function () {
403
431
  }
404
432
  return Object.keys(requestBody.content);
405
433
  };
434
+ /**
435
+ * Determine if this operation has a required request body.
436
+ *
437
+ */
438
+ Operation.prototype.hasRequiredRequestBody = function () {
439
+ if (!this.hasRequestBody()) {
440
+ return false;
441
+ }
442
+ var requestBody = this.schema.requestBody;
443
+ if (RMOAS.isRef(requestBody)) {
444
+ return false;
445
+ }
446
+ if (requestBody.required) {
447
+ return true;
448
+ }
449
+ // The OpenAPI spec isn't clear on the differentiation between schema `required` and
450
+ // `requestBody.required` because you can have required top-level schema properties but a
451
+ // non-required requestBody that negates each other.
452
+ //
453
+ // To kind of work ourselves around this and present a better QOL for this accessor, if at this
454
+ // final point where we don't have a required request body, but the underlying Media Type Object
455
+ // schema says that it has required properties then we should ultimately recognize that this
456
+ // request body is required -- even as the request body description says otherwise.
457
+ return !!this.getParametersAsJsonSchema()
458
+ .filter(function (js) { return ['body', 'formData'].includes(js.type); })
459
+ .find(function (js) { return js.schema && Array.isArray(js.schema.required) && js.schema.required.length; });
460
+ };
406
461
  /**
407
462
  * Retrieve a specific request body content schema off this operation.
408
463
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oas",
3
- "version": "17.7.2",
3
+ "version": "17.8.1",
4
4
  "description": "Working with OpenAPI definitions is hard. This makes it easier.",
5
5
  "license": "MIT",
6
6
  "author": "ReadMe <support@readme.io> (https://readme.com)",
@@ -62,12 +62,12 @@
62
62
  "oas-normalize": "^5.1.1",
63
63
  "openapi-types": "^10.0.0",
64
64
  "path-to-regexp": "^6.2.0",
65
- "swagger-inline": "^5.0.2"
65
+ "swagger-inline": "^5.1.0"
66
66
  },
67
67
  "devDependencies": {
68
68
  "@commitlint/cli": "^16.0.1",
69
69
  "@commitlint/config-conventional": "^16.0.0",
70
- "@readme/eslint-config": "^8.1.2",
70
+ "@readme/eslint-config": "^8.4.1",
71
71
  "@readme/oas-examples": "^4.3.2",
72
72
  "@types/jest": "^27.0.2",
73
73
  "@types/json-schema-merge-allof": "^0.6.1",