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)) {
|
||||
const $ref = `#/components/schemas/${schema.ref}`;
|
||||
if (schema.nullable || schema.optional) {
|
||||
res.allOf = [{ $ref }];
|
||||
if (schema.nullable) {
|
||||
res.oneOf = [{ $ref }, { type: 'null' }];
|
||||
} else {
|
||||
res.$ref = $ref;
|
||||
}
|
||||
}
|
||||
|
||||
if (schema.nullable) {
|
||||
delete res.type;
|
||||
} else if (schema.nullable) {
|
||||
if (Array.isArray(schema.type) && !schema.type.includes('null')) {
|
||||
res.type.push('null');
|
||||
} else if (typeof schema.type === 'string') {
|
||||
|
|
Loading…
Reference in New Issue