How to modify Metadata model without copying all the code #68
-
I couldn't work out a good title for this - sorry! I have an application which is using titiler-pgstac as a dependency: we don't have the whole titiler-pgstac source copied into our app, we just import the relevant bits and build up our own FastAPI application. We'd like to keep it like this if at all possible - I think this is the way it's meant to be used, and it definitely works far better for us (we've tried both ways). However, we would also like to modify the Is it possible to modify the definition of a pydantic model that is deep inside titiler-pgstac, without having to basically copy in all of the titiler-pgstac code? I've managed to do this in a 'hacky' way by doing something like this at the top of my main application file:
But it's not very nice. Is there a nicer way of doing this? I was hoping to find some way of passing the models in as a dependency, but I can't seem to find that. I'm relatively inexperienced with FastAPI, so I may be missing a way of doing this. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
👋 |
Beta Was this translation helpful? Give feedback.
-
Thanks @vincentsarago, using something like |
Beta Was this translation helpful? Give feedback.
👋
Metadata
allowsextra
(https://github.com/stac-utils/titiler-pgstac/blob/master/titiler/pgstac/model.py#L103) attribute so you could in theory just add another property in the Metadata likeassets_properties: Optional[Dict[str, Any]]
when you register your Search request. The only downside is that it won't show up in the OpenAPI schema