Skip to content
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

Added vendorExtensions.x-isPrimitive. #7991

Merged
merged 2 commits into from
Apr 16, 2018

Conversation

satoshikumano
Copy link
Contributor

@satoshikumano satoshikumano commented Apr 9, 2018

Switch template for constructFromObject.

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./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\.
  • Filed the PR against the correct branch: 3.0.0 branch for changes related to OpenAPI spec 3.0. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

(details of the change, additional tests that have been done, reference to the issue for tracking, etc)

When $ref is used to reference primitive types, The value is always empty object.
This forces users to modify the Swagger file even if the API definition is valid.

Reported in #4973

Switch template for constructFromObject.
@satoshikumano
Copy link
Contributor Author

Could you review this PR?
@CodeNinjai @frol @cliffano

@satoshikumano
Copy link
Contributor Author

Have not commit the change made by ./bin/javascript-petstore.sh and ./bin/security/javascript-petstore.sh yet.
Please let me know if I need to push those changes.

@@ -795,6 +795,11 @@ public CodegenModel fromModel(String name, Model model, Map<String, Model> allDe
if (mm.getAdditionalProperties() != null) {
codegenModel.vendorExtensions.put("x-isMap", true);
codegenModel.vendorExtensions.put("x-itemType", getSwaggerType(mm.getAdditionalProperties()));
} else {
String type = mm.getType();
if (type != null && (type.equals("number") || type.equals("integer") || type.equals("string") || type.equals("boolean") || type.equals("null"))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To reduce cyclomatic complexity, could this line perhaps be replace with something like:
String[] PRIMITIVE_TYPES = new String[] {"number", "integer","string","boolean", "null"};
Arrays.asList(PRIMITIVE_TYPES).contains(type)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. It also improves readability.

@satoshikumano
Copy link
Contributor Author

@cliffano Hi. I have fixed review indication. Just would like to send a reminder in case you haven't noticed yet.

@cliffano
Copy link
Contributor

cliffano commented Apr 12, 2018

@satoshikumano Thanks for that.

Overall I don't have any objection, but I was just wondering if it's worth having the primitive types array consistent to

, i.e. scoped the same way, and declared at the top.

What do you think @wing328 ? Does Swagger CodeGen have any preference/standard? If not, I'm fine with it.

@advance512
Copy link

Can we merge this in, to test in a nightly build?
I believe it also solved issue #4973

@wing328
Copy link
Contributor

wing328 commented Apr 16, 2018

@satoshikumano thanks for the PR, which has been merged into master.

@cliffano we don't enforce a standard on this and I agree declaring the array on the top seems more consistent with the overall code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants