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

Fix spec command for complex data types #549

Merged
merged 2 commits into from Mar 7, 2024

Conversation

tsokalski
Copy link
Contributor

Modified the spec_command method to use the Flask application's JSON provider instead of the built-in json module when dumping the spec. This provides consistent JSON serialization behavior when using the flask spec command.

Fixes #547.

To ensure access to the .json attribute of the Flask app, I had to bump the minimum Flask version to 2.2.0 (where it was first introduced), which necessitated version bumps of Werkzeug and Flask-HTTPAuth as well. The other versioning changes were auto-generated by pip-compile-multi.

Checklist:

  • Add tests that demonstrate the correct behavior of the change. Tests should fail without the change.
  • Add or update relevant docs, in the docs folder and in code docstring.
  • Add an entry in CHANGES.md summarizing the change and linking to the issue.
  • Add *Version changed* or *Version added* note in any relevant docs and docstring.
  • Run pytest and tox, no tests failed.

@@ -40,7 +38,7 @@ def spec_command(format, output, indent):
json_indent = None if indent == 0 else indent

if spec_format == 'json':
spec = json.dumps(spec, indent=json_indent)
spec = current_app.json.dumps(spec, indent=json_indent)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change wasn't necessary to get the flask spec command working, but it seemed like it might be helpful, so I included it as well.

@greyli
Copy link
Member

greyli commented Mar 6, 2024

We need to support Flask 2.0.x and 2.1.x version, at least before the APIFlask 3.0 version (see also #479). Let's keep the .json attr change to the next major version. For now, we could just import the json module from Flask.

@tsokalski
Copy link
Contributor Author

We need to support Flask 2.0.x and 2.1.x version, at least before the APIFlask 3.0 version (see also #479). Let's keep the .json attr change to the next major version. For now, we could just import the json module from Flask.

Right, good thinking - I didn't realize the version upgrade was necessary till all the code and tests were done, and it seems overkill just to fix this. Thanks for the suggestion, I've updated the PR.

@greyli greyli merged commit dd1c823 into apiflask:main Mar 7, 2024
16 checks passed
@greyli
Copy link
Member

greyli commented Mar 7, 2024

Merged, thanks! I'll make a new fix release this weekend.

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.

flask spec command raises TypeError on decimal field validator
2 participants