Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
3439836
Adds generic type T
spacether May 10, 2023
fff6c42
Fixes broken python test
spacether May 17, 2023
9fbe9e3
Fixes for vscode basic type checking
spacether May 18, 2023
bd4b242
Adds new instacne casting
spacether May 18, 2023
dc45c67
Sets ValidationMetadata new type
spacether May 18, 2023
ffd1705
Makes ValidationMetadata a dataclass, fixes type issues in _process_s…
spacether May 18, 2023
1326316
Fixes XBase self type errors
spacether May 18, 2023
cbfb57d
Makes two methods static
spacether May 18, 2023
c1741b8
Fixes IntBase as_int type error
spacether May 18, 2023
3453624
Fixes type error in NumberBase
spacether May 18, 2023
cd04b99
Adds needed typing.cast calls in new methods and get_new_class fn
spacether May 18, 2023
32d3ba6
Fixes exponent type error
spacether May 18, 2023
2f3feb2
Fixes type errors in _get_new_instance_without_conversion
spacether May 18, 2023
c6c4737
Fixes typ error in FileIO new
spacether May 19, 2023
67ffaec
Fixes type error in BytesSchema
spacether May 19, 2023
a08e41d
Fixes another type error
spacether May 20, 2023
e1a051f
Adds type ignore for _GenericAlias check and origin access
spacether May 20, 2023
6116295
Removes _takes_ascii usage
spacether May 20, 2023
5bac6fd
Fixes septype error
spacether May 20, 2023
430d458
Adds __parse_isotime type fix
spacether May 20, 2023
c8caa79
Fixes more date/datetime parsing errors
spacether May 20, 2023
f5bf662
Adds missing return types
spacether May 21, 2023
1e3eda6
Changes UnsetAnyType back to AnyType
spacether May 21, 2023
cd35280
Fixes AnyType init signature
spacether May 21, 2023
ba3bafb
Writes new method for all composed or anytype classes
spacether May 21, 2023
cde891d
Removes quote from refclass definitions
spacether May 21, 2023
9cd3f4f
Removes a type ignore comment
spacether May 22, 2023
48da937
Sample regen
spacether May 22, 2023
fa9712a
Adds response body generic type to ApiResponse classes
spacether May 22, 2023
1038f1f
Refactors response content template
spacether May 22, 2023
990b15c
Adds response content type hint
spacether May 22, 2023
45f6365
Fixes response header passing for deserialization
spacether May 22, 2023
c97a832
Moves content schema helper
spacether May 22, 2023
3b58d9a
Adds header and parameter content type type hint
spacether May 22, 2023
847d0ea
Adds missing imports
spacether May 22, 2023
7462bf0
Adds schema types for parameters and headers
spacether May 22, 2023
f1d4802
Samples updated
spacether May 22, 2023
c702027
Removes frozendict base class from ValidationMetadata
spacether May 22, 2023
7971cc4
Removes __origin__ usage
spacether May 22, 2023
87f20b0
Samples regenerated
spacether May 22, 2023
ef5fd91
Fixes python test
spacether May 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ class OpenApiResponse(JSONDetector, TypedDictInputVerifier, typing.Generic[T]):
__filename_content_disposition_pattern = re.compile('filename="(.+?)"')
response_cls: typing.Type[T]
content: typing.Optional[typing.Dict[str, MediaType]] = None
headers: typing.Optional[typing.Dict[str, HeaderParameterWithoutName]] = None
headers: typing.Optional[typing.Dict[str, typing.Type[HeaderParameterWithoutName]]] = None

@staticmethod
def __deserialize_json(response: urllib3.HTTPResponse) -> typing.Any:
Expand Down Expand Up @@ -1367,12 +1367,13 @@ class RequestBody(StyleFormSerializer, JSONDetector):
- encode_multipart and fields for multipart/form-data
"""
media_type = cls.content[content_type]
if isinstance(in_data, media_type.schema):
schema = schemas._get_class(media_type.schema)
if isinstance(in_data, schema):
cast_in_data = in_data
elif isinstance(in_data, (dict, frozendict.frozendict)) and in_data:
cast_in_data = media_type.schema(**in_data)
cast_in_data = schema(**in_data)
else:
cast_in_data = media_type.schema(in_data)
cast_in_data = schema(in_data)
# TODO check for and use encoding if it exists
# and content_type is multipart or application/x-www-form-urlencoded
if cls._content_type_is_json(content_type):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{{#if refInfo.refClass}}
{{#with getDeepestRef}}
{{#if types}}
{{#eq types.size 1}}
{{#if paramName}}{{paramName}}: {{#eq paramName "schema"}}typing_extensions.TypeAlias = {{/eq}}{{/if}}{{#if modulePrefix}}{{modulePrefix}}_{{/if}}{{../jsonPathPiece.snakeCase}}.{{../jsonPathPiece.camelCase}}[{{> components/schemas/_helper_schema_python_base_types }}]{{#unless paramName}},{{/unless}}
{{else}}
{{#if paramName}}{{paramName}}: {{#eq paramName "schema"}}typing_extensions.TypeAlias = {{/eq}}{{/if}}{{#if modulePrefix}}{{modulePrefix}}_{{/if}}{{../jsonPathPiece.snakeCase}}.{{../jsonPathPiece.camelCase}}[typing.Union[
{{> components/schemas/_helper_schema_python_base_types_newline }}
]]{{#unless paramName}},{{/unless}}
{{/eq}}
{{else}}
{{#if paramName}}{{paramName}}: {{#eq paramName "schema"}}typing_extensions.TypeAlias = {{/eq}}{{/if}}{{#if modulePrefix}}{{modulePrefix}}_{{/if}}{{../jsonPathPiece.snakeCase}}.{{../jsonPathPiece.camelCase}}[typing.Union[
{{> components/schemas/_helper_schema_python_base_types_newline }}
]]{{#unless paramName}},{{/unless}}
{{/if}}
{{/with}}
{{else}}
{{#if types}}
{{#eq types.size 1}}
{{#if paramName}}{{paramName}}: {{#eq paramName "schema"}}typing_extensions.TypeAlias = {{/eq}}{{/if}}{{#if modulePrefix}}{{modulePrefix}}_{{/if}}{{jsonPathPiece.snakeCase}}.{{jsonPathPiece.camelCase}}[{{> components/schemas/_helper_schema_python_base_types }}]{{#unless paramName}},{{/unless}}
{{else}}
{{#if includeBody}}{{paramName}}: {{#eq paramName "schema"}}typing_extensions.TypeAlias = {{/eq}}{{/if}}{{#if modulePrefix}}{{modulePrefix}}_{{/if}}{{jsonPathPiece.snakeCase}}.{{jsonPathPiece.camelCase}}[typing.Union[
{{> components/schemas/_helper_schema_python_base_types_newline }}
]]{{#unless paramName}},{{/unless}}
{{/eq}}
{{else}}
{{#if paramName}}{{paramName}}: {{#eq paramName "schema"}}typing_extensions.TypeAlias = {{/eq}}{{/if}}{{#if modulePrefix}}{{modulePrefix}}_{{/if}}{{jsonPathPiece.snakeCase}}.{{jsonPathPiece.camelCase}}[typing.Union[
{{> components/schemas/_helper_schema_python_base_types_newline }}
]]{{#unless paramName}},{{/unless}}
{{/if}}
{{/if}}
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,31 @@ class {{jsonPathPiece.camelCase}}(api_client.{{#if noName}}Header{{/if}}{{#eq in
{{/if}}
{{#if schema}}
{{#with schema}}
schema = {{jsonPathPiece.snakeCase}}.{{jsonPathPiece.camelCase}}
{{> components/_helper_content_schema_type paramName="schema" modulePrefix=null }}
{{/with}}
{{/if}}
{{#if content}}
{{#each content}}


class __{{@key.camelCase}}MediaType(api_client.MediaType):
class {{@key.camelCase}}MediaType(api_client.MediaType):
{{#with this}}
{{#with schema}}
schema: typing.Type[{{../@key.snakeCase}}_{{jsonPathPiece.snakeCase}}.{{jsonPathPiece.camelCase}}] = {{../@key.snakeCase}}_{{jsonPathPiece.snakeCase}}.{{jsonPathPiece.camelCase}}
{{> components/_helper_content_schema_type paramName="schema" modulePrefix=../@key.snakeCase }}
{{/with}}
{{/with}}
{{/each}}
__Content = typing_extensions.TypedDict(
'__Content',
Content = typing_extensions.TypedDict(
'Content',
{
{{#each content}}
'{{{@key.original}}}': typing.Type[__{{@key.camelCase}}MediaType],
'{{{@key.original}}}': typing.Type[{{@key.camelCase}}MediaType],
{{/each}}
}
)
content: __Content = {
content: Content = {
{{#each content}}
'{{{@key.original}}}': __{{@key.camelCase}}MediaType,
'{{{@key.original}}}': {{@key.camelCase}}MediaType,
{{/each}}
}
{{/if}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,24 @@ class {{jsonPathPiece.camelCase}}(api_client.RequestBody):
{{#each content}}


class __{{@key.camelCase}}MediaType(api_client.MediaType):
class {{@key.camelCase}}MediaType(api_client.MediaType):
{{#with this}}
{{#with schema}}
schema: typing.Type[{{../@key.snakeCase}}_{{jsonPathPiece.snakeCase}}.{{jsonPathPiece.camelCase}}] = {{../@key.snakeCase}}_{{jsonPathPiece.snakeCase}}.{{jsonPathPiece.camelCase}}
{{/with}}
{{/with}}
{{/each}}
__Content = typing_extensions.TypedDict(
'__Content',
Content = typing_extensions.TypedDict(
'Content',
{
{{#each content}}
'{{{@key.original}}}': typing.Type[__{{@key.camelCase}}MediaType],
'{{{@key.original}}}': typing.Type[{{@key.camelCase}}MediaType],
{{/each}}
}
)
content: __Content = {
content: Content = {
{{#each content}}
'{{{@key.original}}}': __{{@key.camelCase}}MediaType,
'{{{@key.original}}}': {{@key.camelCase}}MediaType,
{{/each}}
}
{{#if required}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class {{xParamsName}}:
pass


parameters = [
parameters: typing.Dict[str, typing.Type[api_client.HeaderParameterWithoutName]] = {
{{#each xParams}}
{{jsonPathPiece.snakeCase}}.{{jsonPathPiece.camelCase}},
'{{@key}}': {{jsonPathPiece.snakeCase}}.{{jsonPathPiece.camelCase}},
{{/each}}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,23 @@ class Api{{jsonPathPiece.camelCase}}(api_client.ApiResponse):
{{#each content}}
{{#if this.schema}}
{{#with this.schema}}
{{../@key.snakeCase}}_{{jsonPathPiece.snakeCase}}.{{jsonPathPiece.camelCase}},
{{> components/_helper_content_schema_type paramName=null modulePrefix=../@key.snakeCase }}
{{/with}}
{{else}}
schemas.Unset,
{{/if}}
{{/each}}
]
{{else}}
body: {{#each content}}{{#if this.schema}}{{#with this.schema}}{{../@key.snakeCase}}_{{jsonPathPiece.snakeCase}}.{{jsonPathPiece.camelCase}}{{/with}}{{else}}schemas.Unset{{/if}}{{/each}}
{{#each content}}
{{#if this.schema}}
{{#with this.schema}}
{{> components/_helper_content_schema_type paramName="body" modulePrefix=../@key.snakeCase }}
{{/with}}
{{else}}
body: schemas.Unset
{{/if}}
{{/each}}
{{/gt}}
{{else}}
body: schemas.Unset = schemas.unset
Expand All @@ -66,15 +74,23 @@ class Api{{jsonPathPiece.camelCase}}(api_client.ApiResponse):
{{#each content}}
{{#if this.schema}}
{{#with this.schema}}
{{../@key.snakeCase}}_{{jsonPathPiece.snakeCase}}.{{jsonPathPiece.camelCase}},
{{/with}}
{{else}}
{{> components/_helper_content_schema_type paramName=null modulePrefix=../@key.snakeCase }}
{{/with}}
{{else}}
schemas.Unset,
{{/if}}
{{/each}}
]
{{else}}
body: {{#each content}}{{#if this.schema}}{{#with this.schema}}{{../@key.snakeCase}}_{{jsonPathPiece.snakeCase}}.{{jsonPathPiece.camelCase}}{{/with}}{{else}}schemas.Unset{{/if}}{{/each}}
{{#each content}}
{{#if this.schema}}
{{#with this.schema}}
{{> components/_helper_content_schema_type paramName="body" modulePrefix=../@key.snakeCase }}
{{/with}}
{{else}}
body: schemas.Unset
{{/if}}
{{/each}}
{{/gt}}
{{else}}
body: schemas.Unset = schemas.unset
Expand All @@ -96,27 +112,27 @@ class {{jsonPathPiece.camelCase}}(api_client.OpenApiResponse[Api{{jsonPathPiece.
{{#each content}}


class __{{@key.camelCase}}MediaType(api_client.MediaType):
class {{@key.camelCase}}MediaType(api_client.MediaType):
{{#with this}}
{{#with schema}}
schema: typing.Type[{{../@key.snakeCase}}_{{jsonPathPiece.snakeCase}}.{{jsonPathPiece.camelCase}}] = {{../@key.snakeCase}}_{{jsonPathPiece.snakeCase}}.{{jsonPathPiece.camelCase}}
{{> components/_helper_content_schema_type paramName="schema" modulePrefix=../@key.snakeCase }}
{{else}}
pass
{{/with}}
{{/with}}
{{/each}}
{{#if content}}
__Content = typing_extensions.TypedDict(
'__Content',
Content = typing_extensions.TypedDict(
'Content',
{
{{#each content}}
'{{{@key.original}}}': typing.Type[__{{@key.camelCase}}MediaType],
'{{{@key.original}}}': typing.Type[{{@key.camelCase}}MediaType],
{{/each}}
}
)
content: __Content = {
content: Content = {
{{#each content}}
'{{{@key.original}}}': __{{@key.camelCase}}MediaType,
'{{{@key.original}}}': {{@key.camelCase}}MediaType,
{{/each}}
}
{{/if}}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{#if types}}
{{#eq types.size 1}}
def __getitem__(self, name: {{#if literal}}typing_extensions.Literal["{{{key}}}"]{{else}}{{key}}{{/if}}) -> Schema_{{propertyClass}}.{{jsonPathPiece.camelCase}}[{{> components/schemas/_helper_schema_python_base_types }}]:{{#if overload}} ...{{/if}}
{{else}}
def __getitem__(self, name: {{#if literal}}typing_extensions.Literal["{{{key}}}"]{{else}}{{key}}{{/if}}) -> Schema_{{propertyClass}}.{{jsonPathPiece.camelCase}}[typing.Union[
{{> components/schemas/_helper_schema_python_base_types_newline }}
]]:{{#if overload}} ...{{/if}}
{{/eq}}
{{else}}
def __getitem__(self, name: {{#if literal}}typing_extensions.Literal["{{{key}}}"]{{else}}{{key}}{{/if}}) -> Schema_{{propertyClass}}.{{jsonPathPiece.camelCase}}[typing.Union[
{{> components/schemas/_helper_schema_python_base_types_newline }}
]]:{{#if overload}} ...{{/if}}
{{/if}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{#with getDeepestRef}}
{{#if types}}
{{#eq types.size 1}}
def __getitem__(self, name: {{#if literal}}typing_extensions.Literal["{{{key}}}"]{{else}}{{key}}{{/if}}) -> {{#if ../refInfo.refModule}}{{../refInfo.refModule}}.{{/if}}{{../refInfo.refClass}}[{{> components/schemas/_helper_schema_python_base_types }}]:{{#if overload}} ...{{/if}}
{{else}}
def __getitem__(self, name: {{#if literal}}typing_extensions.Literal["{{{key}}}"]{{else}}{{key}}{{/if}}) -> {{#if ../refInfo.refModule}}{{../refInfo.refModule}}.{{/if}}{{../refInfo.refClass}}[typing.Union[
{{> components/schemas/_helper_schema_python_base_types_newline }}
]]:{{#if overload}} ...{{/if}}
{{/eq}}
{{else}}
def __getitem__(self, name: {{#if literal}}typing_extensions.Literal["{{{key}}}"]{{else}}{{key}}{{/if}}) -> {{#if ../refInfo.refModule}}{{../refInfo.refModule}}.{{/if}}{{../refInfo.refClass}}[typing.Union[
{{> components/schemas/_helper_schema_python_base_types_newline }}
]]:{{#if overload}} ...{{/if}}
{{/if}}
{{/with}}
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,94 @@

@typing.overload
{{#if refInfo.refClass}}
def __getitem__(self, name: typing_extensions.Literal["{{{@key.original}}}"]) -> '{{> components/schemas/_helper_refclass_with_module }}': ...
{{> components/schemas/_helper_getitem_refclass literal=true key=@key.original overload=true }}
{{else}}
{{#if jsonPathPiece}}
{{#if schemaIsFromAdditionalProperties}}
def __getitem__(self, name: typing_extensions.Literal["{{{@key.original}}}"]) -> Schema_.{{jsonPathPiece.camelCase}}: ...
{{> components/schemas/_helper_getitem_property propertyClass="" literal=true key=@key.original overload=true }}
{{else}}
def __getitem__(self, name: typing_extensions.Literal["{{{@key.original}}}"]) -> Schema_.Properties.{{jsonPathPiece.camelCase}}: ...
{{> components/schemas/_helper_getitem_property propertyClass=".Properties" literal=true key=@key.original overload=true }}
{{/if}}
{{else}}
def __getitem__(self, name: typing_extensions.Literal["{{{@key.original}}}"]) -> schemas.AnyTypeSchema: ...
{{! for when additionalProperties is unset, use schemas.AnyTypeSchema because val is not always schemas.UnsetAnyTypeSchema }}
def __getitem__(self, name: typing_extensions.Literal["{{{@key.original}}}"]) -> schemas.AnyTypeSchema[typing.Union[
{{> components/schemas/_helper_schema_python_base_types_newline }}
]]: ...
{{/if}}
{{/if}}
{{/with}}
{{/each}}
{{/if}}
{{#if optionalProperties}}
{{#each optionalProperties}}
{{#each optionalProperties}}

@typing.overload
{{#if refInfo.refClass}}
def __getitem__(self, name: typing_extensions.Literal["{{{@key.original}}}"]) -> '{{> components/schemas/_helper_refclass_with_module }}': ...
{{else}}
def __getitem__(self, name: typing_extensions.Literal["{{{@key.original}}}"]) -> Schema_.Properties.{{jsonPathPiece.camelCase}}: ...
{{/if}}
{{/each}}
{{#if refInfo.refClass}}
{{> components/schemas/_helper_getitem_refclass literal=true key=@key.original overload=true }}
{{else}}
{{> components/schemas/_helper_getitem_property propertyClass=".Properties" literal=true key=@key.original overload=true }}
{{/if}}
{{/each}}
{{/if}}
{{#or properties requiredProperties}}
{{#with additionalProperties}}
{{#unless isBooleanSchemaFalse}}

@typing.overload
def __getitem__(self, name: str) -> {{#if refInfo.refClass}}'{{> components/schemas/_helper_refclass_with_module }}'{{else}}Schema_.{{jsonPathPiece.camelCase}}{{/if}}: ...
{{#if refInfo.refClass}}
{{> components/schemas/_helper_getitem_refclass literal=false key="str" overload=true }}
{{else}}
{{> components/schemas/_helper_getitem_property propertyClass="" literal=false key="str" overload=true }}
{{/if}}
{{/unless}}
{{else}}
{{! for when additionalProperties is unset, use schemas.AnyTypeSchema because val is not always schemas.UnsetAnyTypeSchema }}

@typing.overload
def __getitem__(self, name: str) -> schemas.UnsetAnyTypeSchema: ...
def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[
frozendict.frozendict,
str,
decimal.Decimal,
schemas.BoolClass,
schemas.NoneClass,
tuple,
bytes,
schemas.FileIO
]]: ...
{{/with}}

{{> components/schemas/_helper_getitem methodName="__getitem__" }}
def __getitem__(
self,
name: typing.Union[
{{#each requiredProperties}}
{{#if this}}
typing_extensions.Literal["{{{@key.original}}}"],
{{/if}}
{{/each}}
{{#each optionalProperties}}
typing_extensions.Literal["{{{@key.original}}}"],
{{/each}}
{{#with additionalProperties}}
{{#unless isBooleanSchemaFalse}}
str
{{/unless}}
{{else}}
str
{{/with}}
]
):
# dict_instance[name] accessor
return super().__getitem__(name)
{{else}}
{{! no properties or requiredProperties }}
{{#with additionalProperties}}
{{#unless isBooleanSchemaFalse}}

def __getitem__(self, name: str) -> {{#if refInfo.refClass}}'{{> components/schemas/_helper_refclass_with_module }}'{{else}}Schema_.{{jsonPathPiece.camelCase}}{{/if}}:
{{#if refInfo.refClass}}
{{> components/schemas/_helper_getitem_refclass literal=false key="str" overload=false }}
{{else}}
{{> components/schemas/_helper_getitem_property propertyClass="" literal=false key="str" overload=false }}
{{/if}}
# dict_instance[name] accessor
return super().__getitem__(name)
{{/unless}}
Expand Down
Loading