File tree Expand file tree Collapse file tree 2 files changed +45
-2
lines changed Expand file tree Collapse file tree 2 files changed +45
-2
lines changed Original file line number Diff line number Diff line change 33# @Time : 2023/7/4 9:57
44from typing import List , Optional
55
6- from pydantic import BaseModel
6+ from pydantic import BaseModel , Field
77
88
99class ServerVariable (BaseModel ):
1010 """
1111 https://spec.openapis.org/oas/v3.1.0#server-variable-object
1212 """
1313
14- enum : List [str ]
14+ enum : Optional [ List [str ]] = Field ( None , min_length = 1 )
1515 default : str
1616 description : Optional [str ] = None
1717
Original file line number Diff line number Diff line change 1+ # -*- coding: utf-8 -*-
2+ # @Author : llc
3+ # @Time : 2024/11/10 12:17
4+ from pydantic import ValidationError
5+
6+ from flask_openapi3 import Server , ServerVariable
7+
8+
9+ def test_server_variable ():
10+ Server (
11+ url = "http://127.0.0.1:5000" ,
12+ variables = None
13+ )
14+ try :
15+ variables = {"one" : ServerVariable (default = "one" , enum = [])}
16+ Server (
17+ url = "http://127.0.0.1:5000" ,
18+ variables = variables
19+ )
20+ error = 0
21+ except ValidationError :
22+ error = 1
23+ assert error == 1
24+ try :
25+ variables = {"one" : ServerVariable (default = "one" )}
26+ Server (
27+ url = "http://127.0.0.1:5000" ,
28+ variables = variables
29+ )
30+ error = 0
31+ except ValidationError :
32+ error = 1
33+ assert error == 0
34+ try :
35+ variables = {"one" : ServerVariable (default = "one" , enum = ["one" , "two" ])}
36+ Server (
37+ url = "http://127.0.0.1:5000" ,
38+ variables = variables
39+ )
40+ error = 0
41+ except ValidationError :
42+ error = 1
43+ assert error == 0
You can’t perform that action at this time.
0 commit comments