Skip to content

deepObject parameters that are not flat cause panic #294

@jharting

Description

@jharting

Consider the following schema:

---
openapi: 3.0.3
info:
  title: Reproducer
  version: 0.0.1

paths:
  /example:
    get:
      operationId: Example
      parameters:
      - in: query
        name: filter
        required: false
        style: deepObject
        explode: true
        schema:
          type: object
          properties:
            labels:
              type: object
              additionalProperties:
                type: string
          required: []

      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object

This should let one make requests with multiple levels of nesting in the filter parameter, e.g.
/example?filter[labels][foo]=bar

However, kin-openapi only seems to support flat key/value deepObject parameters. The example above therefore yields

echo: http: panic serving 127.0.0.1:58216: schema has non primitive type "object"
goroutine 46 [running]:
net/http.(*conn).serve.func1(0xc0001f1cc0)
        /usr/lib/golang/src/net/http/server.go:1800 +0x139
panic(0x124f3e0, 0xc0003280e0)
        /usr/lib/golang/src/runtime/panic.go:975 +0x3e3
github.com/getkin/kin-openapi/openapi3filter.parsePrimitive(0xc000528039, 0x24, 0xc00035f7c0, 0x6, 0xc000144868, 0xc00042f0b0, 0xc00052802c)
        /home/jharting/go/pkg/mod/github.com/getkin/[email protected]/openapi3filter/req_resp_decoder.go:768 +0x86b
github.com/getkin/kin-openapi/openapi3filter.makeObject(0xc00042f0b0, 0xc00035f6e0, 0x0, 0x0, 0xc000328090)
        /home/jharting/go/pkg/mod/github.com/getkin/[email protected]/openapi3filter/req_resp_decoder.go:709 +0x127
github.com/getkin/kin-openapi/openapi3filter.(*urlValuesDecoder).DecodeObject(0xc000130030, 0xc0006a1a16, 0x6, 0xc00068e100, 0xc00035f6e0, 0xc000328090, 0xc000536160, 0xc000542df0)
        /home/jharting/go/pkg/mod/github.com/getkin/[email protected]/openapi3filter/req_resp_decoder.go:554 +0xd7
github.com/getkin/kin-openapi/openapi3filter.decodeValue.func2(0xc0006a1a16, 0x6, 0xc00068e100, 0xc00035f6e0, 0xc000542e10, 0x45f1e6, 0xc000130030, 0x8)
        /home/jharting/go/pkg/mod/github.com/getkin/[email protected]/openapi3filter/req_resp_decoder.go:302 +0x5b
github.com/getkin/kin-openapi/openapi3filter.decodeValue(0x16eb080, 0xc000130030, 0xc0006a1a16, 0x6, 0xc00068e100, 0xc00035f6e0, 0x0, 0x1399340, 0xc000697301, 0xc00042eed0, ...)
        /home/jharting/go/pkg/mod/github.com/getkin/[email protected]/openapi3filter/req_resp_decoder.go:307 +0x4bd
github.com/getkin/kin-openapi/openapi3filter.decodeStyledParameter(0xc0000a3900, 0xc00042ef00, 0xdad531, 0x203000, 0x203000, 0x203000)
        /home/jharting/go/pkg/mod/github.com/getkin/[email protected]/openapi3filter/req_resp_decoder.go:235 +0x11f
github.com/getkin/kin-openapi/openapi3filter.ValidateParameter(0x16f8100, 0xc00042f050, 0xc00042ef00, 0xc0000a3900, 0xc00042f050, 0x13713c0)
        /home/jharting/go/pkg/mod/github.com/getkin/[email protected]/openapi3filter/validate_request.go:140 +0x3dd
github.com/getkin/kin-openapi/openapi3filter.ValidateRequest(0x16f8100, 0xc00042f050, 0xc00042ef00, 0x16b82a0, 0x13d7600)
        /home/jharting/go/pkg/mod/github.com/getkin/[email protected]/openapi3filter/validate_request.go:65 +0x3ab

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions