@kubb/adapter-oas 5.0.0-beta.43 → 5.0.0-beta.45
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/index.cjs +23 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +23 -6
- package/dist/index.js.map +1 -1
- package/extension.yaml +5 -5
- package/package.json +3 -2
- package/src/parser.ts +7 -6
package/extension.yaml
CHANGED
|
@@ -295,14 +295,14 @@ options:
|
|
|
295
295
|
- name: integerType
|
|
296
296
|
type: "'number' | 'bigint'"
|
|
297
297
|
required: false
|
|
298
|
-
default: "'
|
|
298
|
+
default: "'bigint'"
|
|
299
299
|
description: |
|
|
300
300
|
How `type: integer` (and `format: int64`) maps to TypeScript.
|
|
301
301
|
|
|
302
|
-
- `'
|
|
303
|
-
- `'
|
|
302
|
+
- `'bigint'` (default) — exact for 64-bit IDs, but `JSON.stringify`/`JSON.parse` cannot round-trip it. Use only when you also handle bigint serialization explicitly.
|
|
303
|
+
- `'number'` — fits most JSON APIs; loses precision above `Number.MAX_SAFE_INTEGER`.
|
|
304
304
|
examples:
|
|
305
|
-
- name: "'number'
|
|
305
|
+
- name: "'number'"
|
|
306
306
|
files:
|
|
307
307
|
- lang: typescript
|
|
308
308
|
twoslash: false
|
|
@@ -310,7 +310,7 @@ options:
|
|
|
310
310
|
type Pet = {
|
|
311
311
|
id: number
|
|
312
312
|
}
|
|
313
|
-
- name: "'bigint'"
|
|
313
|
+
- name: "'bigint' (default)"
|
|
314
314
|
files:
|
|
315
315
|
- lang: typescript
|
|
316
316
|
twoslash: false
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/adapter-oas",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.45",
|
|
4
4
|
"description": "OpenAPI and Swagger adapter for Kubb. Parses and validates OAS 2.0/3.x specifications into a @kubb/ast RootNode for downstream code generation plugins.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adapter",
|
|
@@ -47,7 +47,8 @@
|
|
|
47
47
|
"oas": "^32.1.18",
|
|
48
48
|
"oas-normalize": "^16.0.5",
|
|
49
49
|
"swagger2openapi": "^7.0.8",
|
|
50
|
-
"@kubb/
|
|
50
|
+
"@kubb/ast": "5.0.0-beta.45",
|
|
51
|
+
"@kubb/core": "5.0.0-beta.45"
|
|
51
52
|
},
|
|
52
53
|
"devDependencies": {
|
|
53
54
|
"@types/swagger2openapi": "^7.0.4",
|
package/src/parser.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { pascalCase, URLPath } from '@internals/utils'
|
|
2
|
+
import { childName, enumPropName, extractRefName, findDiscriminator } from '@kubb/ast/utils'
|
|
2
3
|
import { ast } from '@kubb/core'
|
|
3
4
|
import BaseOas from 'oas'
|
|
4
5
|
import { DEFAULT_PARSER_OPTIONS, enumExtensionKeys, SCHEMA_REF_PREFIX, typeOptionMap } from './constants.ts'
|
|
@@ -146,7 +147,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
|
|
|
146
147
|
return ast.createSchema({
|
|
147
148
|
...buildSchemaNode(schema, name, nullable, defaultValue),
|
|
148
149
|
type: 'ref',
|
|
149
|
-
name:
|
|
150
|
+
name: extractRefName(schema.$ref!),
|
|
150
151
|
ref: schema.$ref,
|
|
151
152
|
schema: resolvedSchema,
|
|
152
153
|
})
|
|
@@ -199,7 +200,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
|
|
|
199
200
|
const inOneOf = parentUnion.some((oneOfItem) => dialect.isReference(oneOfItem) && oneOfItem.$ref === childRef)
|
|
200
201
|
const inMapping = Object.values(deref.discriminator.mapping ?? {}).some((v) => v === childRef)
|
|
201
202
|
if (inOneOf || inMapping) {
|
|
202
|
-
const discriminatorValue =
|
|
203
|
+
const discriminatorValue = findDiscriminator(deref.discriminator.mapping, childRef)
|
|
203
204
|
if (discriminatorValue) {
|
|
204
205
|
filteredDiscriminantValues.push({
|
|
205
206
|
propertyName: deref.discriminator.propertyName,
|
|
@@ -306,7 +307,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
|
|
|
306
307
|
if (sharedPropertiesNode || discriminator?.mapping) {
|
|
307
308
|
const members = unionMembers.map((s) => {
|
|
308
309
|
const ref = dialect.isReference(s) ? s.$ref : undefined
|
|
309
|
-
const discriminatorValue =
|
|
310
|
+
const discriminatorValue = findDiscriminator(discriminator?.mapping, ref)
|
|
310
311
|
const memberNode = parseSchema({ schema: s as SchemaObject, name }, rawOptions)
|
|
311
312
|
|
|
312
313
|
if (!discriminatorValue || !discriminator) {
|
|
@@ -568,7 +569,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
|
|
|
568
569
|
const resolvedPropSchema = propSchema as SchemaObject
|
|
569
570
|
const propNullable = dialect.isNullable(resolvedPropSchema)
|
|
570
571
|
|
|
571
|
-
const resolvedChildName =
|
|
572
|
+
const resolvedChildName = childName(name, propName)
|
|
572
573
|
const propNode = parseSchema({ schema: resolvedPropSchema, name: resolvedChildName }, rawOptions)
|
|
573
574
|
const schemaNode = (() => {
|
|
574
575
|
const node = ast.setEnumName(propNode, name, propName, options.enumSuffix)
|
|
@@ -633,7 +634,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
|
|
|
633
634
|
if (dialect.isDiscriminator(schema) && schema.discriminator.mapping) {
|
|
634
635
|
const discPropName = schema.discriminator.propertyName
|
|
635
636
|
const values = Object.keys(schema.discriminator.mapping)
|
|
636
|
-
const enumName = name ?
|
|
637
|
+
const enumName = name ? enumPropName(name, discPropName, options.enumSuffix) : undefined
|
|
637
638
|
return ast.setDiscriminatorEnum({
|
|
638
639
|
node: objectNode,
|
|
639
640
|
propertyName: discPropName,
|
|
@@ -668,7 +669,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
|
|
|
668
669
|
*/
|
|
669
670
|
function convertArray({ schema, name, nullable, defaultValue, rawOptions, options }: SchemaContext): ast.SchemaNode {
|
|
670
671
|
const rawItems = schema.items as SchemaObject | undefined
|
|
671
|
-
const itemName = rawItems?.enum?.length && name ?
|
|
672
|
+
const itemName = rawItems?.enum?.length && name ? enumPropName(null, name, options.enumSuffix) : name
|
|
672
673
|
const items = rawItems ? [parseSchema({ schema: rawItems, name: itemName }, rawOptions)] : []
|
|
673
674
|
|
|
674
675
|
return ast.createSchema({
|