Open s-jepsen opened 7 months ago
This is simpler:
/pets:
get:
operationId: getPets
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
It might be - but the structure i'm using is taken from the official documentation.
I've looked in the code. DefaultCodeGen.discriminatorFound() has a bug.
It visits recursively all the children to find the discriminator. To avoid infinite loops, there is a safegard. It is badly implemented.
private CodegenProperty discriminatorFound(String composedSchemaName, Schema sc, String discPropName, Set<String> visitedSchemas) {
if (visitedSchemas.contains(composedSchemaName)) { // recursive schema definition found
return null;
} else {
visitedSchemas.add(composedSchemaName);
}
...
for (Object allOf : composedSchema.getOneOf()) {
// this call will always return null because the first argument is composedSchemaName instead of ((Schema)oneOf).getName()
// warning (Schema)oneOf).getName() can be null so the safeguard needs to take it into account
CodegenProperty thisCp = discriminatorFound(composedSchemaName, (Schema) oneOf, discPropName, visitedSchemas);
...
}
// same for allOf and anyOf
I'll try to create a PR
I think #15298 fix this issue
Bug Report Checklist
Description
Java/Spring generator wrongly emits warnings related to oneOf discriminator:
[WARNING] 'getPets_request' defines discriminator 'pet_type', but the referenced schema 'Cat' is incorrect. pet_type is missing from the schema, define it as required and type string [WARNING] 'getPets_request' defines discriminator 'pet_type', but the referenced schema 'Dog' is incorrect. pet_type is missing from the schema, define it as required and type string
Expected output: Valid generated pojo models No misleading warnings related to oneOf 'pet_type' discriminator.
Actual output: Valid generated pojo models. Misleading warnings related to oneOf 'pet_type' discriminator.
openapi-generator version
7.3.0
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
A Maven project to reproduce the issue is attached openapi-one-of-warning-bug.zip
Related issues/PRs
Suggest a fix