oas 17.7.2 → 17.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/@types/index.d.ts 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
  *
@@ -40,8 +40,8 @@ export default class Operation {
40
40
  * Flattened out arrays of both request and response headers that are utilized on this operation.
41
41
  */
42
42
  headers: {
43
- request: Array<string>;
44
- response: Array<string>;
43
+ request: string[];
44
+ response: string[];
45
45
  };
46
46
  constructor(api: RMOAS.OASDocument, path: string, method: RMOAS.HttpMethods, operation: RMOAS.OperationObject);
47
47
  getSummary(): string;
@@ -56,7 +56,7 @@ export default class Operation {
56
56
  * level, the securities for the entire API definition are returned (with an empty array as a final fallback).
57
57
  *
58
58
  */
59
- getSecurity(): Array<RMOAS.SecurityRequirementObject>;
59
+ getSecurity(): RMOAS.SecurityRequirementObject[];
60
60
  /**
61
61
  * Retrieve a collection of grouped security schemes. The inner array determines and-grouped security schemes, the
62
62
  * outer array determines or-groups.
@@ -67,16 +67,16 @@ export default class Operation {
67
67
  * @param filterInvalid Optional flag that, when set to `true`, filters out invalid/nonexistent security schemes,
68
68
  * rather than returning `false`.
69
69
  */
70
- getSecurityWithTypes(filterInvalid?: boolean): Array<false | Array<false | {
70
+ getSecurityWithTypes(filterInvalid?: boolean): (false | (false | {
71
71
  security: RMOAS.KeyedSecuritySchemeObject;
72
72
  type: SecurityType;
73
- }>>;
73
+ })[])[];
74
74
  /**
75
75
  * Retrieve an object where the keys are unique scheme types, and the values are arrays containing each security
76
76
  * scheme of that type.
77
77
  *
78
78
  */
79
- prepareSecurity(): Record<SecurityType, Array<RMOAS.KeyedSecuritySchemeObject>>;
79
+ prepareSecurity(): Record<SecurityType, RMOAS.KeyedSecuritySchemeObject[]>;
80
80
  getHeaders(): Operation['headers'];
81
81
  /**
82
82
  * Determine if the operation has an operation present in its schema.
@@ -93,7 +93,7 @@ export default class Operation {
93
93
  * Return an array of all tags, and their metadata, that exist on this operation.
94
94
  *
95
95
  */
96
- getTags(): Array<RMOAS.TagObject>;
96
+ getTags(): RMOAS.TagObject[];
97
97
  /**
98
98
  * Return is the operation is flagged as `deprecated` or not.
99
99
  *
@@ -108,7 +108,7 @@ export default class Operation {
108
108
  * Return the parameters (non-request body) on the operation.
109
109
  *
110
110
  */
111
- getParameters(): Array<RMOAS.ParameterObject>;
111
+ getParameters(): RMOAS.ParameterObject[];
112
112
  /**
113
113
  * Convert the operation into an array of JSON Schema schemas for each available type of parameter available on the
114
114
  * operation.
@@ -131,7 +131,7 @@ export default class Operation {
131
131
  * Get an array of all valid response status codes for this operation.
132
132
  *
133
133
  */
134
- getResponseStatusCodes(): Array<string>;
134
+ getResponseStatusCodes(): string[];
135
135
  /**
136
136
  * Determine if the operation has any request bodies.
137
137
  *
@@ -191,7 +191,7 @@ export default class Operation {
191
191
  * Retrieve an array of operations created from each callback.
192
192
  *
193
193
  */
194
- getCallbacks(): false | Array<false | Callback>;
194
+ getCallbacks(): false | (false | Callback)[];
195
195
  /**
196
196
  * Retrieve an array of callback examples that this operation has.
197
197
  *
@@ -233,7 +233,7 @@ export declare class Callback extends Operation {
233
233
  getIdentifier(): string;
234
234
  getSummary(): string;
235
235
  getDescription(): string;
236
- getParameters(): Array<RMOAS.ParameterObject>;
236
+ getParameters(): RMOAS.ParameterObject[];
237
237
  }
238
238
  export declare class Webhook extends Operation {
239
239
  }
@@ -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,10 @@
1
+ ## <small>17.7.3 (2022-02-15)</small>
2
+
3
+ * 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)
4
+ * 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)
5
+
6
+
7
+
1
8
  ## <small>17.7.2 (2022-02-02)</small>
2
9
 
3
10
  * 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
@@ -667,8 +667,10 @@ var Oas = /** @class */ (function () {
667
667
  * Dereference the current OAS definition so it can be parsed free of worries of `$ref` schemas and circular
668
668
  * structures.
669
669
  *
670
+ * @param opts
670
671
  */
671
- Oas.prototype.dereference = function () {
672
+ Oas.prototype.dereference = function (opts) {
673
+ if (opts === void 0) { opts = { preserveRefAsJSONSchemaTitle: false }; }
672
674
  return __awaiter(this, void 0, void 0, function () {
673
675
  var _a, api, promises;
674
676
  var _this = this;
@@ -690,6 +692,12 @@ var Oas = /** @class */ (function () {
690
692
  // dereferencing happens below those names will be preserved.
691
693
  if (api && api.components && api.components.schemas && typeof api.components.schemas === 'object') {
692
694
  Object.keys(api.components.schemas).forEach(function (schemaName) {
695
+ if (opts.preserveRefAsJSONSchemaTitle) {
696
+ // This may result in some data loss if there's already a `title` present, but in the case
697
+ // where we want to generate code for the API definition (see http://npm.im/api), we'd
698
+ // prefer to retain original reference name as a title for any generated types.
699
+ api.components.schemas[schemaName].title = schemaName;
700
+ }
693
701
  api.components.schemas[schemaName]['x-readme-ref-name'] = schemaName;
694
702
  });
695
703
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oas",
3
- "version": "17.7.2",
3
+ "version": "17.7.3",
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)",
@@ -67,7 +67,7 @@
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",
package/src/index.ts CHANGED
@@ -20,9 +20,9 @@ type PathMatch = {
20
20
  operation: RMOAS.PathsObject;
21
21
  match?: MatchResult;
22
22
  };
23
- type PathMatches = Array<PathMatch>;
23
+ type PathMatches = PathMatch[];
24
24
 
25
- type Variables = Record<string, string | number | Array<{ default?: string | number }> | { default?: string | number }>;
25
+ type Variables = Record<string, string | number | { default?: string | number }[] | { default?: string | number }>;
26
26
 
27
27
  function ensureProtocol(url: string) {
28
28
  // Add protocol to urls starting with // e.g. //example.com
@@ -173,14 +173,14 @@ function filterPathMethods(pathMatches: PathMatches, targetMethod: RMOAS.HttpMet
173
173
 
174
174
  return false;
175
175
  })
176
- .filter(Boolean) as Array<{ url: PathMatch['url']; operation: RMOAS.OperationObject }>;
176
+ .filter(Boolean) as { url: PathMatch['url']; operation: RMOAS.OperationObject }[];
177
177
  }
178
178
 
179
179
  /**
180
180
  * @param pathMatches URL and PathsObject matches to narrow down to find a target path.
181
181
  * @returns An object containing matches that were discovered in the API definition.
182
182
  */
183
- function findTargetPath(pathMatches: Array<{ url: PathMatch['url']; operation: RMOAS.PathsObject }>) {
183
+ function findTargetPath(pathMatches: { url: PathMatch['url']; operation: RMOAS.PathsObject }[]) {
184
184
  let minCount = Object.keys(pathMatches[0].url.slugs).length;
185
185
  let operation;
186
186
 
@@ -214,10 +214,10 @@ export default class Oas {
214
214
  *
215
215
  * @todo These are always `Promise.resolve` and `Promise.reject`. Make these types more specific than `any`.
216
216
  */
217
- protected promises: Array<{
217
+ protected promises: {
218
218
  resolve: any;
219
219
  reject: any;
220
- }>;
220
+ }[];
221
221
 
222
222
  /**
223
223
  * Internal storage array that the library utilizes to keep track of its `dereferencing` state so it doesn't initiate
@@ -504,7 +504,7 @@ export default class Oas {
504
504
  pathName: url.split(new RegExp(rgx)).slice(-1).pop(),
505
505
  };
506
506
  })
507
- .filter(Boolean) as Array<{ matchedServer: RMOAS.ServerObject; pathName: string }>;
507
+ .filter(Boolean) as { matchedServer: RMOAS.ServerObject; pathName: string }[];
508
508
 
509
509
  if (!matchedServerAndPath.length) {
510
510
  return undefined;
@@ -548,10 +548,10 @@ export default class Oas {
548
548
  return undefined;
549
549
  }
550
550
 
551
- const matches = filterPathMethods(annotatedPaths, method) as Array<{
551
+ const matches = filterPathMethods(annotatedPaths, method) as {
552
552
  url: PathMatch['url'];
553
553
  operation: RMOAS.PathsObject; // @fixme this should actually be an `OperationObject`.
554
- }>;
554
+ }[];
555
555
  if (!matches.length) return undefined;
556
556
  return findTargetPath(matches);
557
557
  }
@@ -704,8 +704,9 @@ export default class Oas {
704
704
  * Dereference the current OAS definition so it can be parsed free of worries of `$ref` schemas and circular
705
705
  * structures.
706
706
  *
707
+ * @param opts
707
708
  */
708
- async dereference() {
709
+ async dereference(opts = { preserveRefAsJSONSchemaTitle: false }) {
709
710
  if (this.dereferencing.complete) {
710
711
  return new Promise(resolve => {
711
712
  resolve(true);
@@ -727,6 +728,13 @@ export default class Oas {
727
728
  // dereferencing happens below those names will be preserved.
728
729
  if (api && api.components && api.components.schemas && typeof api.components.schemas === 'object') {
729
730
  Object.keys(api.components.schemas).forEach(schemaName => {
731
+ if (opts.preserveRefAsJSONSchemaTitle) {
732
+ // This may result in some data loss if there's already a `title` present, but in the case
733
+ // where we want to generate code for the API definition (see http://npm.im/api), we'd
734
+ // prefer to retain original reference name as a title for any generated types.
735
+ (api.components.schemas[schemaName] as RMOAS.SchemaObject).title = schemaName;
736
+ }
737
+
730
738
  (api.components.schemas[schemaName] as RMOAS.SchemaObject)['x-readme-ref-name'] = schemaName;
731
739
  });
732
740
  }
@@ -16,13 +16,7 @@ import findSchemaDefinition from './find-schema-definition';
16
16
  */
17
17
  export default function getSchema(
18
18
  operation: RMOAS.OperationObject,
19
- api?:
20
- | RMOAS.OASDocument
21
- | {
22
- [schemaType: string]: {
23
- [key: string]: RMOAS.SchemaObject;
24
- };
25
- }
19
+ api?: RMOAS.OASDocument | Record<string /* schemaType */, Record<string, RMOAS.SchemaObject>>
26
20
  ): {
27
21
  type: string;
28
22
  schema: any; // @fixme give this a better type
@@ -1,4 +1,4 @@
1
- function matchesMediaType(types: Array<string>, mediaType: string): boolean {
1
+ function matchesMediaType(types: string[], mediaType: string): boolean {
2
2
  return types.some(function (type) {
3
3
  return mediaType.indexOf(type) > -1;
4
4
  });
@@ -11,7 +11,7 @@ import mergeJSONSchemaAllOf from 'json-schema-merge-allof';
11
11
  *
12
12
  * @see {@link https://github.com/openapi-contrib/openapi-schema-to-json-schema/blob/master/index.js#L23-L27}
13
13
  */
14
- const UNSUPPORTED_SCHEMA_PROPS: Array<'nullable' | 'xml' | 'externalDocs' | 'example'> = [
14
+ const UNSUPPORTED_SCHEMA_PROPS: ('nullable' | 'xml' | 'externalDocs' | 'example')[] = [
15
15
  'nullable',
16
16
  // 'discriminator',
17
17
  // 'readOnly',
@@ -22,13 +22,11 @@ const UNSUPPORTED_SCHEMA_PROPS: Array<'nullable' | 'xml' | 'externalDocs' | 'exa
22
22
  // 'deprecated',
23
23
  ];
24
24
 
25
- type PrevSchemasType = Array<RMOAS.SchemaObject>;
25
+ type PrevSchemasType = RMOAS.SchemaObject[];
26
26
 
27
27
  export type toJsonSchemaOptions = {
28
28
  currentLocation?: string;
29
- globalDefaults?: {
30
- [key: string]: unknown;
31
- };
29
+ globalDefaults?: Record<string, unknown>;
32
30
  isPolymorphicAllOfChild?: boolean;
33
31
  prevSchemas?: PrevSchemasType;
34
32
  refLogger?: (ref: string) => void;
@@ -252,16 +250,16 @@ export default function toJSONSchema(
252
250
  resolvers: {
253
251
  // JSON Schema ony supports examples with the `examples` property, since we're ingesting OpenAPI
254
252
  // definitions we need to add a custom resolver for its `example` property.
255
- example: (obj: Array<unknown>) => obj[0],
253
+ example: (obj: unknown[]) => obj[0],
256
254
 
257
255
  // JSON Schema has no support for `format` on anything other than `string`, but since OpenAPI has it on
258
256
  // `integer` and `number` we need to add a custom resolver here so we can still merge schemas that may
259
257
  // have those.
260
- format: (obj: Array<string>) => obj[0],
258
+ format: (obj: string[]) => obj[0],
261
259
 
262
260
  // Since JSON Schema obviously doesn't know about our vendor extension we need to tell the library to
263
261
  // essentially ignore and pass it along.
264
- 'x-readme-ref-name': (obj: Array<string>) => obj[0],
262
+ 'x-readme-ref-name': (obj: string[]) => obj[0],
265
263
  } as unknown,
266
264
  }) as RMOAS.SchemaObject;
267
265
  } catch (e) {
@@ -353,7 +351,7 @@ export default function toJSONSchema(
353
351
  } else if ('examples' in schema) {
354
352
  let reshapedExamples = false;
355
353
  if (typeof schema.examples === 'object' && !Array.isArray(schema.examples)) {
356
- const examples: Array<unknown> = [];
354
+ const examples: unknown[] = [];
357
355
  Object.keys(schema.examples).forEach(name => {
358
356
  const example = schema.examples[name as unknown as number];
359
357
  if ('$ref' in example) {
@@ -544,7 +542,7 @@ export default function toJSONSchema(
544
542
  // Remove unsupported JSON Schema props.
545
543
  for (let i = 0; i < UNSUPPORTED_SCHEMA_PROPS.length; i += 1) {
546
544
  // Using the as here because the purpose is to delete keys we don't expect, so of course the typing won't work
547
- delete (schema as { [key: string]: unknown })[UNSUPPORTED_SCHEMA_PROPS[i]];
545
+ delete (schema as Record<string, unknown>)[UNSUPPORTED_SCHEMA_PROPS[i]];
548
546
  }
549
547
 
550
548
  return schema;
@@ -1,12 +1,12 @@
1
1
  import type * as RMOAS from '../rmoas.types';
2
2
  import getResponseExamples from './get-response-examples';
3
3
 
4
- export type CallbackExamples = Array<{
4
+ export type CallbackExamples = {
5
5
  identifier: string;
6
6
  expression: string;
7
7
  method: string;
8
8
  example: unknown;
9
- }>;
9
+ }[];
10
10
 
11
11
  /**
12
12
  * With an OpenAPI Operation Object return back a collection of examples for any callbacks that may be present.
@@ -21,7 +21,7 @@ export type SchemaWrapper = {
21
21
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#parameterObject}
22
22
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameterObject}
23
23
  */
24
- export const types: { [key: keyof RMOAS.OASDocument]: string } = {
24
+ export const types: Record<keyof RMOAS.OASDocument, string> = {
25
25
  path: 'Path Params',
26
26
  query: 'Query Params',
27
27
  body: 'Body Params',
@@ -74,10 +74,10 @@ export default function getParametersAsJsonSchema(operation: Operation, api: OAS
74
74
  // Clone the original schema so this doesn't interfere with it
75
75
  const deprecatedBody = cloneObject(schema);
76
76
  // Booleans are not valid for required in draft 4, 7 or 2020. Not sure why the typing thinks they are.
77
- const requiredParams = (schema.required || []) as Array<string>;
77
+ const requiredParams = (schema.required || []) as string[];
78
78
 
79
79
  // Find all top-level deprecated properties from the schema - required and readOnly params are excluded
80
- const allDeprecatedProps: { [key: string]: SchemaObject } = {};
80
+ const allDeprecatedProps: Record<string, SchemaObject> = {};
81
81
 
82
82
  Object.keys(deprecatedBody.properties).forEach(key => {
83
83
  const deprecatedProp = deprecatedBody.properties[key] as SchemaObject;
@@ -87,7 +87,7 @@ export default function getParametersAsJsonSchema(operation: Operation, api: OAS
87
87
  });
88
88
 
89
89
  // We know this is the right type. todo: don't use as
90
- (deprecatedBody.properties as { [key: string]: SchemaObject }) = allDeprecatedProps;
90
+ (deprecatedBody.properties as Record<string, SchemaObject>) = allDeprecatedProps;
91
91
  const deprecatedSchema = toJSONSchema(deprecatedBody, { globalDefaults, prevSchemas: [], refLogger });
92
92
 
93
93
  // Check if the schema wasn't created or there's no deprecated properties
@@ -128,7 +128,7 @@ export default function getParametersAsJsonSchema(operation: Operation, api: OAS
128
128
  return null;
129
129
  }
130
130
 
131
- const prevSchemas = [] as Array<RMOAS.SchemaObject>;
131
+ const prevSchemas: RMOAS.SchemaObject[] = [];
132
132
  if ('example' in mediaTypeObject) {
133
133
  prevSchemas.push({ example: mediaTypeObject.example });
134
134
  } else if ('examples' in mediaTypeObject) {
@@ -186,11 +186,11 @@ export default function getParametersAsJsonSchema(operation: Operation, api: OAS
186
186
  return components;
187
187
  }
188
188
 
189
- function transformParameters(): Array<SchemaWrapper> {
189
+ function transformParameters(): SchemaWrapper[] {
190
190
  const operationParams = operation.getParameters();
191
191
 
192
192
  return Object.keys(types).map(type => {
193
- const required: Array<string> = [];
193
+ const required: string[] = [];
194
194
 
195
195
  // This `as` actually *could* be a ref, but we don't want refs to pass through here, so `.in` will never match `type`
196
196
  const parameters = operationParams.filter(param => (param as RMOAS.ParameterObject).in === type);
@@ -198,7 +198,7 @@ export default function getParametersAsJsonSchema(operation: Operation, api: OAS
198
198
  return null;
199
199
  }
200
200
 
201
- const properties = parameters.reduce((prev: { [key: string]: SchemaObject }, current: RMOAS.ParameterObject) => {
201
+ const properties = parameters.reduce((prev: Record<string, SchemaObject>, current: RMOAS.ParameterObject) => {
202
202
  let schema: SchemaObject = {};
203
203
  if ('schema' in current) {
204
204
  const currentSchema: SchemaObject = current.schema ? cloneObject(current.schema) : {};
@@ -210,7 +210,7 @@ export default function getParametersAsJsonSchema(operation: Operation, api: OAS
210
210
  } else if (current.examples) {
211
211
  // `examples` isn't actually supported here in OAS 3.0, but we might as well support it because `examples` is
212
212
  // JSON Schema and that's fully supported in OAS 3.1.
213
- currentSchema.examples = current.examples as unknown as Array<unknown>;
213
+ currentSchema.examples = current.examples as unknown as unknown[];
214
214
  }
215
215
 
216
216
  if (current.deprecated) currentSchema.deprecated = current.deprecated;
@@ -254,7 +254,7 @@ export default function getParametersAsJsonSchema(operation: Operation, api: OAS
254
254
  } else if (current.examples) {
255
255
  // `examples` isn't actually supported here in OAS 3.0, but we might as well support it because `examples` is
256
256
  // JSON Schema and that's fully supported in OAS 3.1.
257
- currentSchema.examples = current.examples as unknown as Array<unknown>;
257
+ currentSchema.examples = current.examples as unknown as unknown[];
258
258
  }
259
259
 
260
260
  if (current.deprecated) currentSchema.deprecated = current.deprecated;
@@ -290,7 +290,7 @@ export default function getParametersAsJsonSchema(operation: Operation, api: OAS
290
290
  // This typing is technically WRONG :( but it's the best we can do for now.
291
291
  const schema: OpenAPIV3_1.SchemaObject = {
292
292
  type: 'object',
293
- properties: properties as { [key: string]: OpenAPIV3_1.SchemaObject },
293
+ properties: properties as Record<string, OpenAPIV3_1.SchemaObject>,
294
294
  required,
295
295
  };
296
296
 
@@ -1,10 +1,10 @@
1
1
  import type * as RMOAS from '../rmoas.types';
2
2
  import getMediaTypeExamples from '../lib/get-mediatype-examples';
3
3
 
4
- export type RequestBodyExamples = Array<{
4
+ export type RequestBodyExamples = {
5
5
  mediaType: string;
6
6
  examples: any;
7
- }>;
7
+ }[];
8
8
 
9
9
  /**
10
10
  * Retrieve a collection of request body examples, keyed by their media type.
@@ -114,7 +114,7 @@ export default function getResponseAsJsonSchema(operation: Operation, api: OASDo
114
114
  const foundSchema = getPreferredSchema((response as ResponseObject).content);
115
115
  if (foundSchema) {
116
116
  const schemaWrapper: {
117
- type: string | Array<string>;
117
+ type: string | string[];
118
118
  schema: SchemaObject;
119
119
  label: string;
120
120
  description?: string;
@@ -4,10 +4,10 @@ import type { MediaTypeExample } from '../lib/get-mediatype-examples';
4
4
  import { isRef } from '../rmoas.types';
5
5
  import getMediaTypeExamples from '../lib/get-mediatype-examples';
6
6
 
7
- export type ResponseExamples = Array<{
7
+ export type ResponseExamples = {
8
8
  status: string;
9
9
  mediaTypes: Record<string, RMOAS.MediaTypeObject>;
10
- }>;
10
+ }[];
11
11
 
12
12
  /**
13
13
  * Retrieve a collection of response examples keyed, by their media type.
@@ -25,7 +25,7 @@ export default function getResponseExamples(operation: RMOAS.OperationObject) {
25
25
  return false;
26
26
  }
27
27
 
28
- const mediaTypes: Record<string, Array<MediaTypeExample>> = {};
28
+ const mediaTypes: Record<string, MediaTypeExample[]> = {};
29
29
  (response.content ? Object.keys(response.content) : []).forEach(mediaType => {
30
30
  if (!mediaType) return;
31
31
 
package/src/operation.ts CHANGED
@@ -61,8 +61,8 @@ export default class Operation {
61
61
  * Flattened out arrays of both request and response headers that are utilized on this operation.
62
62
  */
63
63
  headers: {
64
- request: Array<string>;
65
- response: Array<string>;
64
+ request: string[];
65
+ response: string[];
66
66
  };
67
67
 
68
68
  constructor(api: RMOAS.OASDocument, path: string, method: RMOAS.HttpMethods, operation: RMOAS.OperationObject) {
@@ -98,7 +98,7 @@ export default class Operation {
98
98
  return this.contentType;
99
99
  }
100
100
 
101
- let types: Array<string> = [];
101
+ let types: string[] = [];
102
102
  if (this.schema.requestBody) {
103
103
  if ('$ref' in this.schema.requestBody) {
104
104
  this.schema.requestBody = findSchemaDefinition(this.schema.requestBody.$ref, this.api);
@@ -145,7 +145,7 @@ export default class Operation {
145
145
  * level, the securities for the entire API definition are returned (with an empty array as a final fallback).
146
146
  *
147
147
  */
148
- getSecurity(): Array<RMOAS.SecurityRequirementObject> {
148
+ getSecurity(): RMOAS.SecurityRequirementObject[] {
149
149
  if (!this.api?.components?.securitySchemes) {
150
150
  return [];
151
151
  }
@@ -165,7 +165,7 @@ export default class Operation {
165
165
  */
166
166
  getSecurityWithTypes(
167
167
  filterInvalid = false
168
- ): Array<false | Array<false | { security: RMOAS.KeyedSecuritySchemeObject; type: SecurityType }>> {
168
+ ): (false | (false | { security: RMOAS.KeyedSecuritySchemeObject; type: SecurityType })[])[] {
169
169
  const securityRequirements = this.getSecurity();
170
170
 
171
171
  return securityRequirements.map(requirement => {
@@ -220,7 +220,7 @@ export default class Operation {
220
220
  * scheme of that type.
221
221
  *
222
222
  */
223
- prepareSecurity(): Record<SecurityType, Array<RMOAS.KeyedSecuritySchemeObject>> {
223
+ prepareSecurity(): Record<SecurityType, RMOAS.KeyedSecuritySchemeObject[]> {
224
224
  const securitiesWithTypes = this.getSecurityWithTypes();
225
225
 
226
226
  return securitiesWithTypes.reduce((prev, securities) => {
@@ -239,7 +239,7 @@ export default class Operation {
239
239
  });
240
240
 
241
241
  return prev;
242
- }, {} as Record<SecurityType, Array<RMOAS.KeyedSecuritySchemeObject>>);
242
+ }, {} as Record<SecurityType, RMOAS.KeyedSecuritySchemeObject[]>);
243
243
  }
244
244
 
245
245
  getHeaders(): Operation['headers'] {
@@ -250,7 +250,7 @@ export default class Operation {
250
250
 
251
251
  const security = this.prepareSecurity();
252
252
  if (security.Header) {
253
- this.headers.request = (security.Header as Array<OpenAPIV3_1.ApiKeySecurityScheme>).map(h => {
253
+ this.headers.request = (security.Header as OpenAPIV3_1.ApiKeySecurityScheme[]).map(h => {
254
254
  return h.name;
255
255
  });
256
256
  }
@@ -266,7 +266,7 @@ export default class Operation {
266
266
  if (this.schema.parameters) {
267
267
  this.headers.request = this.headers.request.concat(
268
268
  // Remove the reference object because we will have already dereferenced
269
- (this.schema.parameters as Array<OpenAPIV3.ParameterObject> | Array<OpenAPIV3_1.ParameterObject>)
269
+ (this.schema.parameters as OpenAPIV3.ParameterObject[] | OpenAPIV3_1.ParameterObject[])
270
270
  .map(p => {
271
271
  if (p.in && p.in === 'header') return p.name;
272
272
  return undefined;
@@ -345,7 +345,7 @@ export default class Operation {
345
345
  * Return an array of all tags, and their metadata, that exist on this operation.
346
346
  *
347
347
  */
348
- getTags(): Array<RMOAS.TagObject> {
348
+ getTags(): RMOAS.TagObject[] {
349
349
  if (!('tags' in this.schema)) {
350
350
  return [];
351
351
  }
@@ -359,7 +359,7 @@ export default class Operation {
359
359
 
360
360
  const oasTags = Object.fromEntries(oasTagMap);
361
361
 
362
- const tags: Array<RMOAS.TagObject> = [];
362
+ const tags: RMOAS.TagObject[] = [];
363
363
  if (Array.isArray(this.schema.tags)) {
364
364
  this.schema.tags.forEach(tag => {
365
365
  if (tag in oasTags) {
@@ -395,9 +395,9 @@ export default class Operation {
395
395
  * Return the parameters (non-request body) on the operation.
396
396
  *
397
397
  */
398
- getParameters(): Array<RMOAS.ParameterObject> {
399
- let parameters = (this.schema?.parameters || []) as Array<RMOAS.ParameterObject>;
400
- const commonParams = (this.api?.paths?.[this.path]?.parameters || []) as Array<RMOAS.ParameterObject>;
398
+ getParameters(): RMOAS.ParameterObject[] {
399
+ let parameters = (this.schema?.parameters || []) as RMOAS.ParameterObject[];
400
+ const commonParams = (this.api?.paths?.[this.path]?.parameters || []) as RMOAS.ParameterObject[];
401
401
  if (commonParams.length) {
402
402
  parameters = parameters.concat(dedupeCommonParameters(parameters, commonParams) || []);
403
403
  }
@@ -428,7 +428,7 @@ export default class Operation {
428
428
  * Get an array of all valid response status codes for this operation.
429
429
  *
430
430
  */
431
- getResponseStatusCodes(): Array<string> {
431
+ getResponseStatusCodes(): string[] {
432
432
  return this.schema.responses ? Object.keys(this.schema.responses) : [];
433
433
  }
434
434
 
@@ -603,8 +603,8 @@ export default class Operation {
603
603
  * Retrieve an array of operations created from each callback.
604
604
  *
605
605
  */
606
- getCallbacks(): false | Array<false | Callback> {
607
- const callbackOperations: Array<false | Callback> = [];
606
+ getCallbacks(): false | (false | Callback)[] {
607
+ const callbackOperations: (false | Callback)[] = [];
608
608
  if (!this.hasCallbacks()) return false;
609
609
 
610
610
  Object.keys(this.schema.callbacks).forEach(callback => {
@@ -715,9 +715,9 @@ export class Callback extends Operation {
715
715
  return this.schema?.description ? this.schema.description.trim() : undefined;
716
716
  }
717
717
 
718
- getParameters(): Array<RMOAS.ParameterObject> {
719
- let parameters = (this.schema?.parameters || []) as Array<RMOAS.ParameterObject>;
720
- const commonParams = (this.parentSchema.parameters || []) as Array<RMOAS.ParameterObject>;
718
+ getParameters(): RMOAS.ParameterObject[] {
719
+ let parameters = (this.schema?.parameters || []) as RMOAS.ParameterObject[];
720
+ const commonParams = (this.parentSchema.parameters || []) as RMOAS.ParameterObject[];
721
721
  if (commonParams.length) {
722
722
  parameters = parameters.concat(dedupeCommonParameters(parameters, commonParams) || []);
723
723
  }
@@ -21,12 +21,12 @@ export function isOAS31(check: OpenAPIV3.Document | OpenAPIV3_1.Document): check
21
21
 
22
22
  export interface User {
23
23
  [key: string]: unknown;
24
- keys?: Array<{
24
+ keys?: {
25
25
  name: string | number;
26
26
  user?: string | number;
27
27
  pass?: string | number;
28
28
  [key: string]: unknown;
29
- }>;
29
+ }[];
30
30
  }
31
31
 
32
32
  export type HttpMethods =
@@ -42,9 +42,9 @@ export type HttpMethods =
42
42
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#oasObject}
43
43
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#oasObject}
44
44
  */
45
- export type OASDocument = (OpenAPIV3.Document | OpenAPIV3_1.Document) & {
46
- [extension: string]: unknown;
47
- };
45
+ export type OASDocument = (OpenAPIV3.Document | OpenAPIV3_1.Document) &
46
+ // `x-*` extensions
47
+ Record<string, unknown>;
48
48
 
49
49
  /**
50
50
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#serverObject}
@@ -57,12 +57,10 @@ export type ServerObject = OpenAPIV3.ServerObject | OpenAPIV3_1.ServerObject;
57
57
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverVariableObject}
58
58
  */
59
59
  export type ServerVariableObject = OpenAPIV3.ServerVariableObject | OpenAPIV3_1.ServerVariableObject;
60
- export type ServerVariablesObject = {
61
- [variable: string]: ServerVariableObject;
62
- };
60
+ export type ServerVariablesObject = Record<string, ServerVariableObject>;
63
61
  export type ServerVariable = Record<
64
62
  string,
65
- string | number | Array<{ default?: string | number }> | { default?: string | number } | Record<string, never>
63
+ string | number | { default?: string | number }[] | { default?: string | number } | Record<string, never>
66
64
  >;
67
65
 
68
66
  export type Servers = {
@@ -92,9 +90,9 @@ export type PathItemObject = OpenAPIV3.PathItemObject | OpenAPIV3_1.PathItemObje
92
90
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#operationObject}
93
91
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#operationObject}
94
92
  */
95
- export type OperationObject = (OpenAPIV3.OperationObject | OpenAPIV3_1.OperationObject) & {
96
- [extension: string]: unknown;
97
- };
93
+ export type OperationObject = (OpenAPIV3.OperationObject | OpenAPIV3_1.OperationObject) &
94
+ // `x-*` extensions
95
+ Record<string, unknown>;
98
96
 
99
97
  /**
100
98
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterObject}
@@ -159,7 +157,7 @@ export type SchemaObject = (
159
157
  readOnly?: boolean;
160
158
  writeOnly?: boolean;
161
159
  example?: unknown;
162
- examples?: Array<unknown>;
160
+ examples?: unknown[];
163
161
  nullable?: boolean;
164
162
 
165
163
  // OpenAPI-specific properties
@@ -194,9 +192,7 @@ export function isSchema(check: unknown, isPolymorphicAllOfChild = false): check
194
192
  */
195
193
  export type SecuritySchemeObject = OpenAPIV3.SecuritySchemeObject | OpenAPIV3_1.SecuritySchemeObject;
196
194
 
197
- export type SecuritySchemesObject = {
198
- [key: string]: SecuritySchemeObject;
199
- };
195
+ export type SecuritySchemesObject = Record<string, SecuritySchemeObject>;
200
196
 
201
197
  export type KeyedSecuritySchemeObject = {
202
198
  _key: string;
@@ -56,7 +56,7 @@ const primitive = (schema: RMOAS.SchemaObject) => {
56
56
  function sampleFromSchema(
57
57
  schema: RMOAS.SchemaObject,
58
58
  opts: { includeReadOnly?: boolean; includeWriteOnly?: boolean } = {}
59
- ): string | number | boolean | null | Array<unknown> | Record<string, unknown> | undefined {
59
+ ): string | number | boolean | null | unknown[] | Record<string, unknown> | undefined {
60
60
  const objectifySchema = objectify(schema);
61
61
  let { type } = objectifySchema;
62
62
 
@@ -76,7 +76,7 @@ function sampleFromSchema(
76
76
  return undefined;
77
77
  }
78
78
  } else if (hasPolymorphism) {
79
- return sampleFromSchema((objectifySchema[hasPolymorphism] as Array<RMOAS.SchemaObject>)[0], opts);
79
+ return sampleFromSchema((objectifySchema[hasPolymorphism] as RMOAS.SchemaObject[])[0], opts);
80
80
  }
81
81
 
82
82
  const { example, additionalProperties, properties, items } = objectifySchema;
@@ -158,7 +158,7 @@ function sampleFromSchema(
158
158
  return schema.default;
159
159
  }
160
160
 
161
- return normalizeArray(schema.enum as Array<string>)[0];
161
+ return normalizeArray(schema.enum as string[])[0];
162
162
  }
163
163
 
164
164
  if (type === 'file') {
@@ -31,7 +31,7 @@ export function objectify(thing: unknown | Record<string, unknown>): Record<stri
31
31
  return thing;
32
32
  }
33
33
 
34
- export function normalizeArray(arr: string | number | Array<string | number>) {
34
+ export function normalizeArray(arr: string | number | (string | number)[]) {
35
35
  if (Array.isArray(arr)) {
36
36
  return arr;
37
37
  }