softwaremill / softwaremill/tapir
[BUG] Open API Parameter Serialization
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 1.5k
- Forks
- 468
- Avg merge
- 5h 37m
- Merged PRs (30d)
- 34
Description
Tapir version: 0.16.16
Scala version: 2.13.1
Describe the bug
I want to use objects in query parameters
def jsonQuery[T: Encoder : Decoder : Schema](name: String): EndpointInput.Query[T] = {
implicit val codec = Codec.string.mapDecode(x => decode[T](x).fold(
x => DecodeResult.Error("json parse error", x),
x => DecodeResult.Value(x)))(_.asJson.noSpaces)
.schema(implicitly[Schema[T]])
query[T](name)
}
val foo = endpoint.in("foo")
.in(jsonQuery[Sort]("sort")).out(jsonBody[Sort])
Tapir generate this yaml
openapi: 3.0.1
info:
title: API
version: '1.0'
paths:
/foo:
get:
operationId: getFoo
parameters:
- name: sort
in: query
required: true
schema:
$ref: '#/components/schemas/Sort'
responses:
'200':
description: ''
content:
application/json:
schema:
$ref: '#/components/schemas/Sort'
components:
schemas:
Sort:
required:
- field
- order
type: object
properties:
field:
type: string
order:
type: string
Open Api support 3 types of object serialization in query
https://swagger.io/docs/specification/serialization/#query
style:style explode:true /users?role=admin&firstName=Alex (default)
style:style explode:false /users?id=role,admin,firstName,Alex
style:deepObject explode:true /users?id[role]=admin&id[firstName]=Alex
Tapir doesn't add any style or explode parameters so url for endpoint should be
/foo?field=a&order=b
But such url doesn't work
Invalid value for: query parameter sort
Neither do
/foo?sort=field,a,order,b
/foo?sort[field]=a&sort[order]=b
I think Tapir should use deepObject:true in object query parameters and support urls like /foo?sort[field]=a&sort[order]=b
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing Tapir's OpenAPI query-parameter generation and the corresponding query decoding for EndpointInput.Query, using the serialization styles and example URLs cited in the issue. Compare the generated specification with the supported request forms; done should make the chosen object serialization explicit and ensure the documented URL form is accepted consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, scala
- Domain
- api, backend-api-design
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100