dtsgenerator 3.19.1 → 3.19.2

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/README.md CHANGED
@@ -143,6 +143,11 @@ Output debug message by [debug](https://www.npmjs.com/package/debug) library.
143
143
 
144
144
  ## ChangeLog
145
145
 
146
+ ### [v3.19.2](https://github.com/horiuchi/dtsgenerator/releases/tag/v3.19.2) (2024-06-11)
147
+
148
+ - fixed:
149
+ - Support a negative number by #566. Thank you @maximebiloe :+1:
150
+
146
151
  ### [v3.19.1](https://github.com/horiuchi/dtsgenerator/releases/tag/v3.19.1) (2023-08-25)
147
152
 
148
153
  - features:
@@ -53,6 +53,9 @@ function buildStringLiteralTypeNode(s) {
53
53
  }
54
54
  exports.buildStringLiteralTypeNode = buildStringLiteralTypeNode;
55
55
  function buildNumericLiteralTypeNode(n) {
56
+ if (!isNaN(parseFloat(n)) && parseFloat(n) < 0) {
57
+ return ts.factory.createLiteralTypeNode(ts.factory.createPrefixUnaryExpression(ts.SyntaxKind.MinusToken, ts.factory.createNumericLiteral(Math.abs(parseFloat(n)))));
58
+ }
56
59
  return ts.factory.createLiteralTypeNode(ts.factory.createNumericLiteral(n));
57
60
  }
58
61
  exports.buildNumericLiteralTypeNode = buildNumericLiteralTypeNode;
@@ -87,7 +90,7 @@ function buildTypeAliasNode(id, type, root) {
87
90
  exports.buildTypeAliasNode = buildTypeAliasNode;
88
91
  function buildPropertySignature(_schema, propertyName, valueType, required, isPattern) {
89
92
  const modifiers = undefined;
90
- const questionToken = required == null || !required.includes(propertyName)
93
+ const questionToken = !(required === null || required === void 0 ? void 0 : required.includes(propertyName))
91
94
  ? ts.factory.createToken(ts.SyntaxKind.QuestionToken)
92
95
  : undefined;
93
96
  if (isPattern) {
@@ -147,8 +150,7 @@ function buildTupleTypeNode(types, minItems, maxItems, additionalItems) {
147
150
  for (let i = 0; i < itemCount; i++) {
148
151
  let node = typesIsArray(types)
149
152
  ? i < types.length
150
- ?
151
- types[i]
153
+ ? types[i]
152
154
  : additionalItems !== undefined
153
155
  ? additionalItems === false
154
156
  ? buildNeverKeyword()
@@ -5,9 +5,7 @@ export interface Config {
5
5
  outputFile?: string;
6
6
  target: ScriptTarget;
7
7
  outputAST: boolean;
8
- plugins: {
9
- [pluginName: string]: boolean | Record<string, unknown>;
10
- };
8
+ plugins: Record<string, boolean | Record<string, unknown>>;
11
9
  }
12
10
  interface InputConfig {
13
11
  files: string[];
@@ -395,7 +395,7 @@ function selectSchemaType(content) {
395
395
  throw new Error(`expect parameter of type object, received ${typeof content}`);
396
396
  }
397
397
  if ('$schema' in content) {
398
- const schema = (_a = content['$schema']) !== null && _a !== void 0 ? _a : '';
398
+ const schema = (_a = content.$schema) !== null && _a !== void 0 ? _a : '';
399
399
  if (/^https?:\/\/json-schema.org\/schema#?$/.test(schema)) {
400
400
  return { type: 'Latest' };
401
401
  }
@@ -25,18 +25,10 @@ export declare namespace JsonSchemaDraft04 {
25
25
  minProperties?: Schema.Definitions.PositiveIntegerDefault0;
26
26
  required?: Schema.Definitions.StringArray;
27
27
  additionalProperties?: boolean | Schema;
28
- definitions?: {
29
- [name: string]: Schema;
30
- };
31
- properties?: {
32
- [name: string]: Schema;
33
- };
34
- patternProperties?: {
35
- [name: string]: Schema;
36
- };
37
- dependencies?: {
38
- [name: string]: Schema | Schema.Definitions.StringArray;
39
- };
28
+ definitions?: Record<string, Schema>;
29
+ properties?: Record<string, Schema>;
30
+ patternProperties?: Record<string, Schema>;
31
+ dependencies?: Record<string, Schema | Schema.Definitions.StringArray>;
40
32
  enum?: any[];
41
33
  type?: Schema.Definitions.SimpleTypes | Schema.Definitions.SimpleTypes[];
42
34
  format?: string;
@@ -1,5 +1,5 @@
1
1
  export declare namespace JsonSchemaDraft07 {
2
- type SchemaObject = {
2
+ interface SchemaObject {
3
3
  $id?: string;
4
4
  $schema?: string;
5
5
  $ref?: string;
@@ -28,18 +28,10 @@ export declare namespace JsonSchemaDraft07 {
28
28
  minProperties?: Schema.Definitions.NonNegativeIntegerDefault0;
29
29
  required?: Schema.Definitions.StringArray;
30
30
  additionalProperties?: Schema;
31
- definitions?: {
32
- [name: string]: Schema;
33
- };
34
- properties?: {
35
- [name: string]: Schema;
36
- };
37
- patternProperties?: {
38
- [name: string]: Schema;
39
- };
40
- dependencies?: {
41
- [name: string]: Schema | Schema.Definitions.StringArray;
42
- };
31
+ definitions?: Record<string, Schema>;
32
+ properties?: Record<string, Schema>;
33
+ patternProperties?: Record<string, Schema>;
34
+ dependencies?: Record<string, Schema | Schema.Definitions.StringArray>;
43
35
  propertyNames?: Schema;
44
36
  const?: any;
45
37
  enum?: any[];
@@ -54,7 +46,7 @@ export declare namespace JsonSchemaDraft07 {
54
46
  anyOf?: Schema.Definitions.SchemaArray;
55
47
  oneOf?: Schema.Definitions.SchemaArray;
56
48
  not?: Schema;
57
- };
49
+ }
58
50
  type Schema = SchemaObject | boolean;
59
51
  namespace Schema {
60
52
  namespace Definitions {
@@ -44,13 +44,9 @@ export declare namespace OpenApisV2 {
44
44
  email?: string;
45
45
  }
46
46
  type Default = JsonSchemaDraft04.Schema.Properties.Default;
47
- interface Definitions {
48
- [name: string]: Schema;
49
- }
47
+ type Definitions = Record<string, Schema>;
50
48
  type Enum = JsonSchemaDraft04.Schema.Properties.Enum;
51
- interface Examples {
52
- [name: string]: any;
53
- }
49
+ type Examples = Record<string, any>;
54
50
  type ExclusiveMaximum = JsonSchemaDraft04.Schema.Properties.ExclusiveMaximum;
55
51
  type ExclusiveMinimum = JsonSchemaDraft04.Schema.Properties.ExclusiveMinimum;
56
52
  interface ExternalDocs {
@@ -135,9 +131,7 @@ export declare namespace OpenApisV2 {
135
131
  enum?: Enum;
136
132
  multipleOf?: MultipleOf;
137
133
  }
138
- interface Headers {
139
- [name: string]: Header;
140
- }
134
+ type Headers = Record<string, Header>;
141
135
  interface Info {
142
136
  title: string;
143
137
  version: string;
@@ -192,9 +186,7 @@ export declare namespace OpenApisV2 {
192
186
  tokenUrl: string;
193
187
  description?: string;
194
188
  }
195
- interface Oauth2Scopes {
196
- [name: string]: string;
197
- }
189
+ type Oauth2Scopes = Record<string, string>;
198
190
  interface Operation {
199
191
  tags?: string[];
200
192
  summary?: string;
@@ -210,9 +202,7 @@ export declare namespace OpenApisV2 {
210
202
  security?: Security;
211
203
  }
212
204
  type Parameter = BodyParameter | NonBodyParameter;
213
- interface ParameterDefinitions {
214
- [name: string]: Parameter;
215
- }
205
+ type ParameterDefinitions = Record<string, Parameter>;
216
206
  type ParametersList = (Parameter | JsonReference)[];
217
207
  interface PathItem {
218
208
  $ref?: string;
@@ -248,9 +238,7 @@ export declare namespace OpenApisV2 {
248
238
  enum?: Enum;
249
239
  multipleOf?: MultipleOf;
250
240
  }
251
- interface Paths {
252
- [pattern: string]: PathItem;
253
- }
241
+ type Paths = Record<string, PathItem>;
254
242
  type Pattern = JsonSchemaDraft04.Schema.Properties.Pattern;
255
243
  interface PrimitivesItems {
256
244
  type?: 'string' | 'number' | 'integer' | 'boolean' | 'array';
@@ -301,13 +289,9 @@ export declare namespace OpenApisV2 {
301
289
  headers?: Headers;
302
290
  examples?: Examples;
303
291
  }
304
- interface ResponseDefinitions {
305
- [name: string]: Response;
306
- }
292
+ type ResponseDefinitions = Record<string, Response>;
307
293
  type ResponseValue = Response | JsonReference;
308
- interface Responses {
309
- [pattern: string]: ResponseValue;
310
- }
294
+ type Responses = Record<string, ResponseValue>;
311
295
  interface Schema {
312
296
  $ref?: string;
313
297
  format?: string;
@@ -339,9 +323,7 @@ export declare namespace OpenApisV2 {
339
323
  Schema,
340
324
  ...Schema[]
341
325
  ];
342
- properties?: {
343
- [name: string]: Schema;
344
- };
326
+ properties?: Record<string, Schema>;
345
327
  discriminator?: string;
346
328
  readOnly?: boolean;
347
329
  xml?: Xml;
@@ -350,12 +332,8 @@ export declare namespace OpenApisV2 {
350
332
  }
351
333
  type SchemesList = ('http' | 'https' | 'ws' | 'wss')[];
352
334
  type Security = SecurityRequirement[];
353
- interface SecurityDefinitions {
354
- [name: string]: BasicAuthenticationSecurity | ApiKeySecurity | Oauth2ImplicitSecurity | Oauth2PasswordSecurity | Oauth2ApplicationSecurity | Oauth2AccessCodeSecurity;
355
- }
356
- interface SecurityRequirement {
357
- [name: string]: string[];
358
- }
335
+ type SecurityDefinitions = Record<string, BasicAuthenticationSecurity | ApiKeySecurity | Oauth2ImplicitSecurity | Oauth2PasswordSecurity | Oauth2ApplicationSecurity | Oauth2AccessCodeSecurity>;
336
+ type SecurityRequirement = Record<string, string[]>;
359
337
  interface Tag {
360
338
  name: string;
361
339
  description?: string;
@@ -12,19 +12,13 @@ export declare namespace OpenApisV3 {
12
12
  }
13
13
  namespace SchemaJson {
14
14
  namespace Definitions {
15
- interface Any {
16
- [name: string]: any;
17
- }
15
+ type Any = Record<string, any>;
18
16
  type AnyOrExpression = Any | Expression;
19
- interface AnysOrExpressions {
20
- [name: string]: AnyOrExpression;
21
- }
17
+ type AnysOrExpressions = Record<string, AnyOrExpression>;
22
18
  interface Callback {
23
19
  }
24
20
  type CallbackOrReference = Callback | Reference;
25
- interface CallbacksOrReferences {
26
- [name: string]: CallbackOrReference;
27
- }
21
+ type CallbacksOrReferences = Record<string, CallbackOrReference>;
28
22
  interface Components {
29
23
  schemas?: SchemasOrReferences;
30
24
  responses?: ResponsesOrReferences;
@@ -53,9 +47,7 @@ export declare namespace OpenApisV3 {
53
47
  explode?: boolean;
54
48
  allowReserved?: boolean;
55
49
  }
56
- interface Encodings {
57
- [name: string]: Encoding;
58
- }
50
+ type Encodings = Record<string, Encoding>;
59
51
  interface Example {
60
52
  summary?: string;
61
53
  description?: string;
@@ -63,12 +55,8 @@ export declare namespace OpenApisV3 {
63
55
  externalValue?: string;
64
56
  }
65
57
  type ExampleOrReference = Example | Reference;
66
- interface ExamplesOrReferences {
67
- [name: string]: ExampleOrReference;
68
- }
69
- interface Expression {
70
- [name: string]: any;
71
- }
58
+ type ExamplesOrReferences = Record<string, ExampleOrReference>;
59
+ type Expression = Record<string, any>;
72
60
  interface ExternalDocs {
73
61
  description?: string;
74
62
  url: string;
@@ -87,9 +75,7 @@ export declare namespace OpenApisV3 {
87
75
  content?: MediaTypes;
88
76
  }
89
77
  type HeaderOrReference = Header | Reference;
90
- interface HeadersOrReferences {
91
- [name: string]: HeaderOrReference;
92
- }
78
+ type HeadersOrReferences = Record<string, HeaderOrReference>;
93
79
  interface Info {
94
80
  title: string;
95
81
  description?: string;
@@ -111,18 +97,14 @@ export declare namespace OpenApisV3 {
111
97
  server?: Server;
112
98
  }
113
99
  type LinkOrReference = Link | Reference;
114
- interface LinksOrReferences {
115
- [name: string]: LinkOrReference;
116
- }
100
+ type LinksOrReferences = Record<string, LinkOrReference>;
117
101
  interface MediaType {
118
102
  schema?: SchemaOrReference;
119
103
  example?: Any;
120
104
  examples?: ExamplesOrReferences;
121
105
  encoding?: Encodings;
122
106
  }
123
- interface MediaTypes {
124
- [name: string]: MediaType;
125
- }
107
+ type MediaTypes = Record<string, MediaType>;
126
108
  interface OauthFlow {
127
109
  authorizationUrl?: string;
128
110
  tokenUrl?: string;
@@ -165,9 +147,7 @@ export declare namespace OpenApisV3 {
165
147
  content?: MediaTypes;
166
148
  }
167
149
  type ParameterOrReference = Parameter | Reference;
168
- interface ParametersOrReferences {
169
- [name: string]: ParameterOrReference;
170
- }
150
+ type ParametersOrReferences = Record<string, ParameterOrReference>;
171
151
  interface PathItem {
172
152
  $ref?: string;
173
153
  summary?: string;
@@ -184,15 +164,11 @@ export declare namespace OpenApisV3 {
184
164
  parameters?: ParameterOrReference[];
185
165
  }
186
166
  type PathItemOrReference = PathItem | Reference;
187
- interface Paths {
188
- [name: string]: PathItemOrReference;
189
- }
167
+ type Paths = Record<string, PathItemOrReference>;
190
168
  interface Reference {
191
169
  $ref: string;
192
170
  }
193
- interface RequestBodiesOrReferences {
194
- [name: string]: RequestBodyOrReference;
195
- }
171
+ type RequestBodiesOrReferences = Record<string, RequestBodyOrReference>;
196
172
  interface RequestBody {
197
173
  description?: string;
198
174
  content: MediaTypes;
@@ -206,13 +182,9 @@ export declare namespace OpenApisV3 {
206
182
  links?: LinksOrReferences;
207
183
  }
208
184
  type ResponseOrReference = Response | Reference;
209
- interface ResponsesOrReferences {
210
- [name: string]: ResponseOrReference;
211
- }
185
+ type ResponsesOrReferences = Record<string, ResponseOrReference>;
212
186
  type SchemaOrReference = JsonSchemaDraft07.SchemaObject | Reference;
213
- interface SchemasOrReferences {
214
- [name: string]: SchemaOrReference;
215
- }
187
+ type SchemasOrReferences = Record<string, SchemaOrReference>;
216
188
  interface SecurityRequirement {
217
189
  }
218
190
  interface SecurityScheme {
@@ -226,9 +198,7 @@ export declare namespace OpenApisV3 {
226
198
  openIdConnectUrl?: string;
227
199
  }
228
200
  type SecuritySchemeOrReference = SecurityScheme | Reference;
229
- interface SecuritySchemesOrReferences {
230
- [name: string]: SecuritySchemeOrReference;
231
- }
201
+ type SecuritySchemesOrReferences = Record<string, SecuritySchemeOrReference>;
232
202
  interface Server {
233
203
  url: string;
234
204
  description?: string;
@@ -239,13 +209,9 @@ export declare namespace OpenApisV3 {
239
209
  default: string;
240
210
  description?: string;
241
211
  }
242
- interface ServerVariables {
243
- [name: string]: ServerVariable;
244
- }
212
+ type ServerVariables = Record<string, ServerVariable>;
245
213
  type SpecificationExtension = null | number | boolean | string | any[];
246
- interface Strings {
247
- [name: string]: string;
248
- }
214
+ type Strings = Record<string, string>;
249
215
  interface Tag {
250
216
  name: string;
251
217
  description?: string;
@@ -27,7 +27,7 @@ export interface PluginContext {
27
27
  inputSchemas: IterableIterator<[string, Schema]>;
28
28
  }
29
29
  export type PreProcessHandler = (contents: Schema[]) => Schema[];
30
- export type Plugin = {
30
+ export interface Plugin {
31
31
  meta: {
32
32
  name: string;
33
33
  version: string;
@@ -35,5 +35,5 @@ export type Plugin = {
35
35
  };
36
36
  preProcess?: (context: PluginContext) => Promise<PreProcessHandler | undefined>;
37
37
  postProcess?: (context: PluginContext) => Promise<TransformerFactory<SourceFile> | undefined>;
38
- };
38
+ }
39
39
  export declare function loadPlugin(name: string, option: boolean | Record<string, unknown>): Promise<Plugin | undefined>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dtsgenerator",
3
- "version": "3.19.1",
3
+ "version": "3.19.2",
4
4
  "description": "TypeScript d.ts file generator for JSON Schema file",
5
5
  "bin": {
6
6
  "dtsgen": "bin/dtsgen"
@@ -11,7 +11,7 @@
11
11
  "build": "tsc -p ./tsconfig-build.json",
12
12
  "clean": "rimraf dist/ build/ {src,test}/**/*.{js,js.map} *.tsbuildinfo",
13
13
  "compile": "tsc -p .",
14
- "lint": "eslint --fix --ext ts src/ test/",
14
+ "lint": "eslint --fix --report-unused-disable-directives --ext ts src/ test/",
15
15
  "format": "prettier --cache --write 'src/**/*.ts' 'test/*.ts' 'test/core/*.ts'",
16
16
  "precompile": "npm run lint && npm run format",
17
17
  "prepublishOnly": "npm run build",
@@ -41,40 +41,40 @@
41
41
  "url": "https://github.com/horiuchi/dtsgenerator/issues"
42
42
  },
43
43
  "engines": {
44
- "node": ">= 16.0"
44
+ "node": ">= 18.0"
45
45
  },
46
46
  "dependencies": {
47
- "commander": "^11.0.0",
47
+ "commander": "^12.1.0",
48
48
  "cross-fetch": "^4.0.0",
49
- "debug": "^4.3.4",
50
- "glob": "^10.3.3",
51
- "http-proxy-agent": "^7.0.0",
52
- "https-proxy-agent": "^7.0.1",
49
+ "debug": "^4.3.5",
50
+ "glob": "^10.4.1",
51
+ "http-proxy-agent": "^7.0.2",
52
+ "https-proxy-agent": "^7.0.4",
53
53
  "js-yaml": "^4.1.0",
54
- "tslib": "^2.6.2",
55
- "typescript": "^5.1.6"
54
+ "tslib": "^2.6.3",
55
+ "typescript": "^5.4.5"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@dtsgenerator/do-nothing": "^2.6.0",
59
- "@dtsgenerator/eslint-config": "^0.6.5",
59
+ "@dtsgenerator/eslint-config": "^0.7.1",
60
60
  "@dtsgenerator/replace-namespace": "^1.6.0",
61
61
  "@dtsgenerator/single-quote": "^1.7.0",
62
62
  "@istanbuljs/nyc-config-typescript": "^1.0.2",
63
- "@types/debug": "^4.1.8",
63
+ "@types/debug": "^4.1.12",
64
64
  "@types/glob": "^8.1.0",
65
- "@types/js-yaml": "^4.0.5",
66
- "@types/mocha": "^10.0.1",
67
- "@types/node": "^16.18.46",
65
+ "@types/js-yaml": "^4.0.9",
66
+ "@types/mocha": "^10.0.6",
67
+ "@types/node": "^18.19.34",
68
68
  "cross-env": "^7.0.3",
69
- "eslint": "^8.47.0",
70
- "husky": "^8.0.3",
71
- "lint-staged": "^14.0.1",
72
- "mocha": "^10.2.0",
73
- "nyc": "^15.1.0",
74
- "prettier": "^3.0.2",
75
- "rimraf": "^5.0.1",
69
+ "eslint": "^8.56.0",
70
+ "husky": "^9.0.11",
71
+ "lint-staged": "^15.2.5",
72
+ "mocha": "^10.4.0",
73
+ "nyc": "^17.0.0",
74
+ "prettier": "^3.3.1",
75
+ "rimraf": "^5.0.7",
76
76
  "source-map-support": "^0.5.21",
77
- "ts-node": "^10.9.1"
77
+ "ts-node": "^10.9.2"
78
78
  },
79
79
  "lint-staged": {
80
80
  "**/*.ts": [
@@ -48,6 +48,15 @@ export function buildStringLiteralTypeNode(s: string): ts.LiteralTypeNode {
48
48
  return ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(s));
49
49
  }
50
50
  export function buildNumericLiteralTypeNode(n: string): ts.LiteralTypeNode {
51
+ if (!isNaN(parseFloat(n)) && parseFloat(n) < 0) {
52
+ return ts.factory.createLiteralTypeNode(
53
+ ts.factory.createPrefixUnaryExpression(
54
+ ts.SyntaxKind.MinusToken,
55
+ ts.factory.createNumericLiteral(Math.abs(parseFloat(n))),
56
+ ),
57
+ );
58
+ }
59
+
51
60
  return ts.factory.createLiteralTypeNode(ts.factory.createNumericLiteral(n));
52
61
  }
53
62
  export function buildBooleanLiteralTypeNode(b: boolean): ts.LiteralTypeNode {
@@ -117,10 +126,9 @@ export function buildPropertySignature(
117
126
  isPattern: boolean | undefined,
118
127
  ): ts.PropertySignature | ts.IndexSignatureDeclaration {
119
128
  const modifiers = undefined;
120
- const questionToken =
121
- required == null || !required.includes(propertyName)
122
- ? ts.factory.createToken(ts.SyntaxKind.QuestionToken)
123
- : undefined;
129
+ const questionToken = !required?.includes(propertyName)
130
+ ? ts.factory.createToken(ts.SyntaxKind.QuestionToken)
131
+ : undefined;
124
132
  if (isPattern) {
125
133
  return ts.factory.createIndexSignature(
126
134
  modifiers,
@@ -223,13 +231,12 @@ export function buildTupleTypeNode(
223
231
  for (let i = 0; i < itemCount; i++) {
224
232
  let node = typesIsArray(types)
225
233
  ? i < types.length
226
- ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
227
- types[i]!
234
+ ? types[i]!
228
235
  : additionalItems !== undefined
229
- ? additionalItems === false
230
- ? buildNeverKeyword()
231
- : additionalItems
232
- : buildAnyKeyword()
236
+ ? additionalItems === false
237
+ ? buildNeverKeyword()
238
+ : additionalItems
239
+ : buildAnyKeyword()
233
240
  : types;
234
241
  if (minItems == null || i >= minItems) {
235
242
  node = ts.factory.createOptionalTypeNode(node);
@@ -8,9 +8,7 @@ export interface Config {
8
8
  target: ScriptTarget;
9
9
  outputAST: boolean;
10
10
 
11
- plugins: {
12
- [pluginName: string]: boolean | Record<string, unknown>;
13
- };
11
+ plugins: Record<string, boolean | Record<string, unknown>>;
14
12
  }
15
13
 
16
14
  interface InputConfig {
@@ -57,7 +57,7 @@ export default class DtsGenerator {
57
57
 
58
58
  const postProcess = await this.getPostProcess(plugins.post);
59
59
  const result = ts.transform(file, postProcess);
60
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
60
+
61
61
  const transformedNodes = result.transformed[0]!;
62
62
 
63
63
  const transformedContent = config.outputAST
@@ -553,14 +553,14 @@ export default class DtsGenerator {
553
553
  const additionalItems = schema.content.additionalItems
554
554
  ? this.normalizeContent(schema, '/additionalItems')
555
555
  : schema.content.additionalItems === false
556
- ? false
557
- : undefined;
556
+ ? false
557
+ : undefined;
558
558
 
559
559
  return additionalItems === undefined
560
560
  ? undefined
561
561
  : additionalItems === false
562
- ? false
563
- : this.generateTypeProperty(additionalItems, false);
562
+ ? false
563
+ : this.generateTypeProperty(additionalItems, false);
564
564
  };
565
565
 
566
566
  if (items == null) {
@@ -1,4 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-unsafe-member-access */
2
1
  import * as JsonPointer from '../jsonPointer';
3
2
  import { JsonSchemaDraft04 } from './jsonSchemaDraft04';
4
3
  import { OpenApisV2 } from './openApiV2';
@@ -103,7 +102,7 @@ export function searchAllSubSchema(
103
102
  });
104
103
  };
105
104
  const walkObject = (
106
- obj: { [name: string]: JsonSchema } | undefined,
105
+ obj: Record<string, JsonSchema> | undefined,
107
106
  paths: string[],
108
107
  parentIds: string[],
109
108
  ): void => {
@@ -202,7 +201,7 @@ export function searchAllSubSchema(
202
201
  }
203
202
  function setSubIdToAnyObject<T>(
204
203
  f: (t: T, keys: string[]) => void,
205
- obj: { [key: string]: T } | undefined,
204
+ obj: Record<string, T> | undefined,
206
205
  keys: string[],
207
206
  ): void {
208
207
  if (obj == null) {
@@ -297,7 +296,7 @@ export function searchAllSubSchema(
297
296
  const paths = keys
298
297
  .slice(0, keys.length - 1)
299
298
  .concat(inType + 'Parameters');
300
- const properties: { [name: string]: JsonSchemaDraft04.Schema } = {};
299
+ const properties: Record<string, JsonSchemaDraft04.Schema> = {};
301
300
  params.forEach(([key, _]) => {
302
301
  properties[key] = {
303
302
  $ref: createId(keys.concat(key)),
@@ -347,7 +346,6 @@ export function searchAllSubSchema(
347
346
  }
348
347
  const operationId = ops.operationId;
349
348
  if (operationId) {
350
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
351
349
  keys = [keys[0]!, convertKeyToTypeName(operationId)];
352
350
  }
353
351
  setSubIdToParameters(ops.parameters, keys.concat('parameters'));
@@ -446,7 +444,6 @@ export function searchAllSubSchema(
446
444
  }
447
445
  const operationId = ops.operationId;
448
446
  if (operationId) {
449
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
450
447
  keys = [keys[0]!, convertKeyToTypeName(operationId)];
451
448
  }
452
449
  setSubIdToParameters(ops.parameters, keys.concat('parameters'));
@@ -476,7 +473,7 @@ export function searchAllSubSchema(
476
473
  }
477
474
 
478
475
  function setSubIdToObject(
479
- obj: { [name: string]: JsonSchema } | undefined,
476
+ obj: Record<string, JsonSchema> | undefined,
480
477
  paths: string[],
481
478
  ): void {
482
479
  if (obj == null) {
@@ -558,7 +555,7 @@ export function selectSchemaType(content: JsonSchema | OpenApiSchema): {
558
555
  );
559
556
  }
560
557
  if ('$schema' in content) {
561
- const schema = content['$schema'] ?? '';
558
+ const schema = content.$schema ?? '';
562
559
  if (/^https?:\/\/json-schema.org\/schema#?$/.test(schema)) {
563
560
  return { type: 'Latest' };
564
561
  }
@@ -1,4 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
1
  /* eslint-disable @typescript-eslint/no-namespace */
3
2
 
4
3
  export namespace JsonSchemaDraft04 {
@@ -31,18 +30,10 @@ export namespace JsonSchemaDraft04 {
31
30
  minProperties?: Schema.Definitions.PositiveIntegerDefault0;
32
31
  required?: Schema.Definitions.StringArray;
33
32
  additionalProperties?: boolean | Schema;
34
- definitions?: {
35
- [name: string]: Schema;
36
- };
37
- properties?: {
38
- [name: string]: Schema;
39
- };
40
- patternProperties?: {
41
- [name: string]: Schema;
42
- };
43
- dependencies?: {
44
- [name: string]: Schema | Schema.Definitions.StringArray;
45
- };
33
+ definitions?: Record<string, Schema>;
34
+ properties?: Record<string, Schema>;
35
+ patternProperties?: Record<string, Schema>;
36
+ dependencies?: Record<string, Schema | Schema.Definitions.StringArray>;
46
37
  enum?: any[];
47
38
  type?:
48
39
  | Schema.Definitions.SimpleTypes
@@ -1,8 +1,7 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
1
  /* eslint-disable @typescript-eslint/no-namespace */
3
2
 
4
3
  export namespace JsonSchemaDraft07 {
5
- export type SchemaObject = {
4
+ export interface SchemaObject {
6
5
  $id?: string; // uri-reference
7
6
  $schema?: string; // uri
8
7
  $ref?: string; // uri-reference
@@ -31,18 +30,10 @@ export namespace JsonSchemaDraft07 {
31
30
  minProperties?: Schema.Definitions.NonNegativeIntegerDefault0;
32
31
  required?: Schema.Definitions.StringArray;
33
32
  additionalProperties?: Schema;
34
- definitions?: {
35
- [name: string]: Schema;
36
- };
37
- properties?: {
38
- [name: string]: Schema;
39
- };
40
- patternProperties?: {
41
- [name: string]: Schema;
42
- };
43
- dependencies?: {
44
- [name: string]: Schema | Schema.Definitions.StringArray;
45
- };
33
+ definitions?: Record<string, Schema>;
34
+ properties?: Record<string, Schema>;
35
+ patternProperties?: Record<string, Schema>;
36
+ dependencies?: Record<string, Schema | Schema.Definitions.StringArray>;
46
37
  propertyNames?: Schema;
47
38
  const?: any;
48
39
  enum?: any[];
@@ -59,7 +50,7 @@ export namespace JsonSchemaDraft07 {
59
50
  anyOf?: Schema.Definitions.SchemaArray;
60
51
  oneOf?: Schema.Definitions.SchemaArray;
61
52
  not?: Schema;
62
- };
53
+ }
63
54
  export type Schema = SchemaObject | boolean;
64
55
  export namespace Schema {
65
56
  export namespace Definitions {
@@ -1,5 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-empty-interface */
2
- /* eslint-disable @typescript-eslint/no-explicit-any */
3
1
  /* eslint-disable @typescript-eslint/no-namespace */
4
2
  import { JsonSchemaDraft04 } from './jsonSchemaDraft04';
5
3
 
@@ -98,15 +96,9 @@ export namespace OpenApisV2 {
98
96
  /**
99
97
  * One or more JSON objects describing the schemas being consumed and produced by the API.
100
98
  */
101
- export interface Definitions {
102
- [
103
- name: string
104
- ]: /* A deterministic version of a JSON Schema object. */ Schema;
105
- }
99
+ export type Definitions = Record<string, Schema>;
106
100
  export type Enum = JsonSchemaDraft04.Schema.Properties.Enum;
107
- export interface Examples {
108
- [name: string]: any;
109
- }
101
+ export type Examples = Record<string, any>;
110
102
  export type ExclusiveMaximum =
111
103
  JsonSchemaDraft04.Schema.Properties.ExclusiveMaximum;
112
104
  export type ExclusiveMinimum =
@@ -232,9 +224,7 @@ export namespace OpenApisV2 {
232
224
  enum?: Enum;
233
225
  multipleOf?: MultipleOf;
234
226
  }
235
- export interface Headers {
236
- [name: string]: Header;
237
- }
227
+ export type Headers = Record<string, Header>;
238
228
  /**
239
229
  * General information about the API.
240
230
  */
@@ -323,9 +313,7 @@ export namespace OpenApisV2 {
323
313
  tokenUrl: string; // uri
324
314
  description?: string;
325
315
  }
326
- export interface Oauth2Scopes {
327
- [name: string]: string;
328
- }
316
+ export type Oauth2Scopes = Record<string, string>;
329
317
  export interface Operation {
330
318
  tags?: string[];
331
319
  /**
@@ -359,9 +347,7 @@ export namespace OpenApisV2 {
359
347
  /**
360
348
  * One or more JSON representations for parameters
361
349
  */
362
- export interface ParameterDefinitions {
363
- [name: string]: Parameter;
364
- }
350
+ export type ParameterDefinitions = Record<string, Parameter>;
365
351
  /**
366
352
  * The parameters needed to send a valid API call.
367
353
  */
@@ -415,9 +401,7 @@ export namespace OpenApisV2 {
415
401
  /**
416
402
  * Relative paths to the individual endpoints. They must be relative to the 'basePath'.
417
403
  */
418
- export interface Paths {
419
- [pattern: string]: PathItem;
420
- }
404
+ export type Paths = Record<string, PathItem>;
421
405
  export type Pattern =
422
406
  JsonSchemaDraft04.Schema.Properties.Pattern /* regex */;
423
407
  export interface PrimitivesItems {
@@ -489,18 +473,12 @@ export namespace OpenApisV2 {
489
473
  /**
490
474
  * One or more JSON representations for responses
491
475
  */
492
- export interface ResponseDefinitions {
493
- [name: string]: Response;
494
- }
476
+ export type ResponseDefinitions = Record<string, Response>;
495
477
  export type ResponseValue = Response | JsonReference;
496
478
  /**
497
479
  * Response objects names can either be any valid HTTP status code or 'default'.
498
480
  */
499
- export interface Responses {
500
- [
501
- pattern: string
502
- ]: ResponseValue /* Patterns: ^([0-9]{3})$|^(default)$ | ^x- */;
503
- }
481
+ export type Responses = Record<string, ResponseValue>;
504
482
  /**
505
483
  * A deterministic version of a JSON Schema object.
506
484
  */
@@ -538,11 +516,7 @@ export namespace OpenApisV2 {
538
516
  /* A deterministic version of a JSON Schema object. */ Schema,
539
517
  .../* A deterministic version of a JSON Schema object. */ Schema[],
540
518
  ];
541
- properties?: {
542
- [
543
- name: string
544
- ]: /* A deterministic version of a JSON Schema object. */ Schema;
545
- };
519
+ properties?: Record<string, Schema>;
546
520
  discriminator?: string;
547
521
  readOnly?: boolean;
548
522
  xml?: Xml;
@@ -554,18 +528,16 @@ export namespace OpenApisV2 {
554
528
  */
555
529
  export type SchemesList = ('http' | 'https' | 'ws' | 'wss')[];
556
530
  export type Security = SecurityRequirement[];
557
- export interface SecurityDefinitions {
558
- [name: string]:
559
- | BasicAuthenticationSecurity
560
- | ApiKeySecurity
561
- | Oauth2ImplicitSecurity
562
- | Oauth2PasswordSecurity
563
- | Oauth2ApplicationSecurity
564
- | Oauth2AccessCodeSecurity;
565
- }
566
- export interface SecurityRequirement {
567
- [name: string]: string[];
568
- }
531
+ export type SecurityDefinitions = Record<
532
+ string,
533
+ | BasicAuthenticationSecurity
534
+ | ApiKeySecurity
535
+ | Oauth2ImplicitSecurity
536
+ | Oauth2PasswordSecurity
537
+ | Oauth2ApplicationSecurity
538
+ | Oauth2AccessCodeSecurity
539
+ >;
540
+ export type SecurityRequirement = Record<string, string[]>;
569
541
  export interface Tag {
570
542
  name: string;
571
543
  description?: string;
@@ -583,5 +555,5 @@ export namespace OpenApisV2 {
583
555
  }
584
556
  }
585
557
  }
586
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
558
+
587
559
  export import SwaggerIo = OpenApisV2;
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/no-empty-interface */
2
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
+
3
3
  /* eslint-disable @typescript-eslint/no-namespace */
4
4
  import { JsonSchemaDraft07 } from './jsonSchemaDraft07';
5
5
 
@@ -20,21 +20,18 @@ export namespace OpenApisV3 {
20
20
  }
21
21
  export namespace SchemaJson {
22
22
  export namespace Definitions {
23
- export interface Any {
24
- [name: string]: any;
25
- }
23
+ export type Any = Record<string, any>;
26
24
  export type AnyOrExpression = Any | Expression;
27
- export interface AnysOrExpressions {
28
- [name: string]: AnyOrExpression;
29
- }
25
+ export type AnysOrExpressions = Record<string, AnyOrExpression>;
30
26
  /**
31
27
  * A map of possible out-of band callbacks related to the parent operation. Each value in the map is a Path Item Object that describes a set of requests that may be initiated by the API provider and the expected responses. The key value used to identify the callback object is an expression, evaluated at runtime, that identifies a URL to use for the callback operation.
32
28
  */
33
29
  export interface Callback {}
34
30
  export type CallbackOrReference = Callback | Reference;
35
- export interface CallbacksOrReferences {
36
- [name: string]: CallbackOrReference;
37
- }
31
+ export type CallbacksOrReferences = Record<
32
+ string,
33
+ CallbackOrReference
34
+ >;
38
35
  /**
39
36
  * Holds a set of reusable objects for different aspects of the OAS. All objects defined within the components object will have no effect on the API unless they are explicitly referenced from properties outside the components object.
40
37
  */
@@ -75,9 +72,7 @@ export namespace OpenApisV3 {
75
72
  explode?: boolean;
76
73
  allowReserved?: boolean;
77
74
  }
78
- export interface Encodings {
79
- [name: string]: Encoding;
80
- }
75
+ export type Encodings = Record<string, Encoding>;
81
76
  /**
82
77
  *
83
78
  */
@@ -88,12 +83,11 @@ export namespace OpenApisV3 {
88
83
  externalValue?: string;
89
84
  }
90
85
  export type ExampleOrReference = Example | Reference;
91
- export interface ExamplesOrReferences {
92
- [name: string]: ExampleOrReference;
93
- }
94
- export interface Expression {
95
- [name: string]: any;
96
- }
86
+ export type ExamplesOrReferences = Record<
87
+ string,
88
+ ExampleOrReference
89
+ >;
90
+ export type Expression = Record<string, any>;
97
91
  /**
98
92
  * Allows referencing an external resource for extended documentation.
99
93
  */
@@ -118,9 +112,7 @@ export namespace OpenApisV3 {
118
112
  content?: MediaTypes;
119
113
  }
120
114
  export type HeaderOrReference = Header | Reference;
121
- export interface HeadersOrReferences {
122
- [name: string]: HeaderOrReference;
123
- }
115
+ export type HeadersOrReferences = Record<string, HeaderOrReference>;
124
116
  /**
125
117
  * The object provides metadata about the API. The metadata MAY be used by the clients if needed, and MAY be presented in editing or documentation generation tools for convenience.
126
118
  */
@@ -151,9 +143,7 @@ export namespace OpenApisV3 {
151
143
  server?: Server;
152
144
  }
153
145
  export type LinkOrReference = Link | Reference;
154
- export interface LinksOrReferences {
155
- [name: string]: LinkOrReference;
156
- }
146
+ export type LinksOrReferences = Record<string, LinkOrReference>;
157
147
  /**
158
148
  * Each Media Type Object provides schema and examples for the media type identified by its key.
159
149
  */
@@ -163,9 +153,7 @@ export namespace OpenApisV3 {
163
153
  examples?: ExamplesOrReferences;
164
154
  encoding?: Encodings;
165
155
  }
166
- export interface MediaTypes {
167
- [name: string]: MediaType;
168
- }
156
+ export type MediaTypes = Record<string, MediaType>;
169
157
  /**
170
158
  * Configuration details for a supported OAuth Flow
171
159
  */
@@ -220,9 +208,10 @@ export namespace OpenApisV3 {
220
208
  content?: MediaTypes;
221
209
  }
222
210
  export type ParameterOrReference = Parameter | Reference;
223
- export interface ParametersOrReferences {
224
- [name: string]: ParameterOrReference;
225
- }
211
+ export type ParametersOrReferences = Record<
212
+ string,
213
+ ParameterOrReference
214
+ >;
226
215
  /**
227
216
  * Describes the operations available on a single path. A Path Item MAY be empty, due to ACL constraints. The path itself is still exposed to the documentation viewer but they will not know which operations and parameters are available.
228
217
  */
@@ -245,18 +234,17 @@ export namespace OpenApisV3 {
245
234
  /**
246
235
  * Holds the relative paths to the individual endpoints and their operations. The path is appended to the URL from the `Server Object` in order to construct the full URL. The Paths MAY be empty, due to ACL constraints.
247
236
  */
248
- export interface Paths {
249
- [name: string]: PathItemOrReference;
250
- }
237
+ export type Paths = Record<string, PathItemOrReference>;
251
238
  /**
252
239
  * A simple object to allow referencing other components in the specification, internally and externally. The Reference Object is defined by JSON Reference and follows the same structure, behavior and rules. For this specification, reference resolution is accomplished as defined by the JSON Reference specification and not by the JSON Schema specification.
253
240
  */
254
241
  export interface Reference {
255
242
  $ref: string;
256
243
  }
257
- export interface RequestBodiesOrReferences {
258
- [name: string]: RequestBodyOrReference;
259
- }
244
+ export type RequestBodiesOrReferences = Record<
245
+ string,
246
+ RequestBodyOrReference
247
+ >;
260
248
  /**
261
249
  * Describes a single request body.
262
250
  */
@@ -279,15 +267,14 @@ export namespace OpenApisV3 {
279
267
  /**
280
268
  * A container for the expected responses of an operation. The container maps a HTTP response code to the expected response. The documentation is not necessarily expected to cover all possible HTTP response codes because they may not be known in advance. However, documentation is expected to cover a successful operation response and any known errors. The `default` MAY be used as a default response object for all HTTP codes that are not covered individually by the specification. The `Responses Object` MUST contain at least one response code, and it SHOULD be the response for a successful operation call.
281
269
  */
282
- export interface ResponsesOrReferences {
283
- [name: string]: ResponseOrReference;
284
- }
270
+ export type ResponsesOrReferences = Record<
271
+ string,
272
+ ResponseOrReference
273
+ >;
285
274
  export type SchemaOrReference =
286
275
  | JsonSchemaDraft07.SchemaObject
287
276
  | Reference;
288
- export interface SchemasOrReferences {
289
- [name: string]: SchemaOrReference;
290
- }
277
+ export type SchemasOrReferences = Record<string, SchemaOrReference>;
291
278
  /**
292
279
  * Lists the required security schemes to execute this operation. The name used for each property MUST correspond to a security scheme declared in the Security Schemes under the Components Object. Security Requirement Objects that contain multiple schemes require that all schemes MUST be satisfied for a request to be authorized. This enables support for scenarios where multiple query parameters or HTTP headers are required to convey security information. When a list of Security Requirement Objects is defined on the Open API object or Operation Object, only one of Security Requirement Objects in the list needs to be satisfied to authorize the request.
293
280
  */
@@ -306,9 +293,10 @@ export namespace OpenApisV3 {
306
293
  openIdConnectUrl?: string;
307
294
  }
308
295
  export type SecuritySchemeOrReference = SecurityScheme | Reference;
309
- export interface SecuritySchemesOrReferences {
310
- [name: string]: SecuritySchemeOrReference;
311
- }
296
+ export type SecuritySchemesOrReferences = Record<
297
+ string,
298
+ SecuritySchemeOrReference
299
+ >;
312
300
  /**
313
301
  * An object representing a Server.
314
302
  */
@@ -325,9 +313,7 @@ export namespace OpenApisV3 {
325
313
  default: string;
326
314
  description?: string;
327
315
  }
328
- export interface ServerVariables {
329
- [name: string]: ServerVariable;
330
- }
316
+ export type ServerVariables = Record<string, ServerVariable>;
331
317
  /**
332
318
  * Any property starting with x- is valid.
333
319
  */
@@ -337,9 +323,7 @@ export namespace OpenApisV3 {
337
323
  | boolean
338
324
  | string
339
325
  | any[];
340
- export interface Strings {
341
- [name: string]: string;
342
- }
326
+ export type Strings = Record<string, string>;
343
327
  /**
344
328
  * Adds metadata to a single tag that is used by the Operation Object. It is not mandatory to have a Tag Object per tag defined in the Operation Object instances.
345
329
  */
package/src/core/type.ts CHANGED
@@ -12,7 +12,7 @@ import { OpenApisV3 } from './openApiV3';
12
12
  import SchemaId from './schemaId';
13
13
 
14
14
  // export `ts` for using the same version of TypeScript in all plugins.
15
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
15
+
16
16
  export import ts = require('typescript');
17
17
 
18
18
  // Schema types
@@ -119,7 +119,7 @@ export interface PluginContext {
119
119
 
120
120
  export type PreProcessHandler = (contents: Schema[]) => Schema[];
121
121
 
122
- export type Plugin = {
122
+ export interface Plugin {
123
123
  meta: {
124
124
  name: string;
125
125
  version: string;
@@ -131,7 +131,7 @@ export type Plugin = {
131
131
  postProcess?: (
132
132
  context: PluginContext,
133
133
  ) => Promise<TransformerFactory<SourceFile> | undefined>;
134
- };
134
+ }
135
135
 
136
136
  export async function loadPlugin(
137
137
  name: string,
package/src/core/utils.ts CHANGED
@@ -78,7 +78,6 @@ export function checkValidMIMEType(mime: string): boolean {
78
78
  return /^application\/(?:[a-z0-9-_.]+\+)?json5?$/.test(type);
79
79
  }
80
80
 
81
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
82
81
  export function mergeSchema(a: any, b: any): boolean {
83
82
  if ('$ref' in a || '$ref' in b) {
84
83
  a.$ref = b.$ref || a.$ref;
@@ -1,4 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
1
  /* eslint-disable @typescript-eslint/no-unsafe-enum-comparison */
3
2
  import { ScriptTarget } from 'typescript';
4
3
 
@@ -785,16 +784,16 @@ function isUnicodeIdentifierStart(code: number, languageVersion: ScriptTarget) {
785
784
  return languageVersion >= ScriptTarget.ES2015
786
785
  ? lookupInUnicodeMap(code, unicodeESNextIdentifierStart)
787
786
  : languageVersion === ScriptTarget.ES5
788
- ? lookupInUnicodeMap(code, unicodeES5IdentifierStart)
789
- : lookupInUnicodeMap(code, unicodeES3IdentifierStart);
787
+ ? lookupInUnicodeMap(code, unicodeES5IdentifierStart)
788
+ : lookupInUnicodeMap(code, unicodeES3IdentifierStart);
790
789
  }
791
790
 
792
791
  function isUnicodeIdentifierPart(code: number, languageVersion: ScriptTarget) {
793
792
  return languageVersion >= ScriptTarget.ES2015
794
793
  ? lookupInUnicodeMap(code, unicodeESNextIdentifierPart)
795
794
  : languageVersion === ScriptTarget.ES5
796
- ? lookupInUnicodeMap(code, unicodeES5IdentifierPart)
797
- : lookupInUnicodeMap(code, unicodeES3IdentifierPart);
795
+ ? lookupInUnicodeMap(code, unicodeES5IdentifierPart)
796
+ : lookupInUnicodeMap(code, unicodeES3IdentifierPart);
798
797
  }
799
798
 
800
799
  function isIdentifierStart(ch: number, languageVersion: ScriptTarget): boolean {
@@ -1,7 +1,5 @@
1
- /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
1
  /* eslint-disable @typescript-eslint/no-unsafe-assignment */
3
2
  /* eslint-disable @typescript-eslint/no-unsafe-member-access */
4
- /* eslint-disable @typescript-eslint/no-unsafe-return */
5
3
 
6
4
  export function get(
7
5
  obj: any,