deepObject parameters that are not flat cause panic
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
The same error surfaces when adding arrays of objects as URL parameters.
Hi! Please provide some example code so issue can be most easily reproduced.
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
Related: https://github.com/getkin/kin-openapi/issues/625