gnostic icon indicating copy to clipboard operation
gnostic copied to clipboard

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

Open ahuijiLearning opened this issue 2 years ago • 0 comments

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?

ahuijiLearning avatar Nov 29 '23 07:11 ahuijiLearning