-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[core] do not always cast to ArraySchema #3780
[core] do not always cast to ArraySchema #3780
Conversation
👍 Thanks for opening this issue! The team will review the labels and make any necessary changes. |
@jmini thanks for the PR. What about removing the following instead? // assume it's an array if maxItems, minItems is set
if (schema != null && (schema.getMaxItems() != null || schema.getMinItems() != null)) {
return true;
} As ModelUtils.isArraySchema(Schema) should be the source of truth to tell if a schema is ArraySchema or not. |
@wing328: this was also my thought. I will change this PR to remove the second part of the |
@wing328 |
That's what I recalled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
,./bin/openapi3/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
. If contributing template-only or documentation-only changes which will change sample output, be sure to build the project first.master
,4.1.x
,5.0.x
. Default:master
.Description of the PR
Similar to PR #3765 but solved at core Level.
Casting an
ObjectSchema
toArraySchema
after aModelUtils.isArraySchema(schema)
producesjava.lang.ClassCastException: io.swagger.v3.oas.models.media.ObjectSchema cannot be cast to io.swagger.v3.oas.models.media.ArraySchema
error in some cases.This is because of the implementation of
ModelUtils.isArraySchema(Schema)
(the second part of the method):openapi-generator/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java
Lines 361 to 370 in 5a54aa5
In the case commented with "// assume it's an array if maxItems, minItems is set" we have an
ObjectSchema
.When we try to read the
items
value, we need to check if we are allowed to cast or not.