Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion openapi_schema_pydantic/v3/v3_0_3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from .path_item import PathItem
from .operation import Operation
from .external_documentation import ExternalDocumentation
from .parameter import Parameter
from .parameter import Parameter, ParameterLocation
from .request_body import RequestBody
from .media_type import MediaType
from .encoding import Encoding
Expand Down
4 changes: 2 additions & 2 deletions openapi_schema_pydantic/v3/v3_0_3/header.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pydantic import Extra, Field

from .parameter import Parameter
from .parameter import Parameter, ParameterLocation


class Header(Parameter):
Expand All @@ -14,7 +14,7 @@ class Header(Parameter):
"""

name = Field(default="", const=True)
param_in = Field(default="header", const=True, alias="in")
param_in = Field(default=ParameterLocation.HEADER, const=True, alias="in")

class Config:
extra = Extra.ignore
Expand Down
12 changes: 11 additions & 1 deletion openapi_schema_pydantic/v3/v3_0_3/parameter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import enum
from typing import Any, Dict, Optional, Union

from pydantic import BaseModel, Field, Extra
Expand All @@ -8,6 +9,15 @@
from .schema import Schema


class ParameterLocation(str, enum.Enum):
"""The location of a given parameter."""

QUERY = "query"
HEADER = "header"
PATH = "path"
COOKIE = "cookie"


class Parameter(BaseModel):
"""
Describes a single operation parameter.
Expand All @@ -30,7 +40,7 @@ class Parameter(BaseModel):
- For all other cases, the `name` corresponds to the parameter name used by the [`in`](#parameterIn) property.
"""

param_in: str = Field(alias="in")
param_in: ParameterLocation = Field(alias="in")
"""
**REQUIRED**. The location of the parameter. Possible values are `"query"`, `"header"`, `"path"` or `"cookie"`.
"""
Expand Down
2 changes: 1 addition & 1 deletion openapi_schema_pydantic/v3/v3_1_0/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from .path_item import PathItem
from .operation import Operation
from .external_documentation import ExternalDocumentation
from .parameter import Parameter
from .parameter import Parameter, ParameterLocation
from .request_body import RequestBody
from .media_type import MediaType
from .encoding import Encoding
Expand Down
4 changes: 2 additions & 2 deletions openapi_schema_pydantic/v3/v3_1_0/header.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pydantic import Extra, Field

from .parameter import Parameter
from .parameter import Parameter, ParameterLocation


class Header(Parameter):
Expand All @@ -14,7 +14,7 @@ class Header(Parameter):
"""

name = Field(default="", const=True)
param_in = Field(default="header", const=True, alias="in")
param_in = Field(default=ParameterLocation.HEADER, const=True, alias="in")

class Config:
extra = Extra.ignore
Expand Down
12 changes: 11 additions & 1 deletion openapi_schema_pydantic/v3/v3_1_0/parameter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Any, Dict, Optional, Union
import enum

from pydantic import BaseModel, Field, Extra

Expand All @@ -8,6 +9,15 @@
from .schema import Schema


class ParameterLocation(str, enum.Enum):
"""The location of a given parameter."""

QUERY = "query"
HEADER = "header"
PATH = "path"
COOKIE = "cookie"


class Parameter(BaseModel):
"""
Describes a single operation parameter.
Expand All @@ -30,7 +40,7 @@ class Parameter(BaseModel):
- For all other cases, the `name` corresponds to the parameter name used by the [`in`](#parameterIn) property.
"""

param_in: str = Field(alias="in")
param_in: ParameterLocation = Field(alias="in")
"""
**REQUIRED**. The location of the parameter. Possible values are `"query"`, `"header"`, `"path"` or `"cookie"`.
"""
Expand Down
14 changes: 12 additions & 2 deletions tests/test_alias.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
from openapi_schema_pydantic import Header, MediaType, Parameter, PathItem, Reference, Schema, SecurityScheme
from openapi_schema_pydantic import (
Header,
MediaType,
Parameter,
ParameterLocation,
PathItem,
Reference,
Schema,
SecurityScheme,
)


def test_header_alias():
header_1 = Header(param_in="header")
header_2 = Header.parse_obj({"param_in": "header"})
header_3 = Header.parse_obj({"in": "header"})
assert header_1 == header_2 == header_3
header_4 = Header.parse_obj({"in": ParameterLocation.HEADER})
assert header_1 == header_2 == header_3 == header_4


def test_media_type_alias():
Expand Down