Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Endpoint type hint for body uses content_type #25

Merged
Merged
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
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 @@ -197,6 +197,23 @@ public boolean getAllResponsesAreErrors() {
return responses.stream().allMatch(response -> response.is4xx || response.is5xx);
}

/**
* @return contentTypeToOperation
* returns a map where the key is the request body content type and the value is the current CodegenOperation
* this is needed by templates when a different signature is needed for each request body content type
*/
public Map<String, CodegenOperation> getContentTypeToOperation() {
LinkedHashMap<String, CodegenOperation> contentTypeToOperation = new LinkedHashMap<>();
if (bodyParam == null) {
return null;
}
LinkedHashMap<String, CodegenMediaType> content = bodyParam.getContent();
for (String contentType: content.keySet()) {
contentTypeToOperation.put(contentType, this);
}
return contentTypeToOperation;
}

/**
* Check if there's at least one vendor extension
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,21 +373,29 @@ _all_accept_content_types = (


class BaseApi(api_client.Api):
{{#if bodyParam}}
{{#each getContentTypeToOperation}}
{{> endpoint_args_baseapi_wrapper contentType=@key this=this}}

{{/each}}
{{> endpoint_args_baseapi_wrapper contentType="null" this=this}}

{{else}}
@typing.overload
def _{{operationId}}_oapg(
{{> endpoint_args isOverload=true skipDeserialization="False"}}
{{> endpoint_args isOverload=true skipDeserialization="False" contentType="null"}}
{{/if}}

@typing.overload
def _{{operationId}}_oapg(
{{> endpoint_args isOverload=true skipDeserialization="True"}}
{{> endpoint_args isOverload=true skipDeserialization="True" contentType="null"}}

@typing.overload
def _{{operationId}}_oapg(
{{> endpoint_args isOverload=true skipDeserialization="null"}}
{{> endpoint_args isOverload=true skipDeserialization="null" contentType="null"}}

def _{{operationId}}_oapg(
{{> endpoint_args isOverload=false skipDeserialization="null"}}
{{> endpoint_args isOverload=false skipDeserialization="null" contentType="null"}}
"""
{{#if summary}}
{{summary}}
Expand Down Expand Up @@ -533,20 +541,29 @@ class BaseApi(api_client.Api):
class {{operationIdCamelCase}}(BaseApi):
# this class is used by api classes that refer to endpoints with operationId fn names

{{#if bodyParam}}
{{#each getContentTypeToOperation}}
{{> endpoint_args_operationid_wrapper contentType=@key this=this}}

{{/each}}
{{> endpoint_args_operationid_wrapper contentType="null" this=this}}

{{else}}
@typing.overload
def {{operationId}}(
{{> endpoint_args isOverload=true skipDeserialization="False"}}
{{> endpoint_args isOverload=true skipDeserialization="False" contentType="null"}}
{{/if}}

@typing.overload
def {{operationId}}(
{{> endpoint_args isOverload=true skipDeserialization="True"}}
{{> endpoint_args isOverload=true skipDeserialization="True" contentType="null"}}

@typing.overload
def {{operationId}}(
{{> endpoint_args isOverload=true skipDeserialization="null"}}
{{> endpoint_args isOverload=true skipDeserialization="null" contentType="null"}}

def {{operationId}}(
{{> endpoint_args isOverload=false skipDeserialization="null"}}
{{> endpoint_args isOverload=false skipDeserialization="null" contentType="null"}}
return self._{{operationId}}_oapg(
{{> endpoint_args_passed }}
)
Expand All @@ -555,20 +572,29 @@ class {{operationIdCamelCase}}(BaseApi):
class ApiFor{{httpMethod}}(BaseApi):
# this class is used by api classes that refer to endpoints by path and http method names

{{#if bodyParam}}
{{#each getContentTypeToOperation}}
{{> endpoint_args_httpmethod_wrapper contentType=@key this=this}}

{{/each}}
{{> endpoint_args_httpmethod_wrapper contentType="null" this=this}}

{{else}}
@typing.overload
def {{httpMethod}}(
{{> endpoint_args isOverload=true skipDeserialization="False"}}
{{> endpoint_args isOverload=true skipDeserialization="False" contentType="null"}}
{{/if}}

@typing.overload
def {{httpMethod}}(
{{> endpoint_args isOverload=true skipDeserialization="True"}}
{{> endpoint_args isOverload=true skipDeserialization="True" contentType="null"}}

@typing.overload
def {{httpMethod}}(
{{> endpoint_args isOverload=true skipDeserialization="null"}}
{{> endpoint_args isOverload=true skipDeserialization="null" contentType="null"}}

def {{httpMethod}}(
{{> endpoint_args isOverload=false skipDeserialization="null"}}
{{> endpoint_args isOverload=false skipDeserialization="null" contentType="null"}}
return self._{{operationId}}_oapg(
{{> endpoint_args_passed }}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,75 @@
{{#if bodyParam}}
{{#if bodyParam.required}}
{{#with bodyParam}}
body: typing.Union[{{#each content}}{{#with this.schema}}{{baseName}},{{> model_templates/schema_python_types }}{{/with}}{{/each}}],
{{#eq ../contentType "null"}}
body: typing.Union[{{#each getContent}}{{#with this.schema}}{{baseName}},{{> model_templates/schema_python_types }}{{/with}}{{/each}}],
{{else}}
body: typing.Union[{{#each getContent}}{{#eq @key ../../contentType }}{{#with this.schema}}{{baseName}},{{> model_templates/schema_python_types }}{{/with}}{{/eq}}{{/each}}],
{{/eq}}
{{/with}}
{{#if isOverload}}
{{#eq skipDeserialization "True"}}
skip_deserialization: typing_extensions.Literal[True],
{{/eq}}
{{#neq contentType "null"}}
{{#with bodyParam}}
{{#each content}}
{{#eq @key ../../contentType}}
{{#if @first}}
content_type: typing_extensions.Literal["{{{@key}}}"] = ...,
{{else}}
content_type: typing_extensions.Literal["{{{@key}}}"],
{{/if}}
{{/eq}}
{{/each}}
{{/with}}
{{else}}
content_type: str = ...,
{{/neq}}
{{else}}
{{#with bodyParam}}
{{#each getContent}}
{{#if @first}}
content_type: str = '{{{@key}}}',
{{/if}}
{{/each}}
{{/with}}
{{/if}}
{{else}}
{{#if isOverload}}
{{#eq skipDeserialization "True"}}
skip_deserialization: typing_extensions.Literal[True],
{{/eq}}
{{#neq contentType "null"}}
{{#with bodyParam}}
{{#each getContent}}
{{#eq @key ../../contentType}}
{{#if @first}}
content_type: typing_extensions.Literal["{{{@key}}}"] = ...,
{{else}}
content_type: typing_extensions.Literal["{{{@key}}}"],
{{/if}}
{{/eq}}
{{/each}}
{{/with}}
{{else}}
content_type: str = ...,
{{/neq}}
{{else}}
{{#with bodyParam}}
{{#each getContent}}
{{#if @first}}
content_type: str = '{{{@key}}}',
{{/if}}
{{/each}}
{{/with}}
{{/if}}
{{#with bodyParam}}
body: typing.Union[{{#each content}}{{#with this.schema}}{{baseName}}, {{> model_templates/schema_python_types }}{{/with}}{{/each}}schemas.Unset] = schemas.unset,
{{#eq ../contentType "null"}}
body: typing.Union[{{#each getContent}}{{#with this.schema}}{{baseName}}, {{> model_templates/schema_python_types }}{{/with}}{{/each}}schemas.Unset] = schemas.unset,
{{else}}
body: typing.Union[{{#each getContent}}{{#eq @key ../../contentType }}{{#with this.schema}}{{baseName}}, {{> model_templates/schema_python_types }}{{/with}}{{/eq}}{{/each}}schemas.Unset] = schemas.unset,
{{/eq}}
{{/with}}
{{/if}}
{{/if}}
Expand All @@ -32,13 +86,6 @@
{{#if cookieParams}}
cookie_params: RequestCookieParams = frozendict.frozendict(),
{{/if}}
{{#with bodyParam}}
{{#each content}}
{{#if @first}}
content_type: str = '{{{@key}}}',
{{/if}}
{{/each}}
{{/with}}
{{#if produces}}
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
{{/if}}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@typing.overload
{{#with this}}
def _{{operationId}}_oapg(
{{> endpoint_args isOverload=true skipDeserialization="False" contentType=contentType}}
{{/with}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@typing.overload
{{#with this}}
def {{httpMethod}}(
{{> endpoint_args isOverload=true skipDeserialization="False" contentType=contentType}}
{{/with}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@typing.overload
{{#with this}}
def {{operationId}}(
{{> endpoint_args isOverload=true skipDeserialization="False" contentType=contentType}}
{{/with}}
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,37 @@ class ApiResponseFor200(api_client.ApiResponse):


class BaseApi(api_client.Api):
@typing.overload
def _post_additionalproperties_allows_a_schema_which_should_validate_request_body_oapg(
self,
body: typing.Union[SchemaForRequestBodyApplicationJson,],
content_type: typing_extensions.Literal["application/json"] = ...,
stream: bool = False,
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
skip_deserialization: typing_extensions.Literal[False] = ...,
) -> typing.Union[
ApiResponseFor200,
]: ...

@typing.overload
def _post_additionalproperties_allows_a_schema_which_should_validate_request_body_oapg(
self,
body: typing.Union[SchemaForRequestBodyApplicationJson,],
content_type: str = 'application/json',
content_type: str = ...,
stream: bool = False,
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
skip_deserialization: typing_extensions.Literal[False] = ...,
) -> typing.Union[
ApiResponseFor200,
]: ...


@typing.overload
def _post_additionalproperties_allows_a_schema_which_should_validate_request_body_oapg(
self,
body: typing.Union[SchemaForRequestBodyApplicationJson,],
skip_deserialization: typing_extensions.Literal[True],
content_type: str = 'application/json',
content_type: str = ...,
stream: bool = False,
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
) -> api_client.ApiResponseWithoutDeserialization: ...
Expand All @@ -85,7 +97,7 @@ def _post_additionalproperties_allows_a_schema_which_should_validate_request_bod
def _post_additionalproperties_allows_a_schema_which_should_validate_request_body_oapg(
self,
body: typing.Union[SchemaForRequestBodyApplicationJson,],
content_type: str = 'application/json',
content_type: str = ...,
stream: bool = False,
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
skip_deserialization: bool = ...,
Expand Down Expand Up @@ -155,20 +167,33 @@ class PostAdditionalpropertiesAllowsASchemaWhichShouldValidateRequestBody(BaseAp
def post_additionalproperties_allows_a_schema_which_should_validate_request_body(
self,
body: typing.Union[SchemaForRequestBodyApplicationJson,],
content_type: str = 'application/json',
content_type: typing_extensions.Literal["application/json"] = ...,
stream: bool = False,
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
skip_deserialization: typing_extensions.Literal[False] = ...,
) -> typing.Union[
ApiResponseFor200,
]: ...

@typing.overload
def post_additionalproperties_allows_a_schema_which_should_validate_request_body(
self,
body: typing.Union[SchemaForRequestBodyApplicationJson,],
content_type: str = ...,
stream: bool = False,
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
skip_deserialization: typing_extensions.Literal[False] = ...,
) -> typing.Union[
ApiResponseFor200,
]: ...


@typing.overload
def post_additionalproperties_allows_a_schema_which_should_validate_request_body(
self,
body: typing.Union[SchemaForRequestBodyApplicationJson,],
skip_deserialization: typing_extensions.Literal[True],
content_type: str = 'application/json',
content_type: str = ...,
stream: bool = False,
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
) -> api_client.ApiResponseWithoutDeserialization: ...
Expand All @@ -177,7 +202,7 @@ def post_additionalproperties_allows_a_schema_which_should_validate_request_body
def post_additionalproperties_allows_a_schema_which_should_validate_request_body(
self,
body: typing.Union[SchemaForRequestBodyApplicationJson,],
content_type: str = 'application/json',
content_type: str = ...,
stream: bool = False,
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
skip_deserialization: bool = ...,
Expand Down Expand Up @@ -210,20 +235,33 @@ class ApiForpost(BaseApi):
def post(
self,
body: typing.Union[SchemaForRequestBodyApplicationJson,],
content_type: str = 'application/json',
content_type: typing_extensions.Literal["application/json"] = ...,
stream: bool = False,
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
skip_deserialization: typing_extensions.Literal[False] = ...,
) -> typing.Union[
ApiResponseFor200,
]: ...

@typing.overload
def post(
self,
body: typing.Union[SchemaForRequestBodyApplicationJson,],
content_type: str = ...,
stream: bool = False,
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
skip_deserialization: typing_extensions.Literal[False] = ...,
) -> typing.Union[
ApiResponseFor200,
]: ...


@typing.overload
def post(
self,
body: typing.Union[SchemaForRequestBodyApplicationJson,],
skip_deserialization: typing_extensions.Literal[True],
content_type: str = 'application/json',
content_type: str = ...,
stream: bool = False,
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
) -> api_client.ApiResponseWithoutDeserialization: ...
Expand All @@ -232,7 +270,7 @@ def post(
def post(
self,
body: typing.Union[SchemaForRequestBodyApplicationJson,],
content_type: str = 'application/json',
content_type: str = ...,
stream: bool = False,
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
skip_deserialization: bool = ...,
Expand Down
Loading