File tree 2 files changed +44
-2
lines changed
2 files changed +44
-2
lines changed Original file line number Diff line number Diff line change @@ -20,9 +20,9 @@ class Schema(BaseModel):
20
20
title : Optional [str ] = None
21
21
multipleOf : Optional [float ] = Field (default = None , gt = 0.0 )
22
22
maximum : Optional [float ] = None
23
- exclusiveMaximum : Optional [bool ] = None
23
+ exclusiveMaximum : Optional [float ] = None
24
24
minimum : Optional [float ] = None
25
- exclusiveMinimum : Optional [bool ] = None
25
+ exclusiveMinimum : Optional [float ] = None
26
26
maxLength : Optional [int ] = Field (default = None , ge = 0 )
27
27
minLength : Optional [int ] = Field (default = None , ge = 0 )
28
28
pattern : Optional [str ] = None
Original file line number Diff line number Diff line change
1
+ # -*- coding: utf-8 -*-
2
+ # @Author : llc
3
+ # @Time : 2024/4/19 20:53
4
+
5
+ import pytest
6
+ from pydantic import BaseModel , Field
7
+
8
+ from flask_openapi3 import OpenAPI
9
+
10
+ app = OpenAPI (__name__ )
11
+ app .config ["TESTING" ] = True
12
+
13
+
14
+ class MyModel (BaseModel ):
15
+ num_1 : int = Field (..., ge = 1 , le = 10 )
16
+ num_2 : int = Field (..., gt = 1 , lt = 10 )
17
+
18
+
19
+ @app .post ('/book' )
20
+ def create_book (body : MyModel ):
21
+ return body .dict ()
22
+
23
+
24
+ @pytest .fixture
25
+ def client ():
26
+ client = app .test_client ()
27
+ return client
28
+
29
+
30
+ def test_openapi (client ):
31
+ resp = client .get ("/openapi/openapi.json" )
32
+ assert resp .status_code == 200
33
+ assert resp .json == app .api_doc
34
+
35
+ model_props = resp .json ['components' ]['schemas' ]['MyModel' ]['properties' ]
36
+ num_1_props = model_props ['num_1' ]
37
+ num_2_props = model_props ['num_2' ]
38
+
39
+ assert num_1_props ['minimum' ] == 1
40
+ assert num_1_props ['maximum' ] == 10
41
+ assert num_2_props ['exclusiveMinimum' ] == 1
42
+ assert num_2_props ['exclusiveMaximum' ] == 10
You can’t perform that action at this time.
0 commit comments