Skip to content

Better APISpec init to allow to modify it before generating spec_json. #195

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

Merged
merged 2 commits into from
Jan 12, 2025

Conversation

ddorian
Copy link
Contributor

@ddorian ddorian commented Nov 12, 2024

This will make it easier for APISpec to be modified by external functions before generating the spec_json (examples: adding webhooks, registering custom components etc).

Checklist:

  • Run pytest tests and no failed.
  • Run ruff check flask_openapi3 tests examples and no failed.
  • Run mypy flask_openapi3 and no failed.
  • Run mkdocs serve and no failed.

close #190

@luolingchun
Copy link
Owner

This PR gave me some inspiration.

I don't quite agree with PR #190's approach, self._register_default_error_responses() only refactored part of the functionality.

You can expose self.generate_spec_json() function on top of this PR to implement spec_json refactoring.

self.generate_spec_json() contains all the remaining logic

@property
def api_doc(self) -> Dict:
    if self.spec_json:
        return self.spec_json

+   self.spec_json = self.generate_spec_json()
+   return self.spec_json

@ddorian
Copy link
Contributor Author

ddorian commented Nov 14, 2024

The difference is if you want to modify the whole thing or piece by piece.

Both ways would be best IMO.

@luolingchun luolingchun added this to the v4.1.0 milestone Nov 23, 2024
@luolingchun luolingchun merged commit 4428f61 into luolingchun:master Jan 12, 2025
12 checks passed
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.

2 participants