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.

Rename 'additionalProp1' in docs to a more descriptive one

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.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

from fastapi import FastAPI
from pydantic import BaseModel, Field, parse_obj_as

app = FastAPI()

City = str  # a type alias

class Misc(BaseModel):
    content: dict = Field(description="All other data here.")

class CompanyDataOut(BaseModel):
    __root__: dict[City, Misc]

@app.post("/", response_model=CompanyDataOut)
async def test():
    m = Misc(content={})
    return {"New York": m}

Description

Open the docs.

It shows response example as:

{
  "additionalProp1": {
    "content": {}
  },
  "additionalProp2": {
    "content": {}
  },
  "additionalProp3": {
    "content": {}
  }
}

Instead of ‘additionalProp1,2,3’ I would like to see ‘city1,2,3’, to let the user know that the key is a city, like below :

{
  "city1": {
    "content": {}
  },
  "city2": {
    "content": {}
  },
  "city3": {
    "content": {}
  }
}

Operating System

Windows

Operating System Details

No response

FastAPI Version

0.70.0

Python Version

3.10

Additional Context

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Jedorecommented, Oct 10, 2022

You can add a custom example:

class CompanyDataOut(BaseModel):
    __root__: dict[City, Misc] = Field(example="""
{
  "city1": {
    "content": {}
  },
  "city2": {
    "content": {}
  },
  "city3": {
    "content": {}
  }
}""")
0reactions
github-actions[bot]commented, Nov 22, 2022

Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add a title, heading, or table of contents in a document
Make a title or heading · On your computer, open a document in Google Docs. · Select the text you want to change....
Read more >
Adding Examples - Swagger
Swagger allows examples on the response level, each example corresponding to a specific MIME type returned by the operation. Such as one example...
Read more >
Creating Accessible Google Drive Documents
one simple trick is to imagine describing the image to someone over the phone. The more important an image's content is, the more...
Read more >
How can I change the request body in Swagger 1.5 to an ...
Even by using @RequestBody we need to add additional annotation within TaskConfig class. We are using Swagger 2.0.x.
Read more >
How to Change Margins in Google Docs - Wordable
Resizing & compressing images one-by-one before uploading back into your content,; ❌ Optimizing images with descriptive file names & alt text ...
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