question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OpenAPI deepObject serialization for query parameters

See original GitHub issue

First check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn’t find it.
  • I searched the FastAPI documentation, with the integrated search.
  • I already searched in Google “How to X in FastAPI” and didn’t find any information.
  • I already read and followed all the tutorial in the docs and didn’t find an answer.
  • I already checked if it is not related to FastAPI but to Pydantic.
  • I already checked if it is not related to FastAPI but to Swagger UI.
  • I already checked if it is not related to FastAPI but to ReDoc.
  • After submitting this, I commit to:
    • Implement a Pull Request for a confirmed bug - or implement the feature described in this issue 😃

Description

Allow usage of deepObject serialization from OpenAPI 3.

What it could look like

from fastapi import FastAPI

app = FastAPI()

class UserQuery(BaseModel):
    role: str
    firstName: str

@app.get("/")
def read_root(id: Optional[UserQuery]):
    return {"Hello": "World"}

Query:

/users?id[role]=admin&id[firstName]=Alex

Related

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:14
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
adriangbcommented, Oct 26, 2021

How about just Query(style="deepObject")?

3reactions
sm-Fifteencommented, May 3, 2021

See also #283 for broader support of encoding styles.

This is the sort of issue where it’s not entirely clear if the responsibility of supporting this should be on FastAPI or Pydantic. On one hand, it has to do with value parsing and encoding, which is something FastAPI tends to fully delegate to Pydantic, but on the other hand it’s not part of JSON Schema, it’s an OpenAPI extension that only applies to route parameter objects, and most of these encoding styles don’t make sense in a JSON context (which is what pydantic is generally meant for).

I would like to see these supported as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Parameter Serialization - Swagger
OpenAPI 3.0 supports arrays and objects in operation parameters (path, query, header, ... deepObject – simple non-nested objects are serialized as ...
Read more >
How to define parameters with square brackets in OpenAPI ...
The parameter serialization method should be style: deepObject and ... Support deep objects for query parameters with deepObject style ...
Read more >
OpenAPI JSON Objects as Query Parameters - Baeldung
Learn how to specify JSON objects as query parameters using the OpenAPI specification.
Read more >
@oats-ts/openapi-parameter-serialization - npm
Start using @oats-ts/openapi-parameter-serialization in your project by ... the following structure, that you would like to express as query parameters:.
Read more >
Parameter Object - Redocly
Describes a request parameter, which excludes the request body. ... Excerpt from the OpenAPI 3.1 specification about the parameter object ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found