镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

The query FieldOptions custom example parameter does not work, the body succeeds, why? #420

Open

Description

@ahuijiLearning

body (success)

// .proto
  // CreateTest
rpc CreateTest(CreateTestRequest) returns (CreateTestReply) {
  option (openapi.v3.operation) = {
    summary : "CreateTest",
  };
  option (google.api.http) = {
    post : "/test"
    body: "*"
  };
}

message CreateTestRequest {
  // title
  string title = 1[
    (openapi.v3.property) = { example: { yaml: "213" } }
  ];
}
message CreateTestReply {
  int32 code = 1;
  string res = 2;
}

// openapi.yaml
/test:
        post:
            tags:
                - Course
            summary: CreateTest
            description: CreateTest
            operationId: Course_CreateTest
            requestBody:
                content:
                    application/json:
                        schema:
                          type: object
                          properties:
                              title:
                                  example: 213 // success
                                  type: string
                                  description: title
                required: true
            responses:
                "200":
                    description: OK
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/CreateTestReply'

query(fail)

// test
  rpc GetTest(GetTestRequest) returns (GetTestReply) {
    option (openapi.v3.operation) = {
      summary : "test",
      parameters: [
        {
            parameter: { // Too much configuration content
              name: 'data',
              in: "query",
              description: "data",
              schema: {
                schema: {
                  type: "string",
                  example: {
                    yaml: "ttt"
                  }
                }
              }
            }
        }
      ]
    };
    option (google.api.http) = {
      get : "/test"
    };
  }

message GetTestRequest {
  // title
  string title = 1[
    (openapi.v3.property) = {example: {yaml: "213"}}  // It looks good, but it's not work
  ];
}
message GetTestReply {
  int32 code = 1;
  string res = 2;
}


// openapi.yaml
  /test:
      get:
          tags:
              - Course
          summary: GetTest
          description: GetTest
          operationId: Course_GetTest
          parameters:
              - name: title
                in: query
                description: title
                schema:
                  type: string // used FieldOptions success
              - name: data
                in: query
                description: data
                schema:
                  example: ttt  // used MethodOptions success
                  type: string
          responses:
              "200":
                  description: OK
                  content:
                      application/json:
                          schema:
                              $ref: '#/components/schemas/GetTestReply'

I want to add an example to my openapi.yaml request parameter. The entry of the body format in the post method was successful, but it failed in the query. Although I found a MethodOptions custom way, I thought it was too complicated. How can I do it at the FieldOptions?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions