FastAPI Request Sample Data - Sample Data Listing: OpenAPI

Let's put the relationships into the model's test data.

Also here if we want a list of options we can use the so-called Open app examples following a bit the same structure or do we have to vary it a bit better said for example here we have to place one here for the dictionary and a summary to indicate the description in this case this text will be used at the time of a Select that is if we have a list of examples:

@task_router.put("/",status_code=status.HTTP_200_OK)
def update(index: int, task: Task = Body(
    examples=[
                {
                   "id" : 123,
                    "name": "Salvar al mundo",
                    "description": "Hola Mundo Desc",
                    "status": 'PENDING',
                    "tag":["tag 1", "tag 2"],
                },
                {
                    "name": "Bar",
                },
                {
                    "name": "Baz",
                },
            ],
)):
    ***

So the Label for the option is going to be the one we define here at the level of adding the description is optional if I remember correctly and for the rest here we have the value to define the values. So let's do the exercise. I'm going to comment on this at this point when we comment on this here we should not have the example that we defined previously but the one of the model and we place Open API examples here which is the same. Here you can really place anything. This is not like who says rendering, place example here we define it before the values. We define the one that this is going to be taken by suary. Here I don't know. First example. This is by the way with the object, I say the dictionary. Now it should take it. I remove this for here. Perfect. Now I'm going to move on to the value. So here I put value which is another object. I say another dictionary, that is, a dictionary inside another dictionary inside another dictionary. Here the comma was missing. And here you would finally place the Data. I'm going to place this so as not to complicate things further. Place this here. We save. Let's see. Here we reload. Now here we have our Select but obviously we only have one but at least now it is is taking in this case it is not an array but we do have several options or we can place several options we duplicate here I am going to place example 2 Here also a two Here I am going to place a four Here I am going to remove this and you can customize it as you prefer I place label four here for example and if you want to place another you know that you simply have to duplicate in this case a Select should appear with two elements which are these two that I am pointing out here So let's check and there you have it and notice that the example you are going to use varies

- Andrés Cruz

En español

This material is part of my complete course and book; You can purchase them from the books and/or courses section, Curso y Libro Primeros pasos con FastApi - 2025.

Andrés Cruz

Develop with Laravel, Django, Flask, CodeIgniter, HTML5, CSS3, MySQL, JavaScript, Vue, Android, iOS, Flutter

Andrés Cruz In Udemy

I agree to receive announcements of interest about this Blog.

!Courses from!

10$

On Udemy

There are 2d 00:08!


Udemy

!Courses from!

4$

In Academy

View courses

!Books from!

1$

View books
¡Become an affiliate on Gumroad!