Skip to content

Commit f048fb0

Browse files
authored
Wrong types of exclusiveMinimum & exclusiveMaximum fields in Schema class (#149)
* fix: change type of exclusiveMinimum & exclusiveMaximum from bool to float * test: add number constraints test
1 parent 95d6e46 commit f048fb0

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

flask_openapi3/models/schema.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ class Schema(BaseModel):
2020
title: Optional[str] = None
2121
multipleOf: Optional[float] = Field(default=None, gt=0.0)
2222
maximum: Optional[float] = None
23-
exclusiveMaximum: Optional[bool] = None
23+
exclusiveMaximum: Optional[float] = None
2424
minimum: Optional[float] = None
25-
exclusiveMinimum: Optional[bool] = None
25+
exclusiveMinimum: Optional[float] = None
2626
maxLength: Optional[int] = Field(default=None, ge=0)
2727
minLength: Optional[int] = Field(default=None, ge=0)
2828
pattern: Optional[str] = None

tests/test_number_constraints.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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

0 commit comments

Comments
 (0)