You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
👋 I have noticed an edge case for generating the AsyncAPI schema. I will try to find some time to handle it soon.
Description
The generated AsyncAPI can potentially be invalid. If there are two or more models with the same name the components will refer to these models using their long name, whereas the channels will always refer to them by their short name.
To illustrate let's use the documented example:
# examples/from_readme.py
...
classPurrModel(BaseModel):
detail: strloudness: intclassBellyRubModel(BaseModel):
where_exactly: strscratches_num: int
...
purr_channel=sio_app.create_emitter(
"purrs",
model=PurrModel,
summary="Channel for purrs",
description="Receive any purrs here!",
)
@sio_app.on("rubs",model=BellyRubModel,summary="Channel for belly rubs",description="Send your belly rubs through here!",)asyncdefhandle_rub(sid, data):
awaitpurr_channel.emit(
PurrModel(loudness=2, detail="Purr for all listeners")
)
return"Ack to the one who rubbed"
In this situation, both channels and components will correctly refer to the models by their short names.
channels will reference:
BellyRubModel with "#/components/schemas/BellyRubModel"
PurrModel with "#/components/schemas/PurrModel"
components.schemas will contain:
BellyRubModel
PurrModel
Now consider the following file and model exists:
# examples/foobar.pyfrompydanticimportBaseModelclassPurrModel(BaseModel):
foo: strbar: int
and the models is used in the example above:
# examples/from_readme.py+ from examples.xyz import PurrModel as YetAnotherPurrModel
...
class PurrModel(BaseModel):
detail: str
loudness: int
class BellyRubModel(BaseModel):
where_exactly: str
scratches_num: int
...
purr_channel = sio_app.create_emitter(
"purrs",
model=PurrModel,
summary="Channel for purrs",
description="Receive any purrs here!",
)
+ yet_another_purr_channel = sio_app.create_emitter(+ "purrs2",+ model=YetAnotherPurrModel,+ summary="Channel for purrs",+ description="Receive more purrs here!",+)
@sio_app.on(
"rubs",
model=BellyRubModel,
summary="Channel for belly rubs",
description="Send your belly rubs through here!",
)
async def handle_rub(sid, data):
await purr_channel.emit(
PurrModel(loudness=2, detail="Purr for all listeners")
)
return "Ack to the one who rubbed"
Channels will still reference the models by their short names, but the components will contain long names for the models with duplicate names.
channels will reference:
BellyRubModel with "#/components/schemas/BellyRubModel"
👋 I have noticed an edge case for generating the
AsyncAPI
schema. I will try to find some time to handle it soon.Description
The generated
AsyncAPI
can potentially be invalid. If there are two or more models with the same name thecomponents
will refer to these models using their long name, whereas thechannels
will always refer to them by their short name.To illustrate let's use the documented example:
In this situation, both
channels
andcomponents
will correctly refer to the models by their short names.channels
will reference:BellyRubModel
with"#/components/schemas/BellyRubModel"
PurrModel
with"#/components/schemas/PurrModel"
components.schemas
will contain:BellyRubModel
PurrModel
Now consider the following file and model exists:
and the models is used in the example above:
Channels will still reference the models by their short names, but the components will contain long names for the models with duplicate names.
channels
will reference:BellyRubModel
with"#/components/schemas/BellyRubModel"
PurrModel
with"#/components/schemas/PurrModel"
components.schemas
will contain:BellyRubModel
examples__from_readme__PurrModel
examples__foobar__PurrModel
Full example with the generated schema is available in this AsyncAPI Studio
The text was updated successfully, but these errors were encountered: