File tree 2 files changed +45
-2
lines changed
2 files changed +45
-2
lines changed Original file line number Diff line number Diff line change 3
3
# @Time : 2023/7/4 9:57
4
4
from typing import List , Optional
5
5
6
- from pydantic import BaseModel
6
+ from pydantic import BaseModel , Field
7
7
8
8
9
9
class ServerVariable (BaseModel ):
10
10
"""
11
11
https://spec.openapis.org/oas/v3.1.0#server-variable-object
12
12
"""
13
13
14
- enum : List [str ]
14
+ enum : Optional [ List [str ]] = Field ( None , min_length = 1 )
15
15
default : str
16
16
description : Optional [str ] = None
17
17
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