@kubb/swagger-ts 1.0.3 → 1.1.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.
- package/README.md +3 -3
- package/dist/index.cjs +29 -21
- package/dist/index.js +29 -21
- package/package.json +4 -4
- package/src/generators/TypeGenerator.ts +36 -24
- package/src/plugin.ts +1 -1
package/README.md
CHANGED
|
@@ -10,13 +10,13 @@
|
|
|
10
10
|
<!-- Badges -->
|
|
11
11
|
<p>
|
|
12
12
|
<a href="https://www.npmjs.com/package/@kubb/swagger-ts">
|
|
13
|
-
<img alt="
|
|
13
|
+
<img alt="npm version" src="https://img.shields.io/npm/v/@kubb/swagger-ts?style=for-the-badge"/>
|
|
14
14
|
</a>
|
|
15
15
|
<a href="https://www.npmjs.com/package/@kubb/swagger-ts">
|
|
16
|
-
<img alt="
|
|
16
|
+
<img alt="npm downloads" src="https://img.shields.io/bundlephobia/min/@kubb/swagger-ts?style=for-the-badge"/>
|
|
17
17
|
</a>
|
|
18
18
|
<a href="https://www.npmjs.com/package/@kubb/swagger-ts">
|
|
19
|
-
<img alt="
|
|
19
|
+
<img alt="npm downloads" src="https://img.shields.io/npm/dm/@kubb/swagger-ts?style=for-the-badge"/>
|
|
20
20
|
</a>
|
|
21
21
|
</p>
|
|
22
22
|
|
package/dist/index.cjs
CHANGED
|
@@ -120,7 +120,9 @@ var _TypeGenerator = class extends core.SchemaGenerator {
|
|
|
120
120
|
comments: [
|
|
121
121
|
schema.description && `@description ${schema.description}`,
|
|
122
122
|
schema.type && `@type ${schema.type}${isRequired ? "" : " | undefined"} ${schema.format || ""}`,
|
|
123
|
-
schema.example && `@example ${schema.example}
|
|
123
|
+
schema.example && `@example ${schema.example}`,
|
|
124
|
+
schema.default !== void 0 && typeof schema.default === "string" && `@default '${schema.default}'`,
|
|
125
|
+
schema.default !== void 0 && typeof schema.default !== "string" && `@default ${schema.default}`
|
|
124
126
|
]
|
|
125
127
|
});
|
|
126
128
|
}
|
|
@@ -172,33 +174,39 @@ var _TypeGenerator = class extends core.SchemaGenerator {
|
|
|
172
174
|
}
|
|
173
175
|
if (schema.oneOf) {
|
|
174
176
|
const schemaWithoutOneOf = { ...schema, oneOf: void 0 };
|
|
177
|
+
const union = factory2.createParenthesizedType(
|
|
178
|
+
tsCodegen.createUnionDeclaration({
|
|
179
|
+
nodes: schema.oneOf.map((item) => {
|
|
180
|
+
return this.getBaseTypeFromSchema(item);
|
|
181
|
+
}).filter(Boolean)
|
|
182
|
+
})
|
|
183
|
+
);
|
|
184
|
+
if (schemaWithoutOneOf.properties) {
|
|
185
|
+
return tsCodegen.createIntersectionDeclaration({
|
|
186
|
+
nodes: [this.getBaseTypeFromSchema(schemaWithoutOneOf, baseName), union].filter(Boolean)
|
|
187
|
+
});
|
|
188
|
+
}
|
|
175
189
|
return tsCodegen.createIntersectionDeclaration({
|
|
176
|
-
nodes: [
|
|
177
|
-
this.getBaseTypeFromSchema(schemaWithoutOneOf, baseName),
|
|
178
|
-
factory2.createParenthesizedType(
|
|
179
|
-
tsCodegen.createUnionDeclaration({
|
|
180
|
-
nodes: schema.oneOf.map((item) => {
|
|
181
|
-
return this.getBaseTypeFromSchema(item);
|
|
182
|
-
}).filter(Boolean)
|
|
183
|
-
})
|
|
184
|
-
)
|
|
185
|
-
].filter(Boolean)
|
|
190
|
+
nodes: [union]
|
|
186
191
|
});
|
|
187
192
|
}
|
|
188
193
|
if (schema.anyOf) ;
|
|
189
194
|
if (schema.allOf) {
|
|
190
195
|
const schemaWithoutAllOf = { ...schema, allOf: void 0 };
|
|
196
|
+
const and = factory2.createParenthesizedType(
|
|
197
|
+
factory2.createIntersectionTypeNode(
|
|
198
|
+
schema.allOf.map((item) => {
|
|
199
|
+
return this.getBaseTypeFromSchema(item);
|
|
200
|
+
}).filter(Boolean)
|
|
201
|
+
)
|
|
202
|
+
);
|
|
203
|
+
if (schemaWithoutAllOf.properties) {
|
|
204
|
+
return tsCodegen.createIntersectionDeclaration({
|
|
205
|
+
nodes: [this.getBaseTypeFromSchema(schemaWithoutAllOf, baseName), and].filter(Boolean)
|
|
206
|
+
});
|
|
207
|
+
}
|
|
191
208
|
return tsCodegen.createIntersectionDeclaration({
|
|
192
|
-
nodes: [
|
|
193
|
-
this.getBaseTypeFromSchema(schemaWithoutAllOf, baseName),
|
|
194
|
-
factory2.createParenthesizedType(
|
|
195
|
-
factory2.createIntersectionTypeNode(
|
|
196
|
-
schema.allOf.map((item) => {
|
|
197
|
-
return this.getBaseTypeFromSchema(item);
|
|
198
|
-
}).filter(Boolean)
|
|
199
|
-
)
|
|
200
|
-
)
|
|
201
|
-
].filter(Boolean)
|
|
209
|
+
nodes: [and]
|
|
202
210
|
});
|
|
203
211
|
}
|
|
204
212
|
if (schema.enum && baseName) {
|
package/dist/index.js
CHANGED
|
@@ -110,7 +110,9 @@ var _TypeGenerator = class extends SchemaGenerator {
|
|
|
110
110
|
comments: [
|
|
111
111
|
schema.description && `@description ${schema.description}`,
|
|
112
112
|
schema.type && `@type ${schema.type}${isRequired ? "" : " | undefined"} ${schema.format || ""}`,
|
|
113
|
-
schema.example && `@example ${schema.example}
|
|
113
|
+
schema.example && `@example ${schema.example}`,
|
|
114
|
+
schema.default !== void 0 && typeof schema.default === "string" && `@default '${schema.default}'`,
|
|
115
|
+
schema.default !== void 0 && typeof schema.default !== "string" && `@default ${schema.default}`
|
|
114
116
|
]
|
|
115
117
|
});
|
|
116
118
|
}
|
|
@@ -162,33 +164,39 @@ var _TypeGenerator = class extends SchemaGenerator {
|
|
|
162
164
|
}
|
|
163
165
|
if (schema.oneOf) {
|
|
164
166
|
const schemaWithoutOneOf = { ...schema, oneOf: void 0 };
|
|
167
|
+
const union = factory2.createParenthesizedType(
|
|
168
|
+
createUnionDeclaration({
|
|
169
|
+
nodes: schema.oneOf.map((item) => {
|
|
170
|
+
return this.getBaseTypeFromSchema(item);
|
|
171
|
+
}).filter(Boolean)
|
|
172
|
+
})
|
|
173
|
+
);
|
|
174
|
+
if (schemaWithoutOneOf.properties) {
|
|
175
|
+
return createIntersectionDeclaration({
|
|
176
|
+
nodes: [this.getBaseTypeFromSchema(schemaWithoutOneOf, baseName), union].filter(Boolean)
|
|
177
|
+
});
|
|
178
|
+
}
|
|
165
179
|
return createIntersectionDeclaration({
|
|
166
|
-
nodes: [
|
|
167
|
-
this.getBaseTypeFromSchema(schemaWithoutOneOf, baseName),
|
|
168
|
-
factory2.createParenthesizedType(
|
|
169
|
-
createUnionDeclaration({
|
|
170
|
-
nodes: schema.oneOf.map((item) => {
|
|
171
|
-
return this.getBaseTypeFromSchema(item);
|
|
172
|
-
}).filter(Boolean)
|
|
173
|
-
})
|
|
174
|
-
)
|
|
175
|
-
].filter(Boolean)
|
|
180
|
+
nodes: [union]
|
|
176
181
|
});
|
|
177
182
|
}
|
|
178
183
|
if (schema.anyOf) ;
|
|
179
184
|
if (schema.allOf) {
|
|
180
185
|
const schemaWithoutAllOf = { ...schema, allOf: void 0 };
|
|
186
|
+
const and = factory2.createParenthesizedType(
|
|
187
|
+
factory2.createIntersectionTypeNode(
|
|
188
|
+
schema.allOf.map((item) => {
|
|
189
|
+
return this.getBaseTypeFromSchema(item);
|
|
190
|
+
}).filter(Boolean)
|
|
191
|
+
)
|
|
192
|
+
);
|
|
193
|
+
if (schemaWithoutAllOf.properties) {
|
|
194
|
+
return createIntersectionDeclaration({
|
|
195
|
+
nodes: [this.getBaseTypeFromSchema(schemaWithoutAllOf, baseName), and].filter(Boolean)
|
|
196
|
+
});
|
|
197
|
+
}
|
|
181
198
|
return createIntersectionDeclaration({
|
|
182
|
-
nodes: [
|
|
183
|
-
this.getBaseTypeFromSchema(schemaWithoutAllOf, baseName),
|
|
184
|
-
factory2.createParenthesizedType(
|
|
185
|
-
factory2.createIntersectionTypeNode(
|
|
186
|
-
schema.allOf.map((item) => {
|
|
187
|
-
return this.getBaseTypeFromSchema(item);
|
|
188
|
-
}).filter(Boolean)
|
|
189
|
-
)
|
|
190
|
-
)
|
|
191
|
-
].filter(Boolean)
|
|
199
|
+
nodes: [and]
|
|
192
200
|
});
|
|
193
201
|
}
|
|
194
202
|
if (schema.enum && baseName) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/swagger-ts",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Generator swagger-ts",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
"change-case": "^4.1.2",
|
|
42
42
|
"lodash.uniqueid": "^4.0.1",
|
|
43
43
|
"typescript": "^5.1.3",
|
|
44
|
-
"@kubb/core": "1.
|
|
45
|
-
"@kubb/swagger": "1.
|
|
46
|
-
"@kubb/ts-codegen": "1.
|
|
44
|
+
"@kubb/core": "1.1.1",
|
|
45
|
+
"@kubb/swagger": "1.1.1",
|
|
46
|
+
"@kubb/ts-codegen": "1.1.1"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@types/lodash.uniqueid": "^4.0.7",
|
|
@@ -138,6 +138,8 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
|
|
|
138
138
|
schema.description && `@description ${schema.description}`,
|
|
139
139
|
schema.type && `@type ${schema.type}${isRequired ? '' : ' | undefined'} ${schema.format || ''}`,
|
|
140
140
|
schema.example && `@example ${schema.example}`,
|
|
141
|
+
schema.default !== undefined && typeof schema.default === 'string' && `@default '${schema.default}'`,
|
|
142
|
+
schema.default !== undefined && typeof schema.default !== 'string' && `@default ${schema.default}`,
|
|
141
143
|
],
|
|
142
144
|
})
|
|
143
145
|
}
|
|
@@ -205,19 +207,24 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
|
|
|
205
207
|
// union
|
|
206
208
|
const schemaWithoutOneOf = { ...schema, oneOf: undefined }
|
|
207
209
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
nodes: schema.oneOf
|
|
214
|
-
.map((item) => {
|
|
215
|
-
return this.getBaseTypeFromSchema(item)
|
|
216
|
-
})
|
|
217
|
-
.filter(Boolean) as ts.TypeNode[],
|
|
210
|
+
const union = factory.createParenthesizedType(
|
|
211
|
+
createUnionDeclaration({
|
|
212
|
+
nodes: schema.oneOf
|
|
213
|
+
.map((item) => {
|
|
214
|
+
return this.getBaseTypeFromSchema(item)
|
|
218
215
|
})
|
|
219
|
-
|
|
220
|
-
|
|
216
|
+
.filter(Boolean) as ts.TypeNode[],
|
|
217
|
+
})
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
if (schemaWithoutOneOf.properties) {
|
|
221
|
+
return createIntersectionDeclaration({
|
|
222
|
+
nodes: [this.getBaseTypeFromSchema(schemaWithoutOneOf, baseName), union].filter(Boolean) as ts.TypeNode[],
|
|
223
|
+
})
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return createIntersectionDeclaration({
|
|
227
|
+
nodes: [union],
|
|
221
228
|
})
|
|
222
229
|
}
|
|
223
230
|
|
|
@@ -228,19 +235,24 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
|
|
|
228
235
|
// intersection/add
|
|
229
236
|
const schemaWithoutAllOf = { ...schema, allOf: undefined }
|
|
230
237
|
|
|
238
|
+
const and = factory.createParenthesizedType(
|
|
239
|
+
factory.createIntersectionTypeNode(
|
|
240
|
+
schema.allOf
|
|
241
|
+
.map((item) => {
|
|
242
|
+
return this.getBaseTypeFromSchema(item)
|
|
243
|
+
})
|
|
244
|
+
.filter(Boolean) as ts.TypeNode[]
|
|
245
|
+
)
|
|
246
|
+
)
|
|
247
|
+
|
|
248
|
+
if (schemaWithoutAllOf.properties) {
|
|
249
|
+
return createIntersectionDeclaration({
|
|
250
|
+
nodes: [this.getBaseTypeFromSchema(schemaWithoutAllOf, baseName), and].filter(Boolean) as ts.TypeNode[],
|
|
251
|
+
})
|
|
252
|
+
}
|
|
253
|
+
|
|
231
254
|
return createIntersectionDeclaration({
|
|
232
|
-
nodes: [
|
|
233
|
-
this.getBaseTypeFromSchema(schemaWithoutAllOf, baseName),
|
|
234
|
-
factory.createParenthesizedType(
|
|
235
|
-
factory.createIntersectionTypeNode(
|
|
236
|
-
schema.allOf
|
|
237
|
-
.map((item) => {
|
|
238
|
-
return this.getBaseTypeFromSchema(item)
|
|
239
|
-
})
|
|
240
|
-
.filter(Boolean) as ts.TypeNode[]
|
|
241
|
-
)
|
|
242
|
-
),
|
|
243
|
-
].filter(Boolean) as ts.TypeNode[],
|
|
255
|
+
nodes: [and],
|
|
244
256
|
})
|
|
245
257
|
}
|
|
246
258
|
|
package/src/plugin.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { pascalCase, pascalCaseTransformMerge } from 'change-case'
|
|
|
8
8
|
|
|
9
9
|
import { getRelativePath, createPlugin, getPathMode, validatePlugins, writeIndexes, renderTemplate } from '@kubb/core'
|
|
10
10
|
import { pluginName as swaggerPluginName } from '@kubb/swagger'
|
|
11
|
-
import type {
|
|
11
|
+
import type { API as SwaggerApi, OpenAPIV3 } from '@kubb/swagger'
|
|
12
12
|
|
|
13
13
|
import { TypeBuilder } from './builders/index.ts'
|
|
14
14
|
import { OperationGenerator } from './generators/index.ts'
|