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

Format option of array type is located in the wrong place #3403

Closed
far4599 opened this issue Jul 17, 2023 · 4 comments · Fixed by #3410
Closed

Format option of array type is located in the wrong place #3403

far4599 opened this issue Jul 17, 2023 · 4 comments · Fixed by #3410

Comments

@far4599
Copy link
Contributor

far4599 commented Jul 17, 2023

🐛 Bug Report

This bug relates to protoc-gen-openapiv2.

It looks like format option with array type is placed in the wrong place when compiled to json. Now format is placed at the root of the property object. But according to the spec: items option describes the type of items in the array. So format shall be a part of items object as the other item type descriptors.

The problem is located here: https://github.com/grpc-ecosystem/grpc-gateway/blob/main/protoc-gen-openapiv2/internal/genopenapi/template.go#L2751C5-L2751C5
where all the type properties (except format) are set to the Items object.

To Reproduce

repeated string uuids = 1 [
  (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {
    type: ARRAY,
    format: "uuid",
    min_items: 1,
    max_items: 10000,
    unique_items: true,
  }
];

complied json schema:

"properties": {
  "uuids": {
    "type": "array",
    "format": "uuid", <- now is here
    "items": {
      "type": "string",
      "uniqueItems": true
    },
    "maxItems": 10000,
    "minItems": 1
  }
},

Expected behavior

"properties": {
  "uuids": {
    "type": "array",
    "items": {
      "type": "string",
      "format": "uuid", <- shall be here
      "uniqueItems": true
    },
    "maxItems": 10000,
    "minItems": 1
  }
},
@far4599
Copy link
Contributor Author

far4599 commented Jul 17, 2023

Just to prove that the current location is wrong here is a sample yaml to copy-paste to https://editor.swagger.io/

When items.format the UI generates UUID for an example of request properly

openapi: 3.0.3
info:
  title: Swagger Petstore - OpenAPI 3.0
  version: 1.0.11
paths:
  /user:
    post:
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/User'
      responses:
        default:
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/User'
components:
  schemas:
    User:
      type: object
      properties:
        tags:
          type: array
          items: 
            type: string
            format: uuid

@adambabik
Copy link
Collaborator

Hi @far4599! Thanks for reporting the issue and locating the source. Would you be willing to send a PR fixing it along with a test case? Happy to help with any questions.

@far4599
Copy link
Contributor Author

far4599 commented Jul 20, 2023

Sure. I'll do this.

@far4599
Copy link
Contributor Author

far4599 commented Jul 20, 2023

Hi @adambabik! RP is ready. Review, please.

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

Successfully merging a pull request may close this issue.

2 participants