Add support for Pydantic v1 and above 🎉 (#646)

* Make compatible with pydantic v1

* Remove unused import

* Remove unused ignores

* Update pydantic version

* Fix minor formatting issue

*  Revert removing iterate_in_threadpool

*  Add backwards compatibility with Pydantic 0.32.2

with deprecation warnings

*  Update tests to not break when using Pydantic < 1.0.0

* 📝 Update docs for Pydantic version 1.0.0

* 📌 Update Pydantic range version to support from 0.32.2

* 🎨 Format test imports

*  Add support for Pydantic < 1.2 for populate_validators

*  Add backwards compatibility for Pydantic < 1.2.0 with required fields

* 📌 Relax requirement for Pydantic to < 2.0.0 🎉 🚀

* 💚 Update pragma coverage for older Pydantic versions
This commit is contained in:
dmontagu
2019-11-27 11:32:02 -08:00
committed by Sebastián Ramírez
parent 90a5796b94
commit ab2b86fe2c
66 changed files with 802 additions and 425 deletions

View File

@@ -43,7 +43,7 @@ openapi_schema = {
"parameters": [
{
"required": True,
"schema": {"title": "Item_Id", "type": "string"},
"schema": {"title": "Item Id", "type": "string"},
"name": "item_id",
"in": "path",
}

View File

@@ -39,7 +39,7 @@ openapi_schema = {
"parameters": [
{
"required": True,
"schema": {"title": "Item_Id", "type": "string"},
"schema": {"title": "Item Id", "type": "string"},
"name": "item_id",
"in": "path",
},

View File

@@ -44,7 +44,7 @@ openapi_schema = {
"parameters": [
{
"required": True,
"schema": {"title": "Item_Id", "type": "string"},
"schema": {"title": "Item Id", "type": "string"},
"name": "item_id",
"in": "path",
}

View File

@@ -42,7 +42,7 @@ openapi_schema = {
"parameters": [
{
"required": True,
"schema": {"title": "Item_Id", "type": "string"},
"schema": {"title": "Item Id", "type": "string"},
"name": "item_id",
"in": "path",
},

View File

@@ -14,7 +14,7 @@ openapi_schema = {
"content": {
"application/json": {
"schema": {
"title": "Response_Read_Notes_Notes__Get",
"title": "Response Read Notes Notes Get",
"type": "array",
"items": {"$ref": "#/components/schemas/Note"},
}

View File

@@ -123,7 +123,7 @@ openapi_schema = {
"parameters": [
{
"required": True,
"schema": {"title": "Item_Id", "type": "string"},
"schema": {"title": "Item Id", "type": "string"},
"name": "item_id",
"in": "path",
},
@@ -160,7 +160,7 @@ openapi_schema = {
"parameters": [
{
"required": True,
"schema": {"title": "Item_Id", "type": "string"},
"schema": {"title": "Item Id", "type": "string"},
"name": "item_id",
"in": "path",
},

View File

@@ -32,7 +32,7 @@ openapi_schema = {
"parameters": [
{
"required": True,
"schema": {"title": "Item_Id", "type": "integer"},
"schema": {"title": "Item Id", "type": "integer"},
"name": "item_id",
"in": "path",
}
@@ -69,7 +69,7 @@ openapi_schema = {
"type": "object",
"properties": {
"username": {"title": "Username", "type": "string"},
"full_name": {"title": "Full_Name", "type": "string"},
"full_name": {"title": "Full Name", "type": "string"},
},
},
"Body_update_item_items__item_id__put": {

View File

@@ -3,6 +3,15 @@ from starlette.testclient import TestClient
from body_schema.tutorial001 import app
# TODO: remove when removing support for Pydantic < 1.0.0
try:
from pydantic import Field # noqa
except ImportError: # pragma: nocover
import pydantic
pydantic.Field = pydantic.Schema
client = TestClient(app)
@@ -33,7 +42,7 @@ openapi_schema = {
"parameters": [
{
"required": True,
"schema": {"title": "Item_Id", "type": "integer"},
"schema": {"title": "Item Id", "type": "integer"},
"name": "item_id",
"in": "path",
}

View File

@@ -35,7 +35,7 @@ openapi_schema = {
"parameters": [
{
"required": True,
"schema": {"title": "Item_Id", "type": "string"},
"schema": {"title": "Item Id", "type": "string"},
"name": "item_id",
"in": "path",
}
@@ -67,7 +67,7 @@ openapi_schema = {
"parameters": [
{
"required": True,
"schema": {"title": "Item_Id", "type": "string"},
"schema": {"title": "Item Id", "type": "string"},
"name": "item_id",
"in": "path",
}

View File

@@ -32,7 +32,7 @@ openapi_schema = {
"parameters": [
{
"required": False,
"schema": {"title": "Ads_Id", "type": "string"},
"schema": {"title": "Ads Id", "type": "string"},
"name": "ads_id",
"in": "cookie",
}

View File

@@ -29,7 +29,7 @@ openapi_schema = {
"parameters": [
{
"required": True,
"schema": {"title": "Item_Id", "type": "string"},
"schema": {"title": "Item Id", "type": "string"},
"name": "item_id",
"in": "path",
}

View File

@@ -33,7 +33,7 @@ openapi_schema = {
{
"required": True,
"schema": {
"title": "Item_Id",
"title": "Item Id",
"type": "string",
"format": "uuid",
},
@@ -60,22 +60,22 @@ openapi_schema = {
"type": "object",
"properties": {
"start_datetime": {
"title": "Start_Datetime",
"title": "Start Datetime",
"type": "string",
"format": "date-time",
},
"end_datetime": {
"title": "End_Datetime",
"title": "End Datetime",
"type": "string",
"format": "date-time",
},
"repeat_at": {
"title": "Repeat_At",
"title": "Repeat At",
"type": "string",
"format": "time",
},
"process_after": {
"title": "Process_After",
"title": "Process After",
"type": "number",
"format": "time-delta",
},

View File

@@ -16,7 +16,7 @@ openapi_schema = {
"content": {
"application/json": {
"schema": {
"title": "Response_Read_Item_Items__Item_Id__Get",
"title": "Response Read Item Items Item Id Get",
"anyOf": [
{"$ref": "#/components/schemas/PlaneItem"},
{"$ref": "#/components/schemas/CarItem"},
@@ -41,7 +41,7 @@ openapi_schema = {
"parameters": [
{
"required": True,
"schema": {"title": "Item_Id", "type": "string"},
"schema": {"title": "Item Id", "type": "string"},
"name": "item_id",
"in": "path",
}

View File

@@ -16,7 +16,7 @@ openapi_schema = {
"content": {
"application/json": {
"schema": {
"title": "Response_Read_Items_Items__Get",
"title": "Response Read Items Items Get",
"type": "array",
"items": {"$ref": "#/components/schemas/Item"},
}

View File

@@ -16,7 +16,7 @@ openapi_schema = {
"content": {
"application/json": {
"schema": {
"title": "Response_Read_Keyword_Weights_Keyword-Weights__Get",
"title": "Response Read Keyword Weights Keyword-Weights Get",
"type": "object",
"additionalProperties": {"type": "number"},
}

View File

@@ -31,7 +31,7 @@ openapi_schema = {
"parameters": [
{
"required": True,
"schema": {"title": "Item_Id", "type": "string"},
"schema": {"title": "Item Id", "type": "string"},
"name": "item_id",
"in": "path",
}

View File

@@ -31,7 +31,7 @@ openapi_schema = {
"parameters": [
{
"required": True,
"schema": {"title": "Item_Id", "type": "string"},
"schema": {"title": "Item Id", "type": "string"},
"name": "item_id",
"in": "path",
}

View File

@@ -31,7 +31,7 @@ openapi_schema = {
"parameters": [
{
"required": True,
"schema": {"title": "Item_Id", "type": "integer"},
"schema": {"title": "Item Id", "type": "integer"},
"name": "item_id",
"in": "path",
}

View File

@@ -31,7 +31,7 @@ openapi_schema = {
"parameters": [
{
"required": True,
"schema": {"title": "Item_Id", "type": "integer"},
"schema": {"title": "Item Id", "type": "integer"},
"name": "item_id",
"in": "path",
}

View File

@@ -31,7 +31,7 @@ openapi_schema = {
"parameters": [
{
"required": True,
"schema": {"title": "File_Path", "type": "string"},
"schema": {"title": "File Path", "type": "string"},
"name": "file_path",
"in": "path",
}

View File

@@ -33,7 +33,7 @@ openapi_schema = {
{
"required": True,
"schema": {
"title": "Model_Name",
"title": "Model Name",
"enum": ["alexnet", "resnet", "lenet"],
"type": "string",
},

View File

@@ -32,7 +32,7 @@ openapi_schema = {
"parameters": [
{
"required": True,
"schema": {"title": "Item_Id", "type": "string"},
"schema": {"title": "Item Id", "type": "string"},
"name": "item_id",
"in": "path",
},

View File

@@ -32,7 +32,7 @@ openapi_schema = {
"parameters": [
{
"required": True,
"schema": {"title": "Item_Id", "type": "string"},
"schema": {"title": "Item Id", "type": "string"},
"name": "item_id",
"in": "path",
},

View File

@@ -31,7 +31,7 @@ openapi_schema = {
"parameters": [
{
"required": True,
"schema": {"title": "Item_Id", "type": "string"},
"schema": {"title": "Item Id", "type": "string"},
"name": "item_id",
"in": "path",
},

View File

@@ -52,7 +52,7 @@ openapi_schema = {
"properties": {
"username": {"title": "Username", "type": "string"},
"email": {"title": "Email", "type": "string", "format": "email"},
"full_name": {"title": "Full_Name", "type": "string"},
"full_name": {"title": "Full Name", "type": "string"},
},
},
"UserIn": {
@@ -63,7 +63,7 @@ openapi_schema = {
"username": {"title": "Username", "type": "string"},
"password": {"title": "Password", "type": "string"},
"email": {"title": "Email", "type": "string", "format": "email"},
"full_name": {"title": "Full_Name", "type": "string"},
"full_name": {"title": "Full Name", "type": "string"},
},
},
"ValidationError": {

View File

@@ -36,7 +36,7 @@ openapi_schema = {
"parameters": [
{
"required": True,
"schema": {"title": "Item_Id", "type": "string"},
"schema": {"title": "Item Id", "type": "string"},
"name": "item_id",
"in": "path",
}

View File

@@ -35,7 +35,7 @@ openapi_schema = {
"parameters": [
{
"required": True,
"schema": {"title": "Item_Id", "type": "string"},
"schema": {"title": "Item Id", "type": "string"},
"name": "item_id",
"in": "path",
}
@@ -69,7 +69,7 @@ openapi_schema = {
"parameters": [
{
"required": True,
"schema": {"title": "Item_Id", "type": "string"},
"schema": {"title": "Item Id", "type": "string"},
"name": "item_id",
"in": "path",
}

View File

@@ -35,7 +35,7 @@ openapi_schema = {
"parameters": [
{
"required": True,
"schema": {"title": "Item_Id", "type": "string"},
"schema": {"title": "Item Id", "type": "string"},
"name": "item_id",
"in": "path",
}
@@ -69,7 +69,7 @@ openapi_schema = {
"parameters": [
{
"required": True,
"schema": {"title": "Item_Id", "type": "string"},
"schema": {"title": "Item Id", "type": "string"},
"name": "item_id",
"in": "path",
}

View File

@@ -62,15 +62,15 @@ openapi_schema = {
"type": "object",
"properties": {
"grant_type": {
"title": "Grant_Type",
"title": "Grant Type",
"pattern": "password",
"type": "string",
},
"username": {"title": "Username", "type": "string"},
"password": {"title": "Password", "type": "string"},
"scope": {"title": "Scope", "type": "string", "default": ""},
"client_id": {"title": "Client_Id", "type": "string"},
"client_secret": {"title": "Client_Secret", "type": "string"},
"client_id": {"title": "Client Id", "type": "string"},
"client_secret": {"title": "Client Secret", "type": "string"},
},
},
"ValidationError": {

View File

@@ -103,7 +103,7 @@ openapi_schema = {
"properties": {
"username": {"title": "Username", "type": "string"},
"email": {"title": "Email", "type": "string"},
"full_name": {"title": "Full_Name", "type": "string"},
"full_name": {"title": "Full Name", "type": "string"},
"disabled": {"title": "Disabled", "type": "boolean"},
},
},
@@ -112,8 +112,8 @@ openapi_schema = {
"required": ["access_token", "token_type"],
"type": "object",
"properties": {
"access_token": {"title": "Access_Token", "type": "string"},
"token_type": {"title": "Token_Type", "type": "string"},
"access_token": {"title": "Access Token", "type": "string"},
"token_type": {"title": "Token Type", "type": "string"},
},
},
"Body_login_for_access_token_token_post": {
@@ -122,15 +122,15 @@ openapi_schema = {
"type": "object",
"properties": {
"grant_type": {
"title": "Grant_Type",
"title": "Grant Type",
"pattern": "password",
"type": "string",
},
"username": {"title": "Username", "type": "string"},
"password": {"title": "Password", "type": "string"},
"scope": {"title": "Scope", "type": "string", "default": ""},
"client_id": {"title": "Client_Id", "type": "string"},
"client_secret": {"title": "Client_Secret", "type": "string"},
"client_id": {"title": "Client Id", "type": "string"},
"client_secret": {"title": "Client Secret", "type": "string"},
},
},
"ValidationError": {

View File

@@ -15,7 +15,7 @@ openapi_schema = {
"content": {
"application/json": {
"schema": {
"title": "Response_Read_Users_Users__Get",
"title": "Response Read Users Users Get",
"type": "array",
"items": {"$ref": "#/components/schemas/User"},
}
@@ -110,7 +110,7 @@ openapi_schema = {
"parameters": [
{
"required": True,
"schema": {"title": "User_Id", "type": "integer"},
"schema": {"title": "User Id", "type": "integer"},
"name": "user_id",
"in": "path",
}
@@ -144,7 +144,7 @@ openapi_schema = {
"parameters": [
{
"required": True,
"schema": {"title": "User_Id", "type": "integer"},
"schema": {"title": "User Id", "type": "integer"},
"name": "user_id",
"in": "path",
}
@@ -167,7 +167,7 @@ openapi_schema = {
"content": {
"application/json": {
"schema": {
"title": "Response_Read_Items_Items__Get",
"title": "Response Read Items Items Get",
"type": "array",
"items": {"$ref": "#/components/schemas/Item"},
}
@@ -223,7 +223,7 @@ openapi_schema = {
"title": {"title": "Title", "type": "string"},
"description": {"title": "Description", "type": "string"},
"id": {"title": "Id", "type": "integer"},
"owner_id": {"title": "Owner_Id", "type": "integer"},
"owner_id": {"title": "Owner Id", "type": "integer"},
},
},
"User": {
@@ -233,7 +233,7 @@ openapi_schema = {
"properties": {
"email": {"title": "Email", "type": "string"},
"id": {"title": "Id", "type": "integer"},
"is_active": {"title": "Is_Active", "type": "boolean"},
"is_active": {"title": "Is Active", "type": "boolean"},
"items": {
"title": "Items",
"type": "array",

View File

@@ -15,7 +15,7 @@ openapi_schema = {
"content": {
"application/json": {
"schema": {
"title": "Response_Read_Users_Users__Get",
"title": "Response Read Users Users Get",
"type": "array",
"items": {"$ref": "#/components/schemas/User"},
}
@@ -110,7 +110,7 @@ openapi_schema = {
"parameters": [
{
"required": True,
"schema": {"title": "User_Id", "type": "integer"},
"schema": {"title": "User Id", "type": "integer"},
"name": "user_id",
"in": "path",
}
@@ -144,7 +144,7 @@ openapi_schema = {
"parameters": [
{
"required": True,
"schema": {"title": "User_Id", "type": "integer"},
"schema": {"title": "User Id", "type": "integer"},
"name": "user_id",
"in": "path",
}
@@ -167,7 +167,7 @@ openapi_schema = {
"content": {
"application/json": {
"schema": {
"title": "Response_Read_Items_Items__Get",
"title": "Response Read Items Items Get",
"type": "array",
"items": {"$ref": "#/components/schemas/Item"},
}
@@ -223,7 +223,7 @@ openapi_schema = {
"title": {"title": "Title", "type": "string"},
"description": {"title": "Description", "type": "string"},
"id": {"title": "Id", "type": "integer"},
"owner_id": {"title": "Owner_Id", "type": "integer"},
"owner_id": {"title": "Owner Id", "type": "integer"},
},
},
"User": {
@@ -233,7 +233,7 @@ openapi_schema = {
"properties": {
"email": {"title": "Email", "type": "string"},
"id": {"title": "Id", "type": "integer"},
"is_active": {"title": "Is_Active", "type": "boolean"},
"is_active": {"title": "Is Active", "type": "boolean"},
"items": {
"title": "Items",
"type": "array",