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

[unused] adds request_body module #46

Merged
merged 3 commits into from
Oct 18, 2022
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 @@ -578,6 +578,17 @@ protected void generateEndpoints(OperationsMap objs) {
outputFilename = packageFilename(Arrays.asList("paths", pathModuleName, co.httpMethod, "__init__.py"));
pathsFiles.add(Arrays.asList(endpointMap, "endpoint.handlebars", outputFilename));

// paths.some_path.post.request_body.py
if (co.bodyParam != null) {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("requestBody", co.bodyParam);
// TODO consolidate imports into body param only
paramMap.put("imports", co.imports);
paramMap.put("packageName", packageName);
outputFilename = packageFilename(Arrays.asList("paths", pathModuleName, co.httpMethod, "request_body.py"));
pathsFiles.add(Arrays.asList(paramMap, "endpoint_request_body.handlebars", outputFilename));
}

for (CodegenResponse response: co.responses) {
// paths.some_path.post.response_for_200.py (file per response)
Map<String, Object> responseMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Method | HTTP request | Description
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
{{#with bodyParam}}
[{{baseName}}](#{{operationId}}.RequestBody) | typing.Union[{{#each content}}{{#unless @first}}, {{/unless}}{{#with this.schema}}[RequestBody.Schemas.{{#if nameInSnakeCase}}{{name}}{{else}}{{baseName}}{{/if}}](#{{../operationId}}.RequestBody.Schemas.{{#if nameInSnakeCase}}{{name}}{{else}}{{baseName}}{{/if}}){{/with}}{{/each}}{{#unless required}}, Unset]{{else}}]{{/unless}} | {{#if required}}required{{else}}optional, default is unset{{/if}} |
[{{baseName}}](#{{operationId}}.request_body) | typing.Union[{{#each content}}{{#unless @first}}, {{/unless}}{{#with this.schema}}[request_body.{{#if nameInSnakeCase}}{{name}}{{else}}{{baseName}}{{/if}}](#{{../operationId}}.request_body.{{#if nameInSnakeCase}}{{name}}{{else}}{{baseName}}{{/if}}){{/with}}{{/each}}{{#unless required}}, Unset]{{else}}]{{/unless}} | {{#if required}}required{{else}}optional, default is unset{{/if}} |
{{/with}}
{{#if queryParams}}
[query_params](#{{operationId}}.RequestQueryParameters) | [RequestQueryParameters.Params](#{{operationId}}.RequestQueryParameters.Params) | |
Expand Down Expand Up @@ -81,10 +81,10 @@ timeout | typing.Optional[typing.Union[int, typing.Tuple]] | default is None | t
skip_deserialization | bool | default is False | when True, headers and body will be unset and an instance of api_client.ApiResponseWithoutDeserialization will be returned
{{#with bodyParam}}

### <a id="{{operationId}}.RequestBody" >body</a>
### <a id="{{operationId}}.request_body" >body</a>
{{#each content}}
{{#with this.schema}}
{{> api_doc_schema_type_hint anchorPrefix=../operationId schemaNamePrefix1="RequestBody.Schemas." complexTypePrefix="../../models/" }}
{{> api_doc_schema_type_hint anchorPrefix=../operationId schemaNamePrefix1="request_body." complexTypePrefix="../../models/" }}
{{/with}}
{{/each}}
{{/with}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class Test{{operationIdSnakeCase}}(ApiTestMixin, unittest.TestCase):
{{/with}}
)
{{#if valid}}
body = {{httpMethod}}.RequestBody.Schemas.{{#if schema.nameInSnakeCase}}{{schema.name}}{{else}}{{schema.baseName}}{{/if}}.from_openapi_data_oapg(
body = {{httpMethod}}.request_body.{{#if schema.nameInSnakeCase}}{{schema.name}}{{else}}{{schema.baseName}}{{/if}}.from_openapi_data_oapg(
payload,
_configuration=self._configuration
)
Expand All @@ -123,7 +123,7 @@ class Test{{operationIdSnakeCase}}(ApiTestMixin, unittest.TestCase):
assert isinstance(api_response.body, schemas.Unset)
{{else}}
with self.assertRaises(({{packageName}}.ApiValueError, {{packageName}}.ApiTypeError)):
body = {{httpMethod}}.RequestBody.Schemas.{{#if schema.nameInSnakeCase}}{{schema.name}}{{else}}{{schema.baseName}}{{/if}}.from_openapi_data_oapg(
body = {{httpMethod}}.request_body.{{#if schema.nameInSnakeCase}}{{schema.name}}{{else}}{{schema.baseName}}{{/if}}.from_openapi_data_oapg(
payload,
_configuration=self._configuration
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ from .. import path
{{#each responses}}
from . import response_for_{{#if isDefault}}default{{else}}{{code}}{{/if}}
{{/each}}
{{#if bodyParam}}
from . import request_body
{{/if}}

{{#or queryParams headerParams pathParams cookieParams}}
{{#if queryParams}}
Expand All @@ -37,38 +40,6 @@ from . import response_for_{{#if isDefault}}default{{else}}{{code}}{{/if}}
{{> endpoint_parameter_schema_and_def xParams=cookieParams xParamsName="RequestCookieParameters" }}
{{/if}}
{{/or}}
{{#if bodyParam}}
{{#with bodyParam}}


class RequestBody:
class Schemas:
{{#each content}}
{{#with this}}
{{#with schema}}
{{> model_templates/schema }}
{{/with}}
{{/with}}
{{/each}}

parameter = api_client.RequestBody(
content={
{{#each content}}
'{{{@key}}}': api_client.MediaType(
{{#with this}}
{{#with schema}}
schema=Schemas.{{#if nameInSnakeCase}}{{name}}{{else}}{{baseName}}{{/if}}
{{/with}}
{{/with}}
),
{{/each}}
},
{{#if required}}
required=True,
{{/if}}
)
{{/with}}
{{/if}}
{{#unless isStub}}
{{#each authMethods}}
{{#if @first}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
{{#if bodyParam.required}}
{{#with bodyParam}}
{{#eq ../contentType "null"}}
body: typing.Union[{{#each getContent}}{{#with this.schema}}RequestBody.Schemas.{{#if nameInSnakeCase}}{{name}}{{else}}{{baseName}}{{/if}},{{> model_templates/schema_python_types }}{{/with}}{{/each}}],
body: typing.Union[{{#each getContent}}{{#with this.schema}}request_body.{{#if nameInSnakeCase}}{{name}}{{else}}{{baseName}}{{/if}},{{> model_templates/schema_python_types }}{{/with}}{{/each}}],
{{else}}
body: typing.Union[{{#each getContent}}{{#eq @key ../../contentType }}{{#with this.schema}}RequestBody.Schemas.{{#if nameInSnakeCase}}{{name}}{{else}}{{baseName}}{{/if}},{{> model_templates/schema_python_types }}{{/with}}{{/eq}}{{/each}}],
body: typing.Union[{{#each getContent}}{{#eq @key ../../contentType }}{{#with this.schema}}request_body.{{#if nameInSnakeCase}}{{name}}{{else}}{{baseName}}{{/if}},{{> model_templates/schema_python_types }}{{/with}}{{/eq}}{{/each}}],
{{/eq}}
{{/with}}
{{#if isOverload}}
Expand Down Expand Up @@ -67,9 +67,9 @@
{{/if}}
{{#with bodyParam}}
{{#eq ../contentType "null"}}
body: typing.Union[{{#each getContent}}{{#with this.schema}}RequestBody.Schemas.{{#if nameInSnakeCase}}{{name}}{{else}}{{baseName}}{{/if}}, {{> model_templates/schema_python_types }}{{/with}}{{/each}}schemas.Unset] = schemas.unset,
body: typing.Union[{{#each getContent}}{{#with this.schema}}request_body.{{#if nameInSnakeCase}}{{name}}{{else}}{{baseName}}{{/if}}, {{> model_templates/schema_python_types }}{{/with}}{{/each}}schemas.Unset] = schemas.unset,
{{else}}
body: typing.Union[{{#each getContent}}{{#eq @key ../../contentType }}{{#with this.schema}}RequestBody.Schemas.{{#if nameInSnakeCase}}{{name}}{{else}}{{baseName}}{{/if}}, {{> model_templates/schema_python_types }}{{/with}}{{/eq}}{{/each}}schemas.Unset] = schemas.unset,
body: typing.Union[{{#each getContent}}{{#eq @key ../../contentType }}{{#with this.schema}}request_body.{{#if nameInSnakeCase}}{{name}}{{else}}{{baseName}}{{/if}}, {{> model_templates/schema_python_types }}{{/with}}{{/eq}}{{/each}}schemas.Unset] = schemas.unset,
{{/eq}}
{{/with}}
{{/if}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
serialized_data = RequestBody.parameter.serialize(body, content_type)
serialized_data = request_body.parameter_oapg.serialize(body, content_type)
_headers.add('Content-Type', content_type)
if 'fields' in serialized_data:
_fields = serialized_data['fields']
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# coding: utf-8

{{>partial_header}}

from dataclasses import dataclass
import typing_extensions
import urllib3

from {{packageName}} import api_client, exceptions
{{> model_templates/imports_schema_types }}
{{> model_templates/imports_schemas }}
{{#with requestBody}}


{{#each content}}
{{#with this}}
{{#with schema}}
{{> model_templates/schema }}
{{/with}}
{{/with}}
{{/each}}

parameter_oapg = api_client.RequestBody(
content={
{{#each content}}
'{{{@key}}}': api_client.MediaType(
{{#with this}}
{{#with schema}}
schema={{#if nameInSnakeCase}}{{name}}{{else}}{{baseName}}{{/if}}
{{/with}}
{{/with}}
),
{{/each}}
},
{{#if required}}
required=True,
{{/if}}
)
{{/with}}
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ with unit_test_api.ApiClient(configuration) as api_client:

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
[body](#post_additionalproperties_allows_a_schema_which_should_validate_request_body.RequestBody) | typing.Union[[RequestBody.Schemas.application_json](#post_additionalproperties_allows_a_schema_which_should_validate_request_body.RequestBody.Schemas.application_json)] | required |
[body](#post_additionalproperties_allows_a_schema_which_should_validate_request_body.request_body) | typing.Union[[request_body.application_json](#post_additionalproperties_allows_a_schema_which_should_validate_request_body.request_body.application_json)] | required |
content_type | str | optional, default is 'application/json' | Selects the schema and serialization of the request body
stream | bool | default is False | if True then the response.content will be streamed and loaded from a file like object. When downloading a file, set this to True to force the code to deserialize the content to a FileSchema file
timeout | typing.Optional[typing.Union[int, typing.Tuple]] | default is None | the timeout used by the rest client
skip_deserialization | bool | default is False | when True, headers and body will be unset and an instance of api_client.ApiResponseWithoutDeserialization will be returned

### <a id="post_additionalproperties_allows_a_schema_which_should_validate_request_body.RequestBody" >body</a>
### <a id="post_additionalproperties_allows_a_schema_which_should_validate_request_body.request_body" >body</a>

# <a id="post_additionalproperties_allows_a_schema_which_should_validate_request_body.RequestBody.Schemas.application_json" >RequestBody.Schemas.application_json</a>
# <a id="post_additionalproperties_allows_a_schema_which_should_validate_request_body.request_body.application_json" >request_body.application_json</a>
Type | Description | Notes
------------- | ------------- | -------------
[**AdditionalpropertiesAllowsASchemaWhichShouldValidate**](../../models/AdditionalpropertiesAllowsASchemaWhichShouldValidate.md) | |
Expand Down Expand Up @@ -178,15 +178,15 @@ with unit_test_api.ApiClient(configuration) as api_client:

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
[body](#post_additionalproperties_are_allowed_by_default_request_body.RequestBody) | typing.Union[[RequestBody.Schemas.application_json](#post_additionalproperties_are_allowed_by_default_request_body.RequestBody.Schemas.application_json)] | required |
[body](#post_additionalproperties_are_allowed_by_default_request_body.request_body) | typing.Union[[request_body.application_json](#post_additionalproperties_are_allowed_by_default_request_body.request_body.application_json)] | required |
content_type | str | optional, default is 'application/json' | Selects the schema and serialization of the request body
stream | bool | default is False | if True then the response.content will be streamed and loaded from a file like object. When downloading a file, set this to True to force the code to deserialize the content to a FileSchema file
timeout | typing.Optional[typing.Union[int, typing.Tuple]] | default is None | the timeout used by the rest client
skip_deserialization | bool | default is False | when True, headers and body will be unset and an instance of api_client.ApiResponseWithoutDeserialization will be returned

### <a id="post_additionalproperties_are_allowed_by_default_request_body.RequestBody" >body</a>
### <a id="post_additionalproperties_are_allowed_by_default_request_body.request_body" >body</a>

# <a id="post_additionalproperties_are_allowed_by_default_request_body.RequestBody.Schemas.application_json" >RequestBody.Schemas.application_json</a>
# <a id="post_additionalproperties_are_allowed_by_default_request_body.request_body.application_json" >request_body.application_json</a>
Type | Description | Notes
------------- | ------------- | -------------
[**AdditionalpropertiesAreAllowedByDefault**](../../models/AdditionalpropertiesAreAllowedByDefault.md) | |
Expand Down Expand Up @@ -306,15 +306,15 @@ with unit_test_api.ApiClient(configuration) as api_client:

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
[body](#post_additionalproperties_can_exist_by_itself_request_body.RequestBody) | typing.Union[[RequestBody.Schemas.application_json](#post_additionalproperties_can_exist_by_itself_request_body.RequestBody.Schemas.application_json)] | required |
[body](#post_additionalproperties_can_exist_by_itself_request_body.request_body) | typing.Union[[request_body.application_json](#post_additionalproperties_can_exist_by_itself_request_body.request_body.application_json)] | required |
content_type | str | optional, default is 'application/json' | Selects the schema and serialization of the request body
stream | bool | default is False | if True then the response.content will be streamed and loaded from a file like object. When downloading a file, set this to True to force the code to deserialize the content to a FileSchema file
timeout | typing.Optional[typing.Union[int, typing.Tuple]] | default is None | the timeout used by the rest client
skip_deserialization | bool | default is False | when True, headers and body will be unset and an instance of api_client.ApiResponseWithoutDeserialization will be returned

### <a id="post_additionalproperties_can_exist_by_itself_request_body.RequestBody" >body</a>
### <a id="post_additionalproperties_can_exist_by_itself_request_body.request_body" >body</a>

# <a id="post_additionalproperties_can_exist_by_itself_request_body.RequestBody.Schemas.application_json" >RequestBody.Schemas.application_json</a>
# <a id="post_additionalproperties_can_exist_by_itself_request_body.request_body.application_json" >request_body.application_json</a>
Type | Description | Notes
------------- | ------------- | -------------
[**AdditionalpropertiesCanExistByItself**](../../models/AdditionalpropertiesCanExistByItself.md) | |
Expand Down Expand Up @@ -432,15 +432,15 @@ with unit_test_api.ApiClient(configuration) as api_client:

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
[body](#post_additionalproperties_should_not_look_in_applicators_request_body.RequestBody) | typing.Union[[RequestBody.Schemas.application_json](#post_additionalproperties_should_not_look_in_applicators_request_body.RequestBody.Schemas.application_json)] | required |
[body](#post_additionalproperties_should_not_look_in_applicators_request_body.request_body) | typing.Union[[request_body.application_json](#post_additionalproperties_should_not_look_in_applicators_request_body.request_body.application_json)] | required |
content_type | str | optional, default is 'application/json' | Selects the schema and serialization of the request body
stream | bool | default is False | if True then the response.content will be streamed and loaded from a file like object. When downloading a file, set this to True to force the code to deserialize the content to a FileSchema file
timeout | typing.Optional[typing.Union[int, typing.Tuple]] | default is None | the timeout used by the rest client
skip_deserialization | bool | default is False | when True, headers and body will be unset and an instance of api_client.ApiResponseWithoutDeserialization will be returned

### <a id="post_additionalproperties_should_not_look_in_applicators_request_body.RequestBody" >body</a>
### <a id="post_additionalproperties_should_not_look_in_applicators_request_body.request_body" >body</a>

# <a id="post_additionalproperties_should_not_look_in_applicators_request_body.RequestBody.Schemas.application_json" >RequestBody.Schemas.application_json</a>
# <a id="post_additionalproperties_should_not_look_in_applicators_request_body.request_body.application_json" >request_body.application_json</a>
Type | Description | Notes
------------- | ------------- | -------------
[**AdditionalpropertiesShouldNotLookInApplicators**](../../models/AdditionalpropertiesShouldNotLookInApplicators.md) | |
Expand Down
Loading