-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for FastAPI pydantic response models #46
Comments
I think we have support the FastAPI typing methodology.
Let us know if you face any problem. |
Thanks! This kind of works, in that the code runs, but the response model is incorrect and it doesn't play nice with FastAPI's OpenAPI documentation generation:
{
"fhir_comments": null,
"id": null,
"_id": null,
"implicitRules": null,
"_implicitRules": null,
"language": null,
"_language": null,
"meta": null,
"contained": null,
"extension": null,
"modifierExtension": null,
"text": null,
"active": null,
"_active": null,
"address": null,
"birthDate": null,
"_birthDate": null,
"communication": null,
"gender": null,
"_gender": null,
"identifier": null,
"name": null,
"photo": null,
"qualification": null,
"telecom": null,
"resourceType": "Practitioner"
} If improved FastAPI support is something you'd be open to adding to the library, I'm happy to work on a pull request to see if we can fix these issues. |
@garry-jeromson you are welcome to make your pull requests. we are fully open to add any new feature. |
if we add this to here: https://github.com/nazrulworld/fhir.resources/blob/main/fhir/resources/fhirabstractmodel.py#L516
My next question is.. how do we get the sub models to render in FastAPI? if we do something like this: I don't know if there is a way to keep HumanNameType and then like.. simply add the HumanName to the Schema somehow? |
What's the status on FastAPI? Is there any inherit functionality for fastAPI in this repository or is there a 3rd party tool now? |
FastAPI supports using pydantic models to define JSON response bodies for REST API endpoints; making FHIR resources compatible with this support would take the usability of the library to a higher level.
I'm new to the library so I don't know more about how it uses pydantic other than what is stated in the README; in any case, however pydantic is currently used, it doesn't seem to be compatible on first look. The only requirement for compatibility with FastAPI is that the response model class is derived from pydantic's
BaseModel
.A super basic example using the
Practitioner
resource from release 5.1.1, with FastAPI 0.62.0 and pydantic 1.7.3, is as follows:This gives a couple of runtime errors on endpoint setup:
This makes some sense, as the
Practitioner
resource (and most other resources, it would seem) derive fromFHIRAbstractBase
, and not pydantic'sBaseModel
.Is FastAPI support something that's been considered already? Am I missing anything obvious regarding the use of pydantic?
The text was updated successfully, but these errors were encountered: