fix(backend): better nullable ref schema representation (#16088)
* fix(backend): better nullable ref schema representation * refactor
This commit is contained in:
parent
bbbc68a772
commit
9c98c13743
|
@ -38,14 +38,13 @@ export function convertSchemaToOpenApiSchema(schema: Schema, type: 'param' | 're
|
||||||
|
|
||||||
if (type === 'res' && schema.ref && (!schema.selfRef || includeSelfRef)) {
|
if (type === 'res' && schema.ref && (!schema.selfRef || includeSelfRef)) {
|
||||||
const $ref = `#/components/schemas/${schema.ref}`;
|
const $ref = `#/components/schemas/${schema.ref}`;
|
||||||
if (schema.nullable || schema.optional) {
|
if (schema.nullable) {
|
||||||
res.allOf = [{ $ref }];
|
res.oneOf = [{ $ref }, { type: 'null' }];
|
||||||
} else {
|
} else {
|
||||||
res.$ref = $ref;
|
res.$ref = $ref;
|
||||||
}
|
}
|
||||||
}
|
delete res.type;
|
||||||
|
} else if (schema.nullable) {
|
||||||
if (schema.nullable) {
|
|
||||||
if (Array.isArray(schema.type) && !schema.type.includes('null')) {
|
if (Array.isArray(schema.type) && !schema.type.includes('null')) {
|
||||||
res.type.push('null');
|
res.type.push('null');
|
||||||
} else if (typeof schema.type === 'string') {
|
} else if (typeof schema.type === 'string') {
|
||||||
|
|
Loading…
Reference in New Issue