Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define example data in a Pydantic schema.
FastAPI
from pydantic import BaseModel class User(BaseModel): name: str age: int class Config: schema_extra = {"example": [1] }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list instead of a dictionary for example data.
Not matching keys to model fields.
Using incorrect syntax for the example dictionary.
✗ Incorrect
The example data is set inside schema_extra as a dictionary with keys matching the model fields.
2fill in blank
mediumComplete the code to add example data for a Product schema.
FastAPI
from pydantic import BaseModel class Product(BaseModel): id: int name: str price: float class Config: schema_extra = {"example": [1] }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using string instead of int for id.
Using number instead of string for name.
Using string instead of float for price.
✗ Incorrect
Example data must match the field types: id as int, name as str, price as float.
3fill in blank
hardFix the error in the example data for the Address schema.
FastAPI
from pydantic import BaseModel class Address(BaseModel): street: str city: str zipcode: str class Config: schema_extra = {"example": [1] }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using an integer for zipcode instead of a string.
Using numbers for street or city fields.
✗ Incorrect
zipcode should be a string, so the value must be quoted.
4fill in blank
hardFill both blanks to add example data for a BlogPost schema with title and tags.
FastAPI
from pydantic import BaseModel from typing import List class BlogPost(BaseModel): title: str tags: List[str] class Config: schema_extra = {"example": {"title": [1], "tags": [2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using list for title or string for tags.
Not quoting the string values.
✗ Incorrect
The title is a string and tags is a list of strings, so the example must match these types.
5fill in blank
hardFill all three blanks to add example data for a UserProfile schema with username, email, and active status.
FastAPI
from pydantic import BaseModel class UserProfile(BaseModel): username: str email: str active: bool class Config: schema_extra = {"example": {"username": [1], "email": [2], "active": [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting string values.
Quoting boolean values as strings.
Using invalid boolean literals.
✗ Incorrect
Username and email are strings and must be quoted; active is a boolean and should be true or false without quotes.