Skip to content

Fix anyOf transformation #895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2022
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
2 changes: 1 addition & 1 deletion src/transform/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export function transformAnyOf(anyOf: any, options: TransformSchemaObjOptions):
if (schemas.length === 0) {
return "";
}
return tsIntersectionOf(schemas.map((s: any) => tsPartial(transformSchemaObj(s, options))));
return tsUnionOf(schemas.map((s: any) => transformSchemaObj(s, options)));
}

/** transform oneOf */
Expand Down
8 changes: 4 additions & 4 deletions test/core/schema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ describe("SchemaObject", () => {
{ ...defaults }
)
).to.equal(
`(Partial<components["schemas"]["StringType"]>) & (Partial<components["schemas"]["NumberType"]>) & (Partial<components["schemas"]["BooleanType"]>)`
`(components["schemas"]["StringType"]) | (components["schemas"]["NumberType"]) | (components["schemas"]["BooleanType"])`
);
});

Expand Down Expand Up @@ -374,13 +374,13 @@ describe("SchemaObject", () => {
},
{ ...defaults }
)
).to.equal(`((Partial<{
).to.equal(`(({
"b": string;

}>) & (Partial<{
}) | ({
"c": string;

}>)) & ({
})) & ({
"a"?: string;

})`);
Expand Down
34 changes: 34 additions & 0 deletions test/v3/expected/any-of.additional.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* This file was auto-generated by openapi-typescript.
* Do not make direct changes to the file.
*/

export interface paths {
'/cats': {
post: {
responses: {
200: {
content: {
'application/json': {
id: string
name: string
colors: (
| string[]
| {
id: string
name: string
}[]
) & { [key: string]: unknown }
}
}
}
}
}
}
}

export interface components {}

export interface operations {}

export interface external {}
33 changes: 33 additions & 0 deletions test/v3/expected/any-of.exported-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* This file was auto-generated by openapi-typescript.
* Do not make direct changes to the file.
*/

export type paths = {
'/cats': {
post: {
responses: {
200: {
content: {
'application/json': {
id: string
name: string
colors:
| string[]
| {
id: string
name: string
}[]
}
}
}
}
}
}
}

export type components = {}

export type operations = {}

export type external = {}
33 changes: 33 additions & 0 deletions test/v3/expected/any-of.immutable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* This file was auto-generated by openapi-typescript.
* Do not make direct changes to the file.
*/

export interface paths {
readonly '/cats': {
readonly post: {
readonly responses: {
readonly 200: {
readonly content: {
readonly 'application/json': {
readonly id: string
readonly name: string
readonly colors:
| readonly string[]
| readonly {
readonly id: string
readonly name: string
}[]
}
}
}
}
}
}
}

export interface components {}

export interface operations {}

export interface external {}
33 changes: 33 additions & 0 deletions test/v3/expected/any-of.support-array-length.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* This file was auto-generated by openapi-typescript.
* Do not make direct changes to the file.
*/

export interface paths {
'/cats': {
post: {
responses: {
200: {
content: {
'application/json': {
id: string
name: string
colors:
| string[]
| {
id: string
name: string
}[]
}
}
}
}
}
}
}

export interface components {}

export interface operations {}

export interface external {}
33 changes: 33 additions & 0 deletions test/v3/expected/any-of.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* This file was auto-generated by openapi-typescript.
* Do not make direct changes to the file.
*/

export interface paths {
'/cats': {
post: {
responses: {
200: {
content: {
'application/json': {
id: string
name: string
colors:
| string[]
| {
id: string
name: string
}[]
}
}
}
}
}
}
}

export interface components {}

export interface operations {}

export interface external {}
Loading