@@ -1485,24 +1485,11 @@ def get_openapi_schema(
1485
1485
get_definitions ,
1486
1486
)
1487
1487
from aws_lambda_powertools .event_handler .openapi .models import OpenAPI , PathItem , Server , Tag
1488
- from aws_lambda_powertools .event_handler .openapi .pydantic_loader import PYDANTIC_V2
1489
1488
from aws_lambda_powertools .event_handler .openapi .types import (
1490
1489
COMPONENT_REF_TEMPLATE ,
1491
1490
)
1492
1491
1493
- # Pydantic V2 has no support for OpenAPI schema 3.0
1494
- if PYDANTIC_V2 and not openapi_version .startswith ("3.1" ):
1495
- warnings .warn (
1496
- "You are using Pydantic v2, which is incompatible with OpenAPI schema 3.0. Forcing OpenAPI 3.1" ,
1497
- stacklevel = 2 ,
1498
- )
1499
- openapi_version = "3.1.0"
1500
- elif not PYDANTIC_V2 and not openapi_version .startswith ("3.0" ):
1501
- warnings .warn (
1502
- "You are using Pydantic v1, which is incompatible with OpenAPI schema 3.1. Forcing OpenAPI 3.0" ,
1503
- stacklevel = 2 ,
1504
- )
1505
- openapi_version = "3.0.3"
1492
+ openapi_version = self ._determine_openapi_version (openapi_version )
1506
1493
1507
1494
# Start with the bare minimum required for a valid OpenAPI schema
1508
1495
info : Dict [str , Any ] = {"title" : title , "version" : version }
@@ -1582,6 +1569,25 @@ def get_openapi_schema(
1582
1569
1583
1570
return OpenAPI (** output )
1584
1571
1572
+ @staticmethod
1573
+ def _determine_openapi_version (openapi_version ):
1574
+ from aws_lambda_powertools .event_handler .openapi .pydantic_loader import PYDANTIC_V2
1575
+
1576
+ # Pydantic V2 has no support for OpenAPI schema 3.0
1577
+ if PYDANTIC_V2 and not openapi_version .startswith ("3.1" ):
1578
+ warnings .warn (
1579
+ "You are using Pydantic v2, which is incompatible with OpenAPI schema 3.0. Forcing OpenAPI 3.1" ,
1580
+ stacklevel = 2 ,
1581
+ )
1582
+ openapi_version = "3.1.0"
1583
+ elif not PYDANTIC_V2 and not openapi_version .startswith ("3.0" ):
1584
+ warnings .warn (
1585
+ "You are using Pydantic v1, which is incompatible with OpenAPI schema 3.1. Forcing OpenAPI 3.0" ,
1586
+ stacklevel = 2 ,
1587
+ )
1588
+ openapi_version = "3.0.3"
1589
+ return openapi_version
1590
+
1585
1591
def get_openapi_json_schema (
1586
1592
self ,
1587
1593
* ,
0 commit comments