luolingchun / flask-openapi3

Generate REST API and OpenAPI documentation for your Flask project.
https://luolingchun.github.io/flask-openapi3/
MIT License
203 stars 33 forks source link

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

Open ddorian opened 1 week ago

ddorian commented 1 week ago

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:

luolingchun commented 1 week ago

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 commented 1 week ago

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

Both ways would be best IMO.