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

deepObject parameters that are not flat cause panic #294

Closed
jharting opened this issue Jan 29, 2021 · 4 comments · Fixed by #911
Closed

deepObject parameters that are not flat cause panic #294

jharting opened this issue Jan 29, 2021 · 4 comments · Fixed by #911
Labels

Comments

@jharting
Copy link

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
@fenollp fenollp added the bug label Feb 4, 2021
@markuswustenberg
Copy link

The same error surfaces when adding arrays of objects as URL parameters.

@fenollp
Copy link
Collaborator

fenollp commented Dec 14, 2021

Hi! Please provide some example code so issue can be most easily reproduced.

@orensolo
Copy link
Contributor

orensolo commented Sep 28, 2022

Hi,

What is the status of this bug?
I have the same issue when adding arrays of objects as URL parameters (or objects that are defined with polymorphism like anyof, allof etc)

It seems that kin0openapi assumes that all query parameters arrays must contain only primitives which is not valid.
For example :

 paths:
  /nf-instances:
   get:
   - description: Names of the services offered by the NF
        explode: false
        in: query
        name: service-names
        required: false
        schema:
          items:
            $ref: '#/components/schemas/ServiceName'
          minItems: 1
          type: array
          uniqueItems: true
    ...
       ServiceName:
      anyOf:
      - $ref: '#/components/schemas/ServiceName_anyOf'
      - type: string
      description: Service names known to NRF

Thanks,
Oren

@fenollp
Copy link
Collaborator

fenollp commented Oct 14, 2022

Related: #625

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants