Skip to content

Feature/87 support enums in generators #130

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

Merged

Conversation

thowimmer
Copy link
Contributor

@thowimmer thowimmer requested review from ooz and ozscheyge and removed request for ooz February 21, 2020 14:36
@coveralls
Copy link

coveralls commented Feb 22, 2020

Coverage Status

Coverage increased (+0.02%) to 92.063% when pulling 02b62b9 on thowimmer:feature/87-support-enums-in-generators into 21213ef on ePages-de:master.

@ozscheyge ozscheyge self-assigned this Feb 24, 2020
@thowimmer
Copy link
Contributor Author

Hey @ozscheyge ,

did you already took a look into this PR ? Any change to get this functionality merged and probably released by the end of this week ? I would have some spare time this week :-)

@ozscheyge
Copy link
Contributor

Hey @thowimmer ,

I had a brief look, but realized I first need to better research how possible enum values are modeled in OpenAPI 2/3 before giving feedback.

I'm quite busy atm, but I'll take care of it tomorrow, so it could be done before end of the week.

@thowimmer
Copy link
Contributor Author

Sure, no worries. I'm glad for any feedback and improvements. We can also have a more in-deep discussion if you like.

Here just some things to mention:

  • This PR only covers enum support for fields in request/response bodies.The OpenAPI spec (both v2 and v3) also support enums for other kind of parameters (header params, query params etc).

  • Both generators are mapping to the corresponding models based on the JSON schema which is generated via the JsonSchemaFromFieldDescriptorsGenerator. In order that the mapping works properly, without the need of further code changes, the 'type' field has to be present in the JSON schema which is not required in a valid JSON schema:

Previously generated JSON schema

...
"someEnum" : {
      "description" : "Some enum description",
      "enum" : [ "FIRST_VALUE", "SECOND_VALUE", "THIRD_VALUE" ]
    }
...

Newly generated JSON schema (with commit 04f4bc7)

...
    "someEnum" : {
      "description" : "Some enum description",
      "type" : "string", //this is necessary for proper mapping - but optional by the JSON schema
      "enum" : [ "FIRST_VALUE", "SECOND_VALUE", "THIRD_VALUE" ]
    }
...
  • Added tests for the generators which verify that the enums properties are present in v2 and v3 request and response models

Here are some references to the OpenAPI specs:

Copy link
Contributor

@ozscheyge ozscheyge left a comment

Choose a reason for hiding this comment

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

Thanks for the detailed explanation and links to the schema specs. Made reviewing it a lot easier!

One suggestion:

@ozscheyge ozscheyge merged commit d68049a into ePages-de:master Feb 27, 2020
@thowimmer thowimmer deleted the feature/87-support-enums-in-generators branch February 27, 2020 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Is there a known workaround for handling an array of string/enum?
3 participants