fix openAPI schema generation
This commit is contained in:
parent
c82beceee1
commit
ac196d5c6a
2 changed files with 5 additions and 5 deletions
|
|
@ -10,7 +10,7 @@ import { getSchemas, convertSchemaToOpenApiSchema } from './schemas.js';
|
|||
|
||||
export function genOpenapiSpec(config: Config, includeSelfRef = false) {
|
||||
const spec = {
|
||||
openapi: '3.1.0',
|
||||
openapi: '3.1',
|
||||
|
||||
info: {
|
||||
version: config.version,
|
||||
|
|
|
|||
|
|
@ -38,14 +38,14 @@ export function convertSchemaToOpenApiSchema(schema: Schema, type: 'param' | 're
|
|||
|
||||
if (type === 'res' && schema.ref && (!schema.selfRef || includeSelfRef)) {
|
||||
const $ref = `#/components/schemas/${schema.ref}`;
|
||||
// https://stackoverflow.com/a/23737104
|
||||
if (schema.nullable || schema.optional) {
|
||||
res.allOf = [{ $ref }];
|
||||
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…
Add table
Add a link
Reference in a new issue