-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Open
Labels
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issuue still exists?
- Have you search for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
With #6789 merged I regenerated my client and unfortunately there are still some union-related errors.
There are multiple locations with invalid code generated for handling union values:
return new runtime.JSONApiResponse(response, (jsonValue) => jsonValue.map(Pet | Cat | DogFromJSON));
const response = await this.request({
path: `/pets`,
method: 'POST',
headers: headerParameters,
query: queryParameters,
body: Pet | Cat | DogToJSON(requestParameters.petCatDog),
});
No errors are thrown during generation but when compiling with typescript it's failing.
openapi-generator version
openapi-generator-cli-5.0.0-20200907.080402-621.jar
OpenAPI declaration file content or url
openapi: "3.0.1"
info:
version: 1.0.0
title: typescript union issue
paths:
/pets:
get:
responses:
"200":
description: OK
content:
application/json:
schema:
type: array
items:
oneOf:
- $ref: "#/components/schemas/Pet"
- $ref: "#/components/schemas/Cat"
- $ref: "#/components/schemas/Dog"
discriminator:
mapping:
cat: "#/components/schemas/Cat"
dog: "#/components/schemas/Dog"
propertyName: "petType"
post:
requestBody:
content:
application/json:
schema:
oneOf:
- $ref: "#/components/schemas/Pet"
- $ref: "#/components/schemas/Cat"
- $ref: "#/components/schemas/Dog"
discriminator:
mapping:
cat: "#/components/schemas/Cat"
dog: "#/components/schemas/Dog"
propertyName: "petType"
responses:
"201":
description: Created
/pets-alt:
get:
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/PetsResponse"
components:
schemas:
Pet:
type: object
required:
- petType
properties:
petType:
type: string
name:
type: string
Cat:
type: object
allOf:
- $ref: "#/components/schemas/Pet"
- type: object
properties:
scratching:
type: boolean
Dog:
type: object
allOf:
- $ref: "#/components/schemas/Pet"
- type: object
properties:
sniffing:
type: boolean
PetsResponse:
type: object
properties:
pets:
type: array
items:
oneOf:
- $ref: "#/components/schemas/Pet"
- $ref: "#/components/schemas/Cat"
- $ref: "#/components/schemas/Dog"
discriminator:
mapping:
cat: "#/components/schemas/Cat"
dog: "#/components/schemas/Dog"
propertyName: "petType"
Generation Details
Generator: typescript-fetch
Config:
{
"npmName": "@company/project",
"npmVersion": "1.0.0",
"snapshot": false,
"supportsES6": true,
"typescriptThreePlus": true
}
Steps to reproduce
This issue can be reproduced by using the typescript-fetch
generator with the OpenAPI declaration & config from above.
Related issues/PRs
Suggest a fix
Myhlamaeus, DirSol, UPSQUARED, dielok and shawnpanda