Skip to content

Commit

Permalink
OpenAPI generator supports anyOf as oneOf
Browse files Browse the repository at this point in the history
  • Loading branch information
gius committed Feb 21, 2023
1 parent 61ce345 commit adf52b1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/generator/src/openapi/fileGenerator.ts
Expand Up @@ -33,6 +33,7 @@ export default class FileGenerator {
eq: (a: unknown, b: unknown) => a == b,
ne: (a: unknown, b: unknown) => a != b,
coalesce: (...args) => Array.prototype.find.call(args, x => !!x) as string,
inline: (x: string) => (x ? x.replaceAll(/\r?\n/g, " ").trim() : ""),
});
}

Expand Down
7 changes: 6 additions & 1 deletion packages/generator/src/openapi/parsers/openApi3Parser.ts
Expand Up @@ -77,7 +77,7 @@ export default class OpenApi3Parser implements ApiModel {
return this.setTypeReference(name, definition.type);
}

if (definition.oneOf || definition.allOf) {
if (definition.oneOf || definition.anyOf || definition.allOf) {
return this.parseObject(name, definition);
}

Expand Down Expand Up @@ -105,6 +105,11 @@ export default class OpenApi3Parser implements ApiModel {
if (definition.oneOf) {
return this.parseOneOfObject(name, definition);
}
if (definition.anyOf) {
// handle anyOf the same as oneOf
definition.oneOf = definition.anyOf;
return this.parseOneOfObject(name, definition);
}

return this.parseObjectWithProperties(name, definition);
}
Expand Down
Expand Up @@ -58,7 +58,7 @@ z.preprocess(arg => (typeof arg == "string" || arg instanceof Date ? new Date(ar
{{~/if}}
{{#if description}}

.describe("{{description}}")
.describe("{{inline description}}")
{{~/if}}
,
{{/inline}}
Expand Down

0 comments on commit adf52b1

Please sign in to comment.