Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Protobuf] Generate enum fields #7073

Merged
merged 1 commit into from
Jul 30, 2020
Merged

[Protobuf] Generate enum fields #7073

merged 1 commit into from
Jul 30, 2020

Conversation

k0ral
Copy link
Contributor

@k0ral k0ral commented Jul 29, 2020

An example will best illustrate the point of this pull-request. Take the following OpenAPI definition:

swagger: "2.0"
info:
  title: MyModel
  version: "1.0"
paths: {}

definitions:
  MyModel:
    type: object
    properties:
      color:
        type: string
        enum:
          - RED
          - BLUE
          - GREEN

Without this pull-request, the generated protobuf file looks like:

message MyModel {
  enum color {
    RED = 0;
    BLUE = 1;
    GREEN = 2;
  }
}

With this pull-request, the generated protobuf file looks like:

message MyModel {
  enum ColorEnum {
    RED = 0;
    BLUE = 1;
    GREEN = 2;
  }

 ColorEnum color = 1;
}

PR checklist

  • Read the contribution guidelines.
  • If contributing template-only or documentation-only changes which will change sample output, build the project beforehand.
  • Run the shell script ./bin/generate-samples.shto update all Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*. For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

@wing328
Copy link
Member

wing328 commented Jul 30, 2020

Shippable failure not related to this change.

@wing328 wing328 merged commit 0494d27 into OpenAPITools:master Jul 30, 2020
@wing328
Copy link
Member

wing328 commented Jul 30, 2020

Upgrade Note

The suffix "Enum" is now appeneded to the enum, e.g. status => StatusEnum

Copy link

@dobl1 dobl1 left a comment

Choose a reason for hiding this comment

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

Hi @k0ral, please see decision log regarding this topic
naming shoud be x-protobuf-field-number to be consistent with protobuf specification https://developers.google.com/protocol-buffers/docs/proto#assigning_field_numbers

term "index" could be confusing for some people.

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

Successfully merging this pull request may close these issues.

3 participants