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

Adding of index on array elements is unnecessary #22

Open
Mazgis47 opened this issue Dec 6, 2023 · 0 comments
Open

Adding of index on array elements is unnecessary #22

Mazgis47 opened this issue Dec 6, 2023 · 0 comments

Comments

@Mazgis47
Copy link

Mazgis47 commented Dec 6, 2023

Currently, the index of each array item is appended in a form of [x] e.g. [0]. However swagger does not append that and I believe such indexes should not be added by oapi-codegen too.

Example:

openapi: 3.0.3
info:
  version: 0.0.1
  title: Test array
  description: Test Array
servers:
  - url: http://localhost:8081
    description: local
tags:
  - name: test
paths:
  /v1/asns:
    get:
      summary: Search Asn
      operationId: searchAsn
      tags:
        - asn
      parameters:
        - $ref: "#/components/parameters/QueryTenantUUID"
      responses:
        "200":
          description: Success
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AsnsResponse"
components:
  parameters:
    QueryTenantUUID:
      name: tenant_uuid
      in: query
      style: deepObject
      schema:
        $ref: "#/components/schemas/Filter"
      examples:
        advanced:
          value:
            op: eq
            vals:
              - aaaaaa
              - bbbbbb
  schemas:
    Filter:
      type: object
      required:
        - op
        - vals
      properties:
        op:
          description: Filter operation like equals, greater than, not equals, less than ...
          type: string
          enum:
            - eq
            - ne
            - lt
            - lte
            - gt
            - gte
            - like
        vals:
          type: array
          items: {}
          description: Values can be any type for filtering
    AsnsResponse:
      type: object
      properties:
        data:
          type: array
          items:
            $ref: "#/components/schemas/Asn"
    Asn:
      type: object
      properties:
        tenant_uuid:
          type: string
          format: uuid
          example: "aaaaaa"

https://editor.swagger.io/ generates the request without indexes, and this difference causes problems to parse the parameters correctly.

http://localhost/v1/asns?tenant_uuid%5Bop%5D=eq&tenant_uuid%5Bvals%5D=aaaaaa&tenant_uuid%5Bvals%5D=bbbbbb
without encoding:
http://localhost/v1/asns?tenant_uuid[op]=eq&tenant_uuid[vals]=aaaaaa&tenant_uuid[vals]=bbbbbb

codegen generates with the indexes as:
http://localhost/v1/asns?tenant_uuid[op]=eq&tenant_uuid[vals][0]=aaaaaa&tenant_uuid[vals][1]=bbbbbb

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