Skip to content
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

Rework update_openapi function. #523

Merged
merged 6 commits into from
Feb 7, 2023

Conversation

eseglem
Copy link
Contributor

@eseglem eseglem commented Feb 6, 2023

Related Issue(s):

Description:
The current implementation of update_openapi duplicates code from fastapi/applications.py#L216 without context and could end up out of sync with the source. Rather than duplicating code this implementation just wraps it and modifies the response's content-type header.

While there are tests for the content-type header in other portions of the repo, there was not one in stac_fastapi/api/tests. To ease debugging I added a test to have one closer to the code that implements it.

I also removed the code that was marked with a TODO to remove or fix it. It was not being utilized and it seems like stac_fastapi/api/app.py#L311 would be the place to do any changes in the future. While I did just notice #499 would remove that function for now, I still believe that would be the appropriate location if modifications to the schema are necessary in the future.

PR Checklist:

  • Code is formatted and linted (run pre-commit run --all-files)
  • Tests pass (run make test)
  • Documentation has been updated to reflect changes, if applicable, and docs build successfully (run make docs)
  • Changes are added to the CHANGELOG.

@gadomski gadomski self-requested a review February 6, 2023 17:10
Copy link
Member

@gadomski gadomski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good -- I left one inline comment requesting more documentation so I can feel better about my knowledge of how the patching is working.

I requested changes b/c I think it would be more appropriate to deprecate, rather than than remove, the unused functions and classes. While we don't have a published deprecation strategy for stac-fastapi (note to self: TODO), there's enough implementations of this repo in the wild that I'm cautious about any breaking changes, however small. IMO deprecating both VndOaiRespone and config_openapi, with a plan to remove in v3.0, would be appropriate.

Thanks for the contribution!

stac_fastapi/api/stac_fastapi/api/openapi.py Outdated Show resolved Hide resolved
stac_fastapi/api/stac_fastapi/api/openapi.py Show resolved Hide resolved
stac_fastapi/api/stac_fastapi/api/openapi.py Outdated Show resolved Hide resolved
@eseglem
Copy link
Contributor Author

eseglem commented Feb 7, 2023

@gadomski Added the functions back and added some deprecation warnings to them. It seems unlikely to be necessary, but being cautious is reasonable.

It doesn't prevent private repos from using them, but there are no repos outside of stac-utils that have any mention of VndOaiResponse. And the only other use of config_openapi is an earlier fork: https://github.com/c-core-labs/stac-api which contains the function itself. The config_openapi also calls a function which no longer exists, and it probably cannot be used without an error.

I also made some minor tweaks to the patch to hopefully make it more clear. There are potentially other options, like a hybrid of the old implementation of this one. Still create a new route, but with this patched endpoint function. I am certainly biased, but I prefer this way because it requires the least changes and code so there are less things to go wrong.

Copy link
Collaborator

@geospatial-jeff geospatial-jeff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gadomski gadomski self-requested a review February 7, 2023 12:52
@gadomski gadomski added this to the 2.4.4 milestone Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants