Skip to content

Adding of index on array elements is unnecessary #22

Description

@Mazgis47

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

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