@kubb/swagger-ts 2.0.0-beta.4 → 2.0.0-beta.6
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/dist/components.cjs +13 -5
- package/dist/components.cjs.map +1 -1
- package/dist/components.js +14 -5
- package/dist/components.js.map +1 -1
- package/dist/index.cjs +13 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +14 -5
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/TypeGenerator.ts +25 -5
- package/src/components/Mutation.tsx +1 -1
- package/src/components/Query.tsx +1 -2
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@kubb/swagger-ts",
|
3
|
-
"version": "2.0.0-beta.
|
3
|
+
"version": "2.0.0-beta.6",
|
4
4
|
"description": "Generator swagger-ts",
|
5
5
|
"keywords": [
|
6
6
|
"typescript",
|
@@ -44,10 +44,10 @@
|
|
44
44
|
],
|
45
45
|
"dependencies": {
|
46
46
|
"typescript": "^5.3.2",
|
47
|
-
"@kubb/core": "2.0.0-beta.
|
48
|
-
"@kubb/parser": "2.0.0-beta.
|
49
|
-
"@kubb/react": "2.0.0-beta.
|
50
|
-
"@kubb/swagger": "2.0.0-beta.
|
47
|
+
"@kubb/core": "2.0.0-beta.6",
|
48
|
+
"@kubb/parser": "2.0.0-beta.6",
|
49
|
+
"@kubb/react": "2.0.0-beta.6",
|
50
|
+
"@kubb/swagger": "2.0.0-beta.6"
|
51
51
|
},
|
52
52
|
"devDependencies": {
|
53
53
|
"@types/react": "^18.2.38",
|
@@ -60,7 +60,7 @@
|
|
60
60
|
},
|
61
61
|
"peerDependencies": {
|
62
62
|
"typescript": "^5.3.0",
|
63
|
-
"@kubb/react": "2.0.0-beta.
|
63
|
+
"@kubb/react": "2.0.0-beta.6"
|
64
64
|
},
|
65
65
|
"packageManager": "pnpm@8.3.0",
|
66
66
|
"engines": {
|
package/src/TypeGenerator.ts
CHANGED
@@ -2,6 +2,7 @@ import { Generator } from '@kubb/core'
|
|
2
2
|
import transformers from '@kubb/core/transformers'
|
3
3
|
import { getUniqueName } from '@kubb/core/utils'
|
4
4
|
import * as factory from '@kubb/parser/factory'
|
5
|
+
import { keywordTypeNodes } from '@kubb/parser/factory'
|
5
6
|
import { getSchemaFactory, isReference } from '@kubb/swagger/utils'
|
6
7
|
|
7
8
|
import { pluginKey } from './plugin.ts'
|
@@ -332,8 +333,32 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
|
|
332
333
|
return this.#getTypeFromProperties(schema, baseName)
|
333
334
|
}
|
334
335
|
|
336
|
+
/**
|
337
|
+
* validate "const" property as defined in JSON-Schema-Validation
|
338
|
+
*
|
339
|
+
* https://json-schema.org/draft/2020-12/json-schema-validation#name-const
|
340
|
+
*
|
341
|
+
* > 6.1.3. const
|
342
|
+
* > The value of this keyword MAY be of any type, including null.
|
343
|
+
* > Use of this keyword is functionally equivalent to an "enum" (Section 6.1.2) with a single value.
|
344
|
+
* > An instance validates successfully against this keyword if its value is equal to the value of the keyword.
|
345
|
+
*/
|
346
|
+
if (version === '3.1' && 'const' in schema) {
|
347
|
+
// const keyword takes precendence over the actual type.
|
348
|
+
if (schema['const']) {
|
349
|
+
if (typeof schema['const'] === 'string') {
|
350
|
+
return factory.createLiteralTypeNode(factory.createStringLiteral(schema['const']))
|
351
|
+
} else if (typeof schema['const'] === 'number') {
|
352
|
+
return factory.createLiteralTypeNode(factory.createNumericLiteral(schema['const']))
|
353
|
+
}
|
354
|
+
} else {
|
355
|
+
return keywordTypeNodes.null
|
356
|
+
}
|
357
|
+
}
|
358
|
+
|
335
359
|
if (schema.type) {
|
336
360
|
if (Array.isArray(schema.type)) {
|
361
|
+
// TODO remove hardcoded first type, second nullable
|
337
362
|
// OPENAPI v3.1.0: https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0
|
338
363
|
const [type, nullable] = schema.type as Array<OpenAPIV3_1.NonArraySchemaObjectType>
|
339
364
|
|
@@ -365,11 +390,6 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
|
|
365
390
|
return factory.createTypeReferenceNode('Blob', [])
|
366
391
|
}
|
367
392
|
|
368
|
-
// detect assertion "const" and define the type property as a Literal
|
369
|
-
if (version === '3.1' && typeof schema['const'] === 'string') {
|
370
|
-
return factory.createLiteralTypeNode(factory.createStringLiteral(schema['const']))
|
371
|
-
}
|
372
|
-
|
373
393
|
return factory.keywordTypeNodes.any
|
374
394
|
}
|
375
395
|
}
|
@@ -6,11 +6,11 @@ import { useOas, useOperation, useOperationFile, useOperationName, useSchemas }
|
|
6
6
|
|
7
7
|
import { TypeBuilder } from '../TypeBuilder.ts'
|
8
8
|
|
9
|
+
import type { KubbFile } from '@kubb/core'
|
9
10
|
import type { ts } from '@kubb/parser'
|
10
11
|
import type { Operation, OperationSchemas } from '@kubb/swagger'
|
11
12
|
import type { ReactNode } from 'react'
|
12
13
|
import type { FileMeta, PluginOptions } from '../types.ts'
|
13
|
-
import type { KubbFile } from '@kubb/core'
|
14
14
|
|
15
15
|
type Props = {
|
16
16
|
builder: TypeBuilder
|
package/src/components/Query.tsx
CHANGED
@@ -6,11 +6,11 @@ import { useOas, useOperation, useOperationFile, useOperationName, useSchemas }
|
|
6
6
|
|
7
7
|
import { TypeBuilder } from '../TypeBuilder.ts'
|
8
8
|
|
9
|
+
import type { KubbFile } from '@kubb/core'
|
9
10
|
import type { ts } from '@kubb/parser'
|
10
11
|
import type { Operation, OperationSchemas } from '@kubb/swagger'
|
11
12
|
import type { ReactNode } from 'react'
|
12
13
|
import type { FileMeta, PluginOptions } from '../types.ts'
|
13
|
-
import type { KubbFile } from '@kubb/core'
|
14
14
|
|
15
15
|
type Props = {
|
16
16
|
builder: TypeBuilder
|
@@ -93,7 +93,6 @@ export function Query({
|
|
93
93
|
)
|
94
94
|
}
|
95
95
|
|
96
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
97
96
|
type FileProps = {
|
98
97
|
mode: KubbFile.Mode
|
99
98
|
}
|