这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/chilled-wolves-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hey-api/openapi-ts": patch
---

parser: merge `default` keyword with `$ref` in OpenAPI 3.1
Original file line number Diff line number Diff line change
Expand Up @@ -1455,7 +1455,9 @@ export const vCallWithDefaultParametersData = v.object({
'Error'
])),
parameterModel: v.optional(v.union([
vModelWithString,
v.optional(vModelWithString, {
prop: 'Hello World!'
}),
v.null()
]))
}))
Expand All @@ -1473,7 +1475,9 @@ export const vCallWithDefaultOptionalParametersData = v.object({
'Warning',
'Error'
])),
parameterModel: v.optional(vModelWithString)
parameterModel: v.optional(vModelWithString, {
prop: 'Hello World!'
})
}))
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,9 @@ export const zCallWithDefaultParametersData = z.object({
'Error'
])),
parameterModel: z.optional(z.union([
zModelWithString,
z._default(zModelWithString, {
prop: 'Hello World!'
}),
z.null()
]))
}))
Expand All @@ -1504,7 +1506,9 @@ export const zCallWithDefaultOptionalParametersData = z.object({
'Warning',
'Error'
])),
parameterModel: z.optional(zModelWithString)
parameterModel: z._default(z.optional(zModelWithString), {
prop: 'Hello World!'
})
}))
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,9 @@ export const zCallWithDefaultParametersData = z.object({
'Error'
]).optional(),
parameterModel: z.union([
zModelWithString,
zModelWithString.default({
prop: 'Hello World!'
}),
z.null()
]).optional()
}).optional()
Expand All @@ -1502,7 +1504,9 @@ export const zCallWithDefaultOptionalParametersData = z.object({
'Warning',
'Error'
]).optional(),
parameterModel: zModelWithString.optional()
parameterModel: zModelWithString.optional().default({
prop: 'Hello World!'
})
}).optional()
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,9 @@ export const zCallWithDefaultParametersData = z.object({
'Error'
])),
parameterModel: z.optional(z.union([
zModelWithString,
zModelWithString.default({
prop: 'Hello World!'
}),
z.null()
]))
}))
Expand All @@ -1504,7 +1506,9 @@ export const zCallWithDefaultOptionalParametersData = z.object({
'Warning',
'Error'
])),
parameterModel: z.optional(zModelWithString)
parameterModel: z.optional(zModelWithString).default({
prop: 'Hello World!'
})
}))
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,9 @@ export const zCallWithDefaultParametersData = z.object({
'Error'
])),
parameterModel: z.optional(z.union([
zModelWithString,
z._default(zModelWithString, {
prop: 'Hello World!'
}),
z.null()
]))
}))
Expand All @@ -1504,7 +1506,9 @@ export const zCallWithDefaultOptionalParametersData = z.object({
'Warning',
'Error'
])),
parameterModel: z.optional(zModelWithString)
parameterModel: z._default(z.optional(zModelWithString), {
prop: 'Hello World!'
})
}))
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// This file is auto-generated by @hey-api/openapi-ts

import * as z from 'zod/mini';

export const zAudioFormat = z.enum([
'pcm_16bit_44.1khz',
'pcm_16bit_24khz'
]);

export const zLanguage = z.enum([
'en',
'es',
'fr'
]);

export const zNestedConfig = z.object({
model: z._default(z.string(), 'gpt-4'),
temperature: z._default(z.number(), 1)
});

export const zTestSchema = z.object({
primitiveDefault: z._default(z.number(), 42),
refWithPrimitiveDefault: z._default(zAudioFormat, 'pcm_16bit_44.1khz'),
refWithObjectDefault: z._default(zNestedConfig, {
model: 'gpt-4',
temperature: 1
}),
anyOfWithNullDefault: z._default(z.union([
z.number(),
z.null()
]), null),
anyOfWithRefAndNullDefault: z._default(z.union([
zLanguage,
z.null()
]), null),
optionalAnyOfWithDefault: z._default(z.optional(z.union([
z.string(),
z.null()
])), null)
});
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,9 @@ export const zCallWithDefaultParametersData = z.object({
'Error'
]).optional(),
parameterModel: z.union([
zModelWithString,
zModelWithString.default({
prop: 'Hello World!'
}),
z.null()
]).optional()
}).optional()
Expand All @@ -1502,7 +1504,9 @@ export const zCallWithDefaultOptionalParametersData = z.object({
'Warning',
'Error'
]).optional(),
parameterModel: zModelWithString.optional()
parameterModel: zModelWithString.optional().default({
prop: 'Hello World!'
})
}).optional()
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// This file is auto-generated by @hey-api/openapi-ts

import { z } from 'zod/v3';

export const zAudioFormat = z.enum([
'pcm_16bit_44.1khz',
'pcm_16bit_24khz'
]);

export const zLanguage = z.enum([
'en',
'es',
'fr'
]);

export const zNestedConfig = z.object({
model: z.string().default('gpt-4'),
temperature: z.number().default(1)
});

export const zTestSchema = z.object({
primitiveDefault: z.number().default(42),
refWithPrimitiveDefault: zAudioFormat.default('pcm_16bit_44.1khz'),
refWithObjectDefault: zNestedConfig.default({
model: 'gpt-4',
temperature: 1
}),
anyOfWithNullDefault: z.union([
z.number(),
z.null()
]).default(null),
anyOfWithRefAndNullDefault: z.union([
zLanguage,
z.null()
]).default(null),
optionalAnyOfWithDefault: z.union([
z.string(),
z.null()
]).optional().default(null)
});
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,9 @@ export const zCallWithDefaultParametersData = z.object({
'Error'
])),
parameterModel: z.optional(z.union([
zModelWithString,
zModelWithString.default({
prop: 'Hello World!'
}),
z.null()
]))
}))
Expand All @@ -1504,7 +1506,9 @@ export const zCallWithDefaultOptionalParametersData = z.object({
'Warning',
'Error'
])),
parameterModel: z.optional(zModelWithString)
parameterModel: z.optional(zModelWithString).default({
prop: 'Hello World!'
})
}))
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// This file is auto-generated by @hey-api/openapi-ts

import { z } from 'zod';

export const zAudioFormat = z.enum([
'pcm_16bit_44.1khz',
'pcm_16bit_24khz'
]);

export const zLanguage = z.enum([
'en',
'es',
'fr'
]);

export const zNestedConfig = z.object({
model: z.string().default('gpt-4'),
temperature: z.number().default(1)
});

export const zTestSchema = z.object({
primitiveDefault: z.number().default(42),
refWithPrimitiveDefault: zAudioFormat.default('pcm_16bit_44.1khz'),
refWithObjectDefault: zNestedConfig.default({
model: 'gpt-4',
temperature: 1
}),
anyOfWithNullDefault: z.union([
z.number(),
z.null()
]).default(null),
anyOfWithRefAndNullDefault: z.union([
zLanguage,
z.null()
]).default(null),
optionalAnyOfWithDefault: z.optional(z.union([
z.string(),
z.null()
])).default(null)
});
7 changes: 7 additions & 0 deletions packages/openapi-ts-tests/zod/v4/test/3.1.x.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ for (const zodVersion of zodVersions) {
description:
'generates correct array when items are oneOf array with single item',
},
{
config: createConfig({
input: 'defaults-with-ref-and-anyof.json',
output: 'defaults-with-ref-and-anyof',
}),
description: 'preserves defaults with $ref and anyOf',
},
{
config: createConfig({
input: 'enum-null.json',
Expand Down
4 changes: 4 additions & 0 deletions packages/openapi-ts/src/openApi/3.1.x/parser/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ const parseAllOf = ({
state: SchemaState;
}): IR.SchemaObject => {
let irSchema = initIrSchema({ schema });
parseSchemaMeta({ irSchema, schema });

const schemaItems: Array<IR.SchemaObject> = [];
const schemaTypes = getSchemaTypes({ schema });
Expand Down Expand Up @@ -543,6 +544,7 @@ const parseAnyOf = ({
state: SchemaState;
}): IR.SchemaObject => {
let irSchema = initIrSchema({ schema });
parseSchemaMeta({ irSchema, schema });

const schemaItems: Array<IR.SchemaObject> = [];
const schemaTypes = getSchemaTypes({ schema });
Expand Down Expand Up @@ -699,6 +701,7 @@ const parseOneOf = ({
state: SchemaState;
}): IR.SchemaObject => {
let irSchema = initIrSchema({ schema });
parseSchemaMeta({ irSchema, schema });

let schemaItems: Array<IR.SchemaObject> = [];
const schemaTypes = getSchemaTypes({ schema });
Expand Down Expand Up @@ -817,6 +820,7 @@ const parseRef = ({
}

let irSchema = initIrSchema({ schema });
parseSchemaMeta({ irSchema, schema });

const irRefSchema: IR.SchemaObject = {};

Expand Down
Loading
Loading