-
-
Notifications
You must be signed in to change notification settings - Fork 7k
[core] cleanup: remove OpenAPI parameter from CodegenConfig methods #1953
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
Conversation
👍 Thanks for opening this issue! The team will review the labels and make any necessary changes. |
Input @wing328
This is a very good feedback. After a short discussion on Gitter we agreed that:
This way we are consistent and have only one pattern in place. |
PR is updated with new commits. |
…penAPITools#1953) * Add OpenAPI parameter to DefaultCodegen#toDefaultValue(..) * Remove CodegenConfig#fromOperation() * Remove allDefinitions parameter from fromModel(..) * Remove definitions parameter from CodegenConfig#fromOperation(..) * remove schemas parameter from DefaultCodegen#fromRequestBody(..) * remove schemas parameter from DefaultCodegen#fromCallback(..) * Remove openAPI parameter from CodegenConfig#fromModel(..) * Remove openAPI parameter from CodegenConfig#fromOperation(..) * Remove openAPI parameter from DefaultCodegen#fromProperty(..) * Remove openAPI parameter from DefaultCodegen#fromParameter(..) * Remove OpenAPI parameter from several methods * Use ModelUtils.getReferencedParameter(..) * Remove unused variable * Remove openAPI parameter from DefaultCodegen#fromResponse(..) * Remove openAPI parameter from DefaultCodegen#addHeaders(..) * Remove from addConsumesInfo(..)/addProducesInfo(..) * Improve test: add property to prevent Pet from being a free-form object * remove globalSchemas Map<String, Schema> * remove deprecated method: postProcessOperations() * Remove 'Map<String, Schema> allSchemas' from addProperties(..) * Remove 'Map<String, Schema> allDefinitions' from createDiscriminator(..) * Remove 'Map<String, Schema> allSchemas' from unaliasPropertySchema(..) * Rename globalOpenAPI to openAPI * Update documentation * Run “Optimize import” in IntelliJ IDEA
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
and./bin/security/{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\
.master
,. Default:3.4.x
,4.0.x
master
.Description of the PR
In order to solve #1927 I will need to access the OpenAPI instance inDefaultCodegen#toDefaultValue(..)
in order to be able to see if the schema contains a$ref
and if this is the case, to see if the referenced schema has a default value or not.The main change of this PR is to have:public String toDefaultValue(Schema p, OpenAPI openAPI)
Instead ofpublic String toDefaultValue(Schema p)
To fulfill this requirement theOpenAPI
is added as parameter to some methods ofDefaultCodegen
.Some of those methods also hadMap<String, Schema> allDefinitions
which corresponds toopenAPI.getComponents().getSchemas()
. This parameter was also removed from the methods, and theopenAPI
instance is used to access to all schemas.Based on feedback the initial intention of this PR was changed.
Historically, to access the
OpenAPI
instance, or all schemas of the OpenAPI instance, parameters were used in different methods. Example:CodegenConfig#fromOperation(String, String, Operation, Map<String, Schema>, OpenAPI)
CodegenConfig#fromModel(String, Schema, Map<String, Schema>)
DefaultCodegen#fromResponse(OpenAPI, String, ApiResponse)
DefaultCodegen#DefaultCodegen.fromRequestBody(RequestBody, Map<String, Schema>, Set<String>, String)
DefaultCodegen#createDiscriminator(String, Schema, Map<String, Schema>)
Then @wing328 noticed that access to this information is requested in a lot of places (for unaliasing).
So he introduced a new approach: having two members
globalOpenAPI
andglobalSchemas
.Having two ways for doing the same task is not consistent. It is harder to understand, to maintain and can lead to errors (for example all the unit tests were not using
globalOpenAPI
, meaning that they were not reproducing real cases, because when the generator is used for real, then theglobalOpenAPI
member is set).This PR cleans the situation by removing the original approach completely. There is no
openAPI
orallDefinitions
parameter anymore in the methods. Instead they use theglobalOpenAPI
member which is renamedopenAPI
.In addition
globalSchemas
was only a convenient and null-pointer safe access toopenAPI.getComponents().getSchemas()
. It is also removed.This change is mentioned in the migration guide "From 3.x to 4.0.0"
In my opinion the PR improves the readability of the code and reduces the potential coding mistakes.