Skip to content

Commit

Permalink
Fix spec command for complex data types (#549)
Browse files Browse the repository at this point in the history
* Fix spec command for complex data types

* PR feedback: switch to using Flask's json module

---------

Co-authored-by: Tayler Sokalski <tsokalski@users.noreply.github.com>
  • Loading branch information
tsokalski and tsokalski committed Mar 7, 2024
1 parent d93c470 commit dd1c823
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
Released: -
- Reuse the File, Config field, and file-related validators from flask-marshmallow ([issue #540][issue_540]).
- Add support for a `--quiet` option to the `flask spec` command ([issue #548][issue_548]).
- Fix the `flask spec` command for validators operating on complex data types ([issue #547][issue_547]).

[issue_540]: https://github.com/apiflask/apiflask/issues/540
[issue_548]: https://github.com/apiflask/apiflask/issues/548
[issue_547]: https://github.com/apiflask/apiflask/issues/547


## Version 2.1.0
Expand Down
2 changes: 1 addition & 1 deletion src/apiflask/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import inspect
import json
import re
import typing as t
import warnings
Expand All @@ -11,6 +10,7 @@
from flask import Blueprint
from flask import Flask
from flask import has_request_context
from flask import json
from flask import jsonify
from flask import render_template_string
from flask import request
Expand Down
3 changes: 1 addition & 2 deletions src/apiflask/commands.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json

import click
from flask import current_app
from flask import json
from flask.cli import with_appcontext


Expand Down
6 changes: 6 additions & 0 deletions tests/schemas.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from marshmallow import EXCLUDE
from marshmallow.validate import Range

from apiflask import Schema
from apiflask.fields import Decimal
from apiflask.fields import File
from apiflask.fields import Integer
from apiflask.fields import List
Expand Down Expand Up @@ -29,6 +31,10 @@ class Baz(Schema):
name = String()


class Qux(Schema):
number = Decimal(validate=Range(min=0))


class Query(Schema):
class Meta:
unknown = EXCLUDE
Expand Down
11 changes: 11 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest

from .schemas import Foo
from .schemas import Qux
from apiflask.commands import spec_command


Expand Down Expand Up @@ -76,3 +77,13 @@ def test_flask_spec_indent(cli_runner, indent, tmp_path):
def test_flask_spec_quiet(app, cli_runner):
result = cli_runner.invoke(spec_command, ['--quiet'])
assert result.output == ''


def test_flask_spec_decimal_field(app, cli_runner):
@app.get('/qux')
@app.output(Qux)
def qux():
pass

result = cli_runner.invoke(spec_command)
assert 'openapi' in result.output

0 comments on commit dd1c823

Please sign in to comment.