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

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

Open
ahuijiLearning opened this issue Nov 29, 2023 · 0 comments

Comments

@ahuijiLearning
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant