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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

protoc-gen-openapiv2 not working for google.api.field_behavior as expected #3265

Closed
int64max opened this issue Mar 28, 2023 · 1 comment
Closed

Comments

@int64max
Copy link

馃悰 Bug Report

According to this, protoc-gen-openapiv2 can mark fields as required based on the google.api.field_behavior field option. But when I tried doing so, it does not mark the fields as required.

Note that the fields are only marked as required if I use specify them as required by using grpc.gateway.protoc_gen_openapiv2.options.openapiv2_schema.

To Reproduce

My proto file myproto.proto

syntax = "proto3";

option go_package = "tms.com/test";

import "protoc-gen-openapiv2/options/annotations.proto";
import "google/api/field_behavior.proto";
import "google/api/annotations.proto";

message TestMessage {
  // Works if I uncomment this block.
  // option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_schema) = {
  //  json_schema: { required: [ "my_required_field" ] }
  //};

  int32 my_optional_field = 1;
  int32 my_required_field = 2 [(google.api.field_behavior) = REQUIRED];
}
...

Generate spec via:
protoc -I /opt/include -I . --openapiv2_out=logtostderr=true,json_names_for_fields=true:gen myproto.proto

Expected behavior

...
    "TestMessage": {
      "type": "object",
      "properties": {
        "myOptionalField": {
          "type": "integer",
          "format": "int32"
        },
        "myRequiredField": {
          "type": "integer",
          "format": "int32"
        }
      },
      "required": [
        "my_required_field"
      ]
    },
...

Actual Behavior

...
    "TestMessage": {
      "type": "object",
      "properties": {
        "myOptionalField": {
          "type": "integer",
          "format": "int32"
        },
        "myRequiredField": {
          "type": "integer",
          "format": "int32"
        }
      }
    },
...

Your Environment

$ protoc --version
libprotoc 3.21.6

What am I missing? Is google.api.field_behavior not supported by protoc-gen-openapiv2?

@johanbrandhorst
Copy link
Collaborator

Hi. Sorry that you ran into this, but you are indeed right that this is not currently supported. This issue is a dupe of #3058.

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

No branches or pull requests

2 participants