openapi-generator
openapi-generator copied to clipboard
[BUG][typescript] `oneOf` + `allOf` breaks serialization
Bug Report Checklist
- [x] Have you provided a full/minimal spec to reproduce the issue?
- [x] Have you validated the input using an OpenAPI validator (example)?
- [x] Have you tested with the latest master to confirm the issue still exists?
- [x] Have you searched for related issues/PRs?
- [x] What's the actual output vs expected output?
- [ ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When using an API that uses a oneOf union containing several allOf elements, trying to send/receive data will fail with the error typeMap[type].getAttributeTypeMap is not a function. The underlying reason is that no discriminator value or mapping is generated for this value.
Prior to #19494 this worked fine, but as of 7.9.0 trying to run this schema will crash.
openapi-generator version
7.9.0, this is a regression.
OpenAPI declaration file content or url
openapi: 3.0.1
info:
title: fruity
version: 0.0.1
paths:
/:
get:
responses:
"200":
description: get a fruit
content:
application/json:
schema:
$ref: "#/components/schemas/Fruit"
components:
schemas:
Apple:
title: Apple
type: object
properties:
variety:
type: string
description: The type of apple
required:
- variety
Banana:
title: Banana
type: object
properties:
ripeness:
type: number
description: How ripe the banana is from 0 to 1
Fruit:
title: Fruit
oneOf:
- type: object
allOf:
- type: object
properties:
type:
type: string
enum:
- apple
- $ref: '#/components/schemas/Apple'
required:
- type
- type: object
allOf:
- type: object
properties:
type:
type: string
enum:
- banana
- $ref: '#/components/schemas/Banana'
required:
- type
Generation Details
Generated with v7.9.0.
Steps to reproduce
Generate the above yaml using the typescript generator, then try to use the API. It will fail with typeMap[type].getAttributeTypeMap is not a function
Related issues/PRs
Not as far as I could tell.
Suggest a fix
I don't have an exact fix in mind since I don't fully understand how this mapping logic is supposed to work.