oneOf is not being validated/used for generating models, consider the following example:
oneOf Example:
Parent:
type: object
properties:
type:
type: string
description: Some description.
discriminator:
propertyName: type
mapping:
ChildOne: '#/components/schemas/ChildOne'
ChildTwo: '#/components/schemas/ChildTwo'
oneOf:
- $ref: '#/components/schemas/ChildOne'
- $ref: '#/components/schemas/ChildTwo'
ChildOne:
title: ChildOne
type: object
properties:
data:
$ref: '#/components/schemas/Data'
ChildTwo:
title: ChildTwo
type: object
properties:
properties:
data:
$ref: '#/components/schemas/Data'
In this case, both ChildOne
and ChildTwo
models/classes should inherit from Parent
, but that is not the actual result, on the other hand, using allOf
in children results in ChildOne
and ChildTwo
models/classes inheriting from Parent
.
allOf example:
Parent:
type: object
properties:
type:
type: string
description: Some description.
ChildOne:
allOf:
- $ref: '#/components/schemas/Parent'
title: ChildOne
type: object
properties:
data:
$ref: '#/components/schemas/Data'
ChildTwo:
allOf:
- $ref: '#/components/schemas/Parent'
title: ChildTwo
type: object
properties:
properties:
data:
$ref: '#/components/schemas/Data'
Used commandline:
$ datamodel-codegen ADD YOUR EXACT COMMAND USED HERE
Expected behavior
A clear and concise description of what you expected to happen.
Version:
Additional context
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too