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

[protoc-gen-openapi] How the string type supports enum option #3341

Closed
zhb127 opened this issue Jun 5, 2023 · 2 comments · Fixed by #3352
Closed

[protoc-gen-openapi] How the string type supports enum option #3341

zhb127 opened this issue Jun 5, 2023 · 2 comments · Fixed by #3352

Comments

@zhb127
Copy link
Contributor

zhb127 commented Jun 5, 2023

🚀 Feature

How the string type supports enum option:

  string sort_direction = 1 [
    (validate.rules).string = {
      in: [
        'asc',
        'desc'
      ]
    },
    (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {
      enum: [
        'asc',
        'desc'
      ]
    }
  ];

protoc-gen-openapiv2 actual output:

          {
            "name": "sort_direction",
            "in": "query",
            "required": false,
            "type": "string"
          }

expect output:

          {
            "name": "sort_direction",
            "in": "query",
            "required": false,
            "type": "string",
            "enum": [
              "asc", 
              "desc"
            ]
          }
@johanbrandhorst
Copy link
Collaborator

This sounds like a bug, I would expect that to populate the enum field as you expect. I expect it would do the right thing if the field type was an enum, but we should be able to support this annotation too. Would you be willing in helping to fix this? You probably want to start looking here: https://github.com/grpc-ecosystem/grpc-gateway/blob/main/protoc-gen-openapiv2/internal/genopenapi/template.go#L321

@zhb127
Copy link
Contributor Author

zhb127 commented Jun 9, 2023

Would you be willing in helping to fix this

Code is committed and unit tests are added.

Please review.

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

Successfully merging a pull request may close this issue.

2 participants