@kubb/adapter-oas 5.0.0-beta.42 → 5.0.0-beta.44
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/package.json +6 -5
- package/src/parser.ts +7 -6
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.44",
|
|
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",
|
|
@@ -43,11 +43,12 @@
|
|
|
43
43
|
"registry": "https://registry.npmjs.org/"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@redocly/openapi-core": "^2.31.
|
|
46
|
+
"@redocly/openapi-core": "^2.31.6",
|
|
47
47
|
"oas": "^32.1.18",
|
|
48
|
-
"oas-normalize": "^16.0.
|
|
48
|
+
"oas-normalize": "^16.0.5",
|
|
49
49
|
"swagger2openapi": "^7.0.8",
|
|
50
|
-
"@kubb/
|
|
50
|
+
"@kubb/ast": "5.0.0-beta.44",
|
|
51
|
+
"@kubb/core": "5.0.0-beta.44"
|
|
51
52
|
},
|
|
52
53
|
"devDependencies": {
|
|
53
54
|
"@types/swagger2openapi": "^7.0.4",
|
|
@@ -63,7 +64,7 @@
|
|
|
63
64
|
"scripts": {
|
|
64
65
|
"bench": "vitest bench",
|
|
65
66
|
"build": "tsdown",
|
|
66
|
-
"clean": "
|
|
67
|
+
"clean": "node -e \"require('node:fs').rmSync('./dist', {recursive:true,force:true})\"",
|
|
67
68
|
"lint": "oxlint .",
|
|
68
69
|
"lint:fix": "oxlint --fix .",
|
|
69
70
|
"release": "pnpm publish --no-git-check",
|
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({
|