The generated code when using OneOf, AnyOf or AllOf contain errors, i.e.:
4.3.1
openapi: 3.0.0
info:
version: 0.0.1
title: Test
paths:
/endpointAllOf:
put:
operationId: allOf
description: "-"
requestBody:
description: Content All Of
content:
application/json:
schema:
$ref: '#/components/schemas/SchemaAllOf'
responses:
200:
description: Success
/endpointOneOf:
put:
operationId: oneOf
description: "-"
requestBody:
description: Content One Of
content:
application/json:
schema:
$ref: '#/components/schemas/SchemaOneOf'
responses:
200:
description: Success
/endpointAnyOf:
put:
operationId: anyOf
description: "-"
requestBody:
description: Content Any Of
content:
application/json:
schema:
$ref: '#/components/schemas/SchemaAnyOf'
responses:
200:
description: Success
components:
schemas:
SchemaAllOf:
type: object
description: 'All Of Example'
properties:
information:
type: string
description: 'Some information field'
additionalInfo:
allOf:
- $ref: '#/components/schemas/OptionA'
- $ref: '#/components/schemas/OptionB'
SchemaAnyOf:
type: object
description: 'Any Of Example'
properties:
information:
type: string
description: 'Some information field'
additionalInfo:
anyOf:
- $ref: '#/components/schemas/OptionA'
- $ref: '#/components/schemas/OptionB'
SchemaOneOf:
type: object
description: 'One Of Example'
properties:
information:
type: string
description: 'Some information field'
additionalInfo:
oneOf:
- $ref: '#/components/schemas/OptionA'
- $ref: '#/components/schemas/OptionB'
OptionA:
type: object
description: 'Option A'
properties:
data1:
type: string
description: 'Data'
OptionB:
type: object
description: 'Option B'
properties:
data2:
type: number
description: 'Data'
java -cp openapi-generator-cli-4.3.1.jar org.openapitools.codegen.OpenAPIGenerator generate -i ${SPEC_FILE} -g cpp-qt5-client -o gen/ --model-name-prefix Test
Execute code generation and take a look at the files (SchemaOneOf.h, SchemaAllOf.h, SchemaAnyOf.h, etc.).
E.g. for oneOf: https://github.com/OpenAPITools/openapi-generator/issues/15
##### Suggest a fix
-
@muttleyxd @stkrwork @ravinikam @MartinDelille
There seems to be a problem to handle in C++
std::variant/std::any
OneOf
AnyOf
AllOf
Easiest way would be to generate separate members for the OneOf/AllOf/AnyOf refs
Then set the class to be valid for the ones for which data arrived.
Do you have some ideas and better proposals?
I think it's an issue with the inline model resolver. As a workaround, please define the schemas (oneOf, anyOf, allOf) separately instead, e.g.
SchemaAllOf:
type: object
description: 'All Of Example'
properties:
information:
type: string
description: 'Some information field'
additionalInfo:
$ref: '#/components/schemas/AllOfOptionAB'
AllOfOptionAB:
allOf:
- $ref: '#/components/schemas/OptionA'
- $ref: '#/components/schemas/OptionB'
Most helpful comment
I think it's an issue with the inline model resolver. As a workaround, please define the schemas (oneOf, anyOf, allOf) separately instead, e.g.