From 7072009ab560e14ab782c13cc01052852d81b83a Mon Sep 17 00:00:00 2001 From: Victoria Casasampere Fernandez Date: Tue, 26 Nov 2024 14:36:11 +0100 Subject: [PATCH 01/12] [Rust-Axum] Support quotes in string literals (#20176) * Allow quotes in string literals * Update samples --- .../codegen/languages/RustAxumServerCodegen.java | 2 +- .../petstore/rust-axum/output/openapi-v3/src/models.rs | 2 +- .../src/models.rs | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustAxumServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustAxumServerCodegen.java index 4a35fc695dc41..059d6ac6fb543 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustAxumServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustAxumServerCodegen.java @@ -809,7 +809,7 @@ public String toDefaultValue(final Schema p) { } } else if (ModelUtils.isStringSchema(p)) { if (p.getDefault() != null) { - defaultValue = "\"" + p.getDefault() + "\".to_string()"; + defaultValue = "r#\"" + p.getDefault() + "\"#.to_string()"; } } diff --git a/samples/server/petstore/rust-axum/output/openapi-v3/src/models.rs b/samples/server/petstore/rust-axum/output/openapi-v3/src/models.rs index 5437c7abd43b9..b484a7a0ce3ba 100644 --- a/samples/server/petstore/rust-axum/output/openapi-v3/src/models.rs +++ b/samples/server/petstore/rust-axum/output/openapi-v3/src/models.rs @@ -1827,7 +1827,7 @@ impl NullableTest { NullableTest { nullable, nullable_with_null_default: None, - nullable_with_present_default: Some(Nullable::Present("default".to_string())), + nullable_with_present_default: Some(Nullable::Present(r#"default"#.to_string())), nullable_with_no_default: None, nullable_array: None, min_item_test: None, diff --git a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/models.rs b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/models.rs index 65d9e95ad9ecc..47e78e88d90c1 100644 --- a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/models.rs +++ b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/models.rs @@ -309,7 +309,7 @@ impl Animal { pub fn new(class_name: String) -> Animal { Animal { class_name, - color: Some("red".to_string()), + color: Some(r#"red"#.to_string()), } } } @@ -1460,7 +1460,7 @@ impl Cat { pub fn new(class_name: String) -> Cat { Cat { class_name, - color: Some("red".to_string()), + color: Some(r#"red"#.to_string()), declawed: None, } } @@ -2041,7 +2041,7 @@ impl Dog { pub fn new(class_name: String) -> Dog { Dog { class_name, - color: Some("red".to_string()), + color: Some(r#"red"#.to_string()), breed: None, } } @@ -5858,7 +5858,7 @@ impl TestEnumParametersRequest { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> TestEnumParametersRequest { TestEnumParametersRequest { - enum_form_string: Some("-efg".to_string()), + enum_form_string: Some(r#"-efg"#.to_string()), } } } From 7b35613cfc42dd1e473f0adc5962b5ad48db019c Mon Sep 17 00:00:00 2001 From: jops-wtakase <92840130+jops-wtakase@users.noreply.github.com> Date: Wed, 27 Nov 2024 00:53:12 +0900 Subject: [PATCH 02/12] [python] Encode list query params (#20148) * Bugfix: #17688: Encode list query params * Test: #17688: Update validation error message tests for Pydantic 2.10+ Pydantic 2.10+ introduced changes to validation error messages, requiring updates to the affected test cases. --- .../src/main/resources/python/api_client.mustache | 2 +- .../openapi_client/api_client.py | 2 +- samples/client/echo_api/python/openapi_client/api_client.py | 2 +- .../petstore/python-aiohttp/petstore_api/api_client.py | 2 +- .../client/petstore/python/petstore_api/api_client.py | 2 +- .../openapi3/client/petstore/python/tests/test_api_client.py | 5 +++++ .../client/petstore/python/tests/test_api_validation.py | 4 ++-- 7 files changed, 12 insertions(+), 7 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/python/api_client.mustache b/modules/openapi-generator/src/main/resources/python/api_client.mustache index 3580c8ff9c68a..26071c8b835d2 100644 --- a/modules/openapi-generator/src/main/resources/python/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/python/api_client.mustache @@ -525,7 +525,7 @@ class ApiClient: if k in collection_formats: collection_format = collection_formats[k] if collection_format == 'multi': - new_params.extend((k, str(value)) for value in v) + new_params.extend((k, quote(str(value))) for value in v) else: if collection_format == 'ssv': delimiter = ' ' diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api_client.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api_client.py index 60d053860e36e..033aa324e3264 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api_client.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api_client.py @@ -518,7 +518,7 @@ def parameters_to_url_query(self, params, collection_formats): if k in collection_formats: collection_format = collection_formats[k] if collection_format == 'multi': - new_params.extend((k, str(value)) for value in v) + new_params.extend((k, quote(str(value))) for value in v) else: if collection_format == 'ssv': delimiter = ' ' diff --git a/samples/client/echo_api/python/openapi_client/api_client.py b/samples/client/echo_api/python/openapi_client/api_client.py index 60d053860e36e..033aa324e3264 100644 --- a/samples/client/echo_api/python/openapi_client/api_client.py +++ b/samples/client/echo_api/python/openapi_client/api_client.py @@ -518,7 +518,7 @@ def parameters_to_url_query(self, params, collection_formats): if k in collection_formats: collection_format = collection_formats[k] if collection_format == 'multi': - new_params.extend((k, str(value)) for value in v) + new_params.extend((k, quote(str(value))) for value in v) else: if collection_format == 'ssv': delimiter = ' ' diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api_client.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api_client.py index 7fef2f7c0db75..defe61c039f54 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api_client.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api_client.py @@ -520,7 +520,7 @@ def parameters_to_url_query(self, params, collection_formats): if k in collection_formats: collection_format = collection_formats[k] if collection_format == 'multi': - new_params.extend((k, str(value)) for value in v) + new_params.extend((k, quote(str(value))) for value in v) else: if collection_format == 'ssv': delimiter = ' ' diff --git a/samples/openapi3/client/petstore/python/petstore_api/api_client.py b/samples/openapi3/client/petstore/python/petstore_api/api_client.py index ae27d95bd4f3a..dd4d22ec6afc6 100755 --- a/samples/openapi3/client/petstore/python/petstore_api/api_client.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api_client.py @@ -517,7 +517,7 @@ def parameters_to_url_query(self, params, collection_formats): if k in collection_formats: collection_format = collection_formats[k] if collection_format == 'multi': - new_params.extend((k, str(value)) for value in v) + new_params.extend((k, quote(str(value))) for value in v) else: if collection_format == 'ssv': delimiter = ' ' diff --git a/samples/openapi3/client/petstore/python/tests/test_api_client.py b/samples/openapi3/client/petstore/python/tests/test_api_client.py index 9567c5ca315d6..a84bf1b623009 100644 --- a/samples/openapi3/client/petstore/python/tests/test_api_client.py +++ b/samples/openapi3/client/petstore/python/tests/test_api_client.py @@ -294,3 +294,8 @@ def test_parameters_to_url_query_list_value(self): params = self.api_client.parameters_to_url_query(params=[('list', [1, 2, 3])], collection_formats={'list': 'multi'}) self.assertEqual(params, "list=1&list=2&list=3") + + def test_parameters_to_url_query_list_value_encoded(self): + params = self.api_client.parameters_to_url_query(params=[('list', [" !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", "2023-01-01T00:00:00+01:00"])], + collection_formats={'list': 'multi'}) + self.assertEqual(params, "list=%20%21%22%23%24%25%26%27%28%29%2A%2B%2C-./%3A%3B%3C%3D%3E%3F%40%5B%5C%5D%5E_%60%7B%7C%7D~&list=2023-01-01T00%3A00%3A00%2B01%3A00") diff --git a/samples/openapi3/client/petstore/python/tests/test_api_validation.py b/samples/openapi3/client/petstore/python/tests/test_api_validation.py index 679a3bb67b59b..da1634eecebc3 100644 --- a/samples/openapi3/client/petstore/python/tests/test_api_validation.py +++ b/samples/openapi3/client/petstore/python/tests/test_api_validation.py @@ -50,7 +50,7 @@ def test_required_param_validation(self): try: self.pet_api.get_pet_by_id() # type: ignore except ValidationError as e: - self.assertIn("1 validation error for get_pet_by_id", str(e)) + self.assertIn("1 validation error for PetApi.get_pet_by_id", str(e)) self.assertIn("Missing required argument", str(e)) def test_integer_validation(self): @@ -61,7 +61,7 @@ def test_integer_validation(self): # pet_id # Input should be a valid integer [type=int_type, input_value='123', input_type=str] # For further information visit https://errors.pydantic.dev/2.3/v/int_type - self.assertIn("1 validation error for get_pet_by_id", str(e)) + self.assertIn("1 validation error for PetApi.get_pet_by_id", str(e)) self.assertIn("Input should be a valid integer", str(e)) def test_string_enum_validation(self): From 705261978dab70980e2ab96b829de3dbdaa21d71 Mon Sep 17 00:00:00 2001 From: Qluxzz Date: Wed, 27 Nov 2024 08:44:21 +0100 Subject: [PATCH 03/12] [Elm] Fix not compiling all elm files in test suite (#20191) * Fix not trying to compile all elm files * Validate that changes to pipeline works --- .github/workflows/samples-elm.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/samples-elm.yaml b/.github/workflows/samples-elm.yaml index a9dad78925a64..b494ffaf4b09e 100644 --- a/.github/workflows/samples-elm.yaml +++ b/.github/workflows/samples-elm.yaml @@ -3,10 +3,12 @@ name: Samples Elm on: push: paths: + - .github/workflows/samples-elm.yaml - samples/client/petstore/elm/** - samples/openapi3/client/elm/** pull_request: paths: + - .github/workflows/samples-elm.yaml - samples/client/petstore/elm/** - samples/openapi3/client/elm/** jobs: @@ -32,4 +34,4 @@ jobs: # An .elm file couldn't be compiled # No .elm files were found # No elm.json file could be found in the root of the working directory - run: elm make $(find . -name *.elm) --output=/dev/null + run: elm make $(find . -name "*.elm") --output=/dev/null From 8a94fc667ec8e23fb322f6316b84aba25fad87a8 Mon Sep 17 00:00:00 2001 From: Per Hallgren Date: Wed, 27 Nov 2024 11:09:11 +0100 Subject: [PATCH 04/12] [BUG][GO] use value receiver for JSON marshal (#19962) * chore(go): add failing test for JSON marshalling Adds a small schema (FruitJuice) which contains a required gmFruit, which inherits using AnyOf. This fails to correctly marshal as JSON. * fix(go): use non-pointer receiver for JSON marshal In the case of a required anyOf property, JSON marshalling would has been incorrect. Required properties are not nullable, and thus always use value receivers. For the single case of anyOf models, a pointer receiver was used for MarshalJSON. All other instances of json marshalling use value receivers. This change is simply to use a value receiver instead of a pointer receiver in the template for `MarshalJSON` on anyOf models. --------- Co-authored-by: Per Hallgren --- .../main/resources/go/model_anyof.mustache | 2 +- ...odels-for-testing-with-http-signature.yaml | 28 +-- .../go/oneof-anyof-required/model_object2.go | 2 +- .../go/go-petstore/.openapi-generator/FILES | 2 + .../client/petstore/go/go-petstore/README.md | 1 + .../petstore/go/go-petstore/api/openapi.yaml | 26 ++- .../petstore/go/go-petstore/docs/FakeAPI.md | 2 +- .../petstore/go/go-petstore/docs/FilterAny.md | 35 +++- .../go/go-petstore/docs/FilterTypeRange.md | 23 +-- .../go/go-petstore/docs/FilterTypeRegex.md | 23 +-- .../go/go-petstore/docs/FruitJuice.md | 51 +++++ .../model_any_of_primitive_type.go | 2 +- .../go/go-petstore/model_filter_any.go | 2 +- .../go/go-petstore/model_filter_type_range.go | 70 +------ .../go/go-petstore/model_filter_type_regex.go | 70 +------ .../go/go-petstore/model_fruit_juice.go | 186 ++++++++++++++++++ .../petstore/go/go-petstore/model_gm_fruit.go | 2 +- samples/openapi3/client/petstore/go/go.mod | 6 +- samples/openapi3/client/petstore/go/go.sum | 11 ++ .../openapi3/client/petstore/go/model_test.go | 18 ++ 20 files changed, 348 insertions(+), 214 deletions(-) create mode 100644 samples/openapi3/client/petstore/go/go-petstore/docs/FruitJuice.md create mode 100644 samples/openapi3/client/petstore/go/go-petstore/model_fruit_juice.go diff --git a/modules/openapi-generator/src/main/resources/go/model_anyof.mustache b/modules/openapi-generator/src/main/resources/go/model_anyof.mustache index 5e2d57aad107a..21e33137403a0 100644 --- a/modules/openapi-generator/src/main/resources/go/model_anyof.mustache +++ b/modules/openapi-generator/src/main/resources/go/model_anyof.mustache @@ -68,7 +68,7 @@ func (dst *{{classname}}) UnmarshalJSON(data []byte) error { } // Marshal data from the first non-nil pointers in the struct to JSON -func (src *{{classname}}) MarshalJSON() ([]byte, error) { +func (src {{classname}}) MarshalJSON() ([]byte, error) { {{#anyOf}} if src.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} != nil { return json.Marshal(&src.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}) diff --git a/modules/openapi-generator/src/test/resources/3_0/go/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml b/modules/openapi-generator/src/test/resources/3_0/go/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml index f02e8d9e6c2b0..faed76ea4927c 100644 --- a/modules/openapi-generator/src/test/resources/3_0/go/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/go/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml @@ -1394,11 +1394,6 @@ components: FilterTypeRegex: type: object properties: - type: - enum: - - set - - range - type: string regex: type: string required: @@ -1406,11 +1401,6 @@ components: FilterTypeRange: type: object properties: - type: - enum: - - set - - range - type: string data: type: array items: @@ -1425,7 +1415,16 @@ components: mapping: set: '#/components/schemas/FilterTypeRegex' range: '#/components/schemas/FilterTypeRange' - propertyName: type + propertyName: type + properties: + type: + enum: + - set + - range + type: string + date: + type: string + format: date-time MapWithDateTime: type: object additionalProperties: @@ -2119,6 +2118,13 @@ components: type: string required: - className + fruitJuice: + type: object + required: + - fruit + properties: + fruit: + $ref: '#/components/schemas/gmFruit' gmFruit: properties: color: diff --git a/samples/client/others/go/oneof-anyof-required/model_object2.go b/samples/client/others/go/oneof-anyof-required/model_object2.go index ee4ff5ec523e9..462b5429f9003 100644 --- a/samples/client/others/go/oneof-anyof-required/model_object2.go +++ b/samples/client/others/go/oneof-anyof-required/model_object2.go @@ -55,7 +55,7 @@ func (dst *Object2) UnmarshalJSON(data []byte) error { } // Marshal data from the first non-nil pointers in the struct to JSON -func (src *Object2) MarshalJSON() ([]byte, error) { +func (src Object2) MarshalJSON() ([]byte, error) { if src.NestedObject1 != nil { return json.Marshal(&src.NestedObject1) } diff --git a/samples/openapi3/client/petstore/go/go-petstore/.openapi-generator/FILES b/samples/openapi3/client/petstore/go/go-petstore/.openapi-generator/FILES index 78d7498ae37be..e6cac5bc3f305 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/go/go-petstore/.openapi-generator/FILES @@ -47,6 +47,7 @@ docs/Foo.md docs/FooGetDefaultResponse.md docs/FormatTest.md docs/Fruit.md +docs/FruitJuice.md docs/FruitReq.md docs/GmFruit.md docs/HasOnlyReadOnly.md @@ -126,6 +127,7 @@ model_filter_type_regex.go model_foo.go model_format_test_.go model_fruit.go +model_fruit_juice.go model_fruit_req.go model_gm_fruit.go model_has_only_read_only.go diff --git a/samples/openapi3/client/petstore/go/go-petstore/README.md b/samples/openapi3/client/petstore/go/go-petstore/README.md index b437572d32cf2..c346c1155cffb 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/README.md +++ b/samples/openapi3/client/petstore/go/go-petstore/README.md @@ -161,6 +161,7 @@ Class | Method | HTTP request | Description - [FooGetDefaultResponse](docs/FooGetDefaultResponse.md) - [FormatTest](docs/FormatTest.md) - [Fruit](docs/Fruit.md) + - [FruitJuice](docs/FruitJuice.md) - [FruitReq](docs/FruitReq.md) - [GmFruit](docs/GmFruit.md) - [HasOnlyReadOnly](docs/HasOnlyReadOnly.md) diff --git a/samples/openapi3/client/petstore/go/go-petstore/api/openapi.yaml b/samples/openapi3/client/petstore/go/go-petstore/api/openapi.yaml index 3a8b28a21ae9f..580a6c45a2388 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/api/openapi.yaml +++ b/samples/openapi3/client/petstore/go/go-petstore/api/openapi.yaml @@ -1296,11 +1296,6 @@ components: schemas: FilterTypeRegex: properties: - type: - enum: - - set - - range - type: string regex: type: string required: @@ -1308,11 +1303,6 @@ components: type: object FilterTypeRange: properties: - type: - enum: - - set - - range - type: string data: items: type: string @@ -1329,6 +1319,15 @@ components: set: '#/components/schemas/FilterTypeRegex' range: '#/components/schemas/FilterTypeRange' propertyName: type + properties: + type: + enum: + - set + - range + type: string + date: + format: date-time + type: string MapWithDateTime: additionalProperties: items: @@ -2101,6 +2100,13 @@ components: required: - className type: object + fruitJuice: + properties: + fruit: + $ref: '#/components/schemas/gmFruit' + required: + - fruit + type: object gmFruit: anyOf: - $ref: '#/components/schemas/apple' diff --git a/samples/openapi3/client/petstore/go/go-petstore/docs/FakeAPI.md b/samples/openapi3/client/petstore/go/go-petstore/docs/FakeAPI.md index 5a6d632f7c40f..f533a395e2fac 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/docs/FakeAPI.md +++ b/samples/openapi3/client/petstore/go/go-petstore/docs/FakeAPI.md @@ -1197,7 +1197,7 @@ import ( ) func main() { - filter := *openapiclient.NewFilterAny("Type_example") // FilterAny | (optional) + filter := *openapiclient.NewFilterAny() // FilterAny | (optional) configuration := openapiclient.NewConfiguration() apiClient := openapiclient.NewAPIClient(configuration) diff --git a/samples/openapi3/client/petstore/go/go-petstore/docs/FilterAny.md b/samples/openapi3/client/petstore/go/go-petstore/docs/FilterAny.md index beada8f60c064..350b5e2612172 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/docs/FilterAny.md +++ b/samples/openapi3/client/petstore/go/go-petstore/docs/FilterAny.md @@ -4,7 +4,8 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**Type** | **string** | | +**Type** | Pointer to **string** | | [optional] +**Date** | Pointer to **time.Time** | | [optional] **Regex** | Pointer to **string** | | [optional] **Data** | Pointer to **[]string** | | [optional] @@ -12,7 +13,7 @@ Name | Type | Description | Notes ### NewFilterAny -`func NewFilterAny(type_ string, ) *FilterAny` +`func NewFilterAny() *FilterAny` NewFilterAny instantiates a new FilterAny object This constructor will assign default values to properties that have it defined, @@ -46,6 +47,36 @@ and a boolean to check if the value has been set. SetType sets Type field to given value. +### HasType + +`func (o *FilterAny) HasType() bool` + +HasType returns a boolean if a field has been set. + +### GetDate + +`func (o *FilterAny) GetDate() time.Time` + +GetDate returns the Date field if non-nil, zero value otherwise. + +### GetDateOk + +`func (o *FilterAny) GetDateOk() (*time.Time, bool)` + +GetDateOk returns a tuple with the Date field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetDate + +`func (o *FilterAny) SetDate(v time.Time)` + +SetDate sets Date field to given value. + +### HasDate + +`func (o *FilterAny) HasDate() bool` + +HasDate returns a boolean if a field has been set. ### GetRegex diff --git a/samples/openapi3/client/petstore/go/go-petstore/docs/FilterTypeRange.md b/samples/openapi3/client/petstore/go/go-petstore/docs/FilterTypeRange.md index 436cb910496c5..41e657a60169a 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/docs/FilterTypeRange.md +++ b/samples/openapi3/client/petstore/go/go-petstore/docs/FilterTypeRange.md @@ -4,14 +4,13 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**Type** | **string** | | **Data** | Pointer to **[]string** | | [optional] ## Methods ### NewFilterTypeRange -`func NewFilterTypeRange(type_ string, ) *FilterTypeRange` +`func NewFilterTypeRange() *FilterTypeRange` NewFilterTypeRange instantiates a new FilterTypeRange object This constructor will assign default values to properties that have it defined, @@ -26,26 +25,6 @@ NewFilterTypeRangeWithDefaults instantiates a new FilterTypeRange object This constructor will only assign default values to properties that have it defined, but it doesn't guarantee that properties required by API are set -### GetType - -`func (o *FilterTypeRange) GetType() string` - -GetType returns the Type field if non-nil, zero value otherwise. - -### GetTypeOk - -`func (o *FilterTypeRange) GetTypeOk() (*string, bool)` - -GetTypeOk returns a tuple with the Type field if it's non-nil, zero value otherwise -and a boolean to check if the value has been set. - -### SetType - -`func (o *FilterTypeRange) SetType(v string)` - -SetType sets Type field to given value. - - ### GetData `func (o *FilterTypeRange) GetData() []string` diff --git a/samples/openapi3/client/petstore/go/go-petstore/docs/FilterTypeRegex.md b/samples/openapi3/client/petstore/go/go-petstore/docs/FilterTypeRegex.md index e11048f19aa93..96946b3f56d21 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/docs/FilterTypeRegex.md +++ b/samples/openapi3/client/petstore/go/go-petstore/docs/FilterTypeRegex.md @@ -4,14 +4,13 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**Type** | **string** | | **Regex** | Pointer to **string** | | [optional] ## Methods ### NewFilterTypeRegex -`func NewFilterTypeRegex(type_ string, ) *FilterTypeRegex` +`func NewFilterTypeRegex() *FilterTypeRegex` NewFilterTypeRegex instantiates a new FilterTypeRegex object This constructor will assign default values to properties that have it defined, @@ -26,26 +25,6 @@ NewFilterTypeRegexWithDefaults instantiates a new FilterTypeRegex object This constructor will only assign default values to properties that have it defined, but it doesn't guarantee that properties required by API are set -### GetType - -`func (o *FilterTypeRegex) GetType() string` - -GetType returns the Type field if non-nil, zero value otherwise. - -### GetTypeOk - -`func (o *FilterTypeRegex) GetTypeOk() (*string, bool)` - -GetTypeOk returns a tuple with the Type field if it's non-nil, zero value otherwise -and a boolean to check if the value has been set. - -### SetType - -`func (o *FilterTypeRegex) SetType(v string)` - -SetType sets Type field to given value. - - ### GetRegex `func (o *FilterTypeRegex) GetRegex() string` diff --git a/samples/openapi3/client/petstore/go/go-petstore/docs/FruitJuice.md b/samples/openapi3/client/petstore/go/go-petstore/docs/FruitJuice.md new file mode 100644 index 0000000000000..fe9d41d747053 --- /dev/null +++ b/samples/openapi3/client/petstore/go/go-petstore/docs/FruitJuice.md @@ -0,0 +1,51 @@ +# FruitJuice + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Fruit** | [**GmFruit**](GmFruit.md) | | + +## Methods + +### NewFruitJuice + +`func NewFruitJuice(fruit GmFruit, ) *FruitJuice` + +NewFruitJuice instantiates a new FruitJuice object +This constructor will assign default values to properties that have it defined, +and makes sure properties required by API are set, but the set of arguments +will change when the set of required properties is changed + +### NewFruitJuiceWithDefaults + +`func NewFruitJuiceWithDefaults() *FruitJuice` + +NewFruitJuiceWithDefaults instantiates a new FruitJuice object +This constructor will only assign default values to properties that have it defined, +but it doesn't guarantee that properties required by API are set + +### GetFruit + +`func (o *FruitJuice) GetFruit() GmFruit` + +GetFruit returns the Fruit field if non-nil, zero value otherwise. + +### GetFruitOk + +`func (o *FruitJuice) GetFruitOk() (*GmFruit, bool)` + +GetFruitOk returns a tuple with the Fruit field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetFruit + +`func (o *FruitJuice) SetFruit(v GmFruit)` + +SetFruit sets Fruit field to given value. + + + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_any_of_primitive_type.go b/samples/openapi3/client/petstore/go/go-petstore/model_any_of_primitive_type.go index c18a0c8a21538..81a52e465acf2 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_any_of_primitive_type.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_any_of_primitive_type.go @@ -69,7 +69,7 @@ func (dst *AnyOfPrimitiveType) UnmarshalJSON(data []byte) error { } // Marshal data from the first non-nil pointers in the struct to JSON -func (src *AnyOfPrimitiveType) MarshalJSON() ([]byte, error) { +func (src AnyOfPrimitiveType) MarshalJSON() ([]byte, error) { if src.OneOfPrimitiveTypeChild != nil { return json.Marshal(&src.OneOfPrimitiveTypeChild) } diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_filter_any.go b/samples/openapi3/client/petstore/go/go-petstore/model_filter_any.go index f2785ce45ee0d..8c1cb3803664e 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_filter_any.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_filter_any.go @@ -128,7 +128,7 @@ func (dst *FilterAny) UnmarshalJSON(data []byte) error { } // Marshal data from the first non-nil pointers in the struct to JSON -func (src *FilterAny) MarshalJSON() ([]byte, error) { +func (src FilterAny) MarshalJSON() ([]byte, error) { if src.FilterTypeRange != nil { return json.Marshal(&src.FilterTypeRange) } diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_filter_type_range.go b/samples/openapi3/client/petstore/go/go-petstore/model_filter_type_range.go index cfb9c006444cd..fb7eeebbcaaee 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_filter_type_range.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_filter_type_range.go @@ -12,7 +12,6 @@ package petstore import ( "encoding/json" - "fmt" ) // checks if the FilterTypeRange type satisfies the MappedNullable interface at compile time @@ -20,7 +19,6 @@ var _ MappedNullable = &FilterTypeRange{} // FilterTypeRange struct for FilterTypeRange type FilterTypeRange struct { - Type string `json:"type"` Data []string `json:"data,omitempty"` AdditionalProperties map[string]interface{} } @@ -31,9 +29,8 @@ type _FilterTypeRange FilterTypeRange // This constructor will assign default values to properties that have it defined, // and makes sure properties required by API are set, but the set of arguments // will change when the set of required properties is changed -func NewFilterTypeRange(type_ string) *FilterTypeRange { +func NewFilterTypeRange() *FilterTypeRange { this := FilterTypeRange{} - this.Type = type_ return &this } @@ -45,31 +42,6 @@ func NewFilterTypeRangeWithDefaults() *FilterTypeRange { return &this } -// GetType returns the Type field value -func (o *FilterTypeRange) GetType() string { - if o == nil { - var ret string - return ret - } - - return o.Type -} - -// GetTypeOk returns a tuple with the Type field value -// and a boolean to check if the value has been set. -func (o *FilterTypeRange) GetTypeOk() (*string, bool) { - if o == nil { - return nil, false - } - return &o.Type, true -} - -// SetType sets field value -func (o *FilterTypeRange) SetType(v string) { - o.Type = v -} - - // GetData returns the Data field value if set, zero value otherwise. func (o *FilterTypeRange) GetData() []string { if o == nil || IsNil(o.Data) { @@ -112,7 +84,6 @@ func (o FilterTypeRange) MarshalJSON() ([]byte, error) { func (o FilterTypeRange) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} - toSerialize["type"] = o.Type if !IsNil(o.Data) { toSerialize["data"] = o.Data } @@ -125,44 +96,6 @@ func (o FilterTypeRange) ToMap() (map[string]interface{}, error) { } func (o *FilterTypeRange) UnmarshalJSON(data []byte) (err error) { - // This validates that all required properties are included in the JSON object - // by unmarshalling the object into a generic map with string keys and checking - // that every required field exists as a key in the generic map. - requiredProperties := []string{ - "type", - } - - // defaultValueFuncMap captures the default values for required properties. - // These values are used when required properties are missing from the payload. - defaultValueFuncMap := map[string]func() interface{} { - } - var defaultValueApplied bool - allProperties := make(map[string]interface{}) - - err = json.Unmarshal(data, &allProperties) - - if err != nil { - return err; - } - - for _, requiredProperty := range(requiredProperties) { - if value, exists := allProperties[requiredProperty]; !exists || value == "" { - if _, ok := defaultValueFuncMap[requiredProperty]; ok { - allProperties[requiredProperty] = defaultValueFuncMap[requiredProperty]() - defaultValueApplied = true - } - } - if value, exists := allProperties[requiredProperty]; !exists || value == ""{ - return fmt.Errorf("no value given for required property %v", requiredProperty) - } - } - - if defaultValueApplied { - data, err = json.Marshal(allProperties) - if err != nil{ - return err - } - } varFilterTypeRange := _FilterTypeRange{} err = json.Unmarshal(data, &varFilterTypeRange) @@ -176,7 +109,6 @@ func (o *FilterTypeRange) UnmarshalJSON(data []byte) (err error) { additionalProperties := make(map[string]interface{}) if err = json.Unmarshal(data, &additionalProperties); err == nil { - delete(additionalProperties, "type") delete(additionalProperties, "data") o.AdditionalProperties = additionalProperties } diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_filter_type_regex.go b/samples/openapi3/client/petstore/go/go-petstore/model_filter_type_regex.go index 7ee6c5013cb2d..c38d1bfdd0de1 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_filter_type_regex.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_filter_type_regex.go @@ -12,7 +12,6 @@ package petstore import ( "encoding/json" - "fmt" ) // checks if the FilterTypeRegex type satisfies the MappedNullable interface at compile time @@ -20,7 +19,6 @@ var _ MappedNullable = &FilterTypeRegex{} // FilterTypeRegex struct for FilterTypeRegex type FilterTypeRegex struct { - Type string `json:"type"` Regex *string `json:"regex,omitempty"` AdditionalProperties map[string]interface{} } @@ -31,9 +29,8 @@ type _FilterTypeRegex FilterTypeRegex // This constructor will assign default values to properties that have it defined, // and makes sure properties required by API are set, but the set of arguments // will change when the set of required properties is changed -func NewFilterTypeRegex(type_ string) *FilterTypeRegex { +func NewFilterTypeRegex() *FilterTypeRegex { this := FilterTypeRegex{} - this.Type = type_ return &this } @@ -45,31 +42,6 @@ func NewFilterTypeRegexWithDefaults() *FilterTypeRegex { return &this } -// GetType returns the Type field value -func (o *FilterTypeRegex) GetType() string { - if o == nil { - var ret string - return ret - } - - return o.Type -} - -// GetTypeOk returns a tuple with the Type field value -// and a boolean to check if the value has been set. -func (o *FilterTypeRegex) GetTypeOk() (*string, bool) { - if o == nil { - return nil, false - } - return &o.Type, true -} - -// SetType sets field value -func (o *FilterTypeRegex) SetType(v string) { - o.Type = v -} - - // GetRegex returns the Regex field value if set, zero value otherwise. func (o *FilterTypeRegex) GetRegex() string { if o == nil || IsNil(o.Regex) { @@ -112,7 +84,6 @@ func (o FilterTypeRegex) MarshalJSON() ([]byte, error) { func (o FilterTypeRegex) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} - toSerialize["type"] = o.Type if !IsNil(o.Regex) { toSerialize["regex"] = o.Regex } @@ -125,44 +96,6 @@ func (o FilterTypeRegex) ToMap() (map[string]interface{}, error) { } func (o *FilterTypeRegex) UnmarshalJSON(data []byte) (err error) { - // This validates that all required properties are included in the JSON object - // by unmarshalling the object into a generic map with string keys and checking - // that every required field exists as a key in the generic map. - requiredProperties := []string{ - "type", - } - - // defaultValueFuncMap captures the default values for required properties. - // These values are used when required properties are missing from the payload. - defaultValueFuncMap := map[string]func() interface{} { - } - var defaultValueApplied bool - allProperties := make(map[string]interface{}) - - err = json.Unmarshal(data, &allProperties) - - if err != nil { - return err; - } - - for _, requiredProperty := range(requiredProperties) { - if value, exists := allProperties[requiredProperty]; !exists || value == "" { - if _, ok := defaultValueFuncMap[requiredProperty]; ok { - allProperties[requiredProperty] = defaultValueFuncMap[requiredProperty]() - defaultValueApplied = true - } - } - if value, exists := allProperties[requiredProperty]; !exists || value == ""{ - return fmt.Errorf("no value given for required property %v", requiredProperty) - } - } - - if defaultValueApplied { - data, err = json.Marshal(allProperties) - if err != nil{ - return err - } - } varFilterTypeRegex := _FilterTypeRegex{} err = json.Unmarshal(data, &varFilterTypeRegex) @@ -176,7 +109,6 @@ func (o *FilterTypeRegex) UnmarshalJSON(data []byte) (err error) { additionalProperties := make(map[string]interface{}) if err = json.Unmarshal(data, &additionalProperties); err == nil { - delete(additionalProperties, "type") delete(additionalProperties, "regex") o.AdditionalProperties = additionalProperties } diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_fruit_juice.go b/samples/openapi3/client/petstore/go/go-petstore/model_fruit_juice.go new file mode 100644 index 0000000000000..972b53f000e52 --- /dev/null +++ b/samples/openapi3/client/petstore/go/go-petstore/model_fruit_juice.go @@ -0,0 +1,186 @@ +/* +OpenAPI Petstore + +This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + +API version: 1.0.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package petstore + +import ( + "encoding/json" + "fmt" +) + +// checks if the FruitJuice type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &FruitJuice{} + +// FruitJuice struct for FruitJuice +type FruitJuice struct { + Fruit GmFruit `json:"fruit"` + AdditionalProperties map[string]interface{} +} + +type _FruitJuice FruitJuice + +// NewFruitJuice instantiates a new FruitJuice object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewFruitJuice(fruit GmFruit) *FruitJuice { + this := FruitJuice{} + this.Fruit = fruit + return &this +} + +// NewFruitJuiceWithDefaults instantiates a new FruitJuice object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewFruitJuiceWithDefaults() *FruitJuice { + this := FruitJuice{} + return &this +} + +// GetFruit returns the Fruit field value +func (o *FruitJuice) GetFruit() GmFruit { + if o == nil { + var ret GmFruit + return ret + } + + return o.Fruit +} + +// GetFruitOk returns a tuple with the Fruit field value +// and a boolean to check if the value has been set. +func (o *FruitJuice) GetFruitOk() (*GmFruit, bool) { + if o == nil { + return nil, false + } + return &o.Fruit, true +} + +// SetFruit sets field value +func (o *FruitJuice) SetFruit(v GmFruit) { + o.Fruit = v +} + + +func (o FruitJuice) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o FruitJuice) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["fruit"] = o.Fruit + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *FruitJuice) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "fruit", + } + + // defaultValueFuncMap captures the default values for required properties. + // These values are used when required properties are missing from the payload. + defaultValueFuncMap := map[string]func() interface{} { + } + var defaultValueApplied bool + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err; + } + + for _, requiredProperty := range(requiredProperties) { + if value, exists := allProperties[requiredProperty]; !exists || value == "" { + if _, ok := defaultValueFuncMap[requiredProperty]; ok { + allProperties[requiredProperty] = defaultValueFuncMap[requiredProperty]() + defaultValueApplied = true + } + } + if value, exists := allProperties[requiredProperty]; !exists || value == ""{ + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + if defaultValueApplied { + data, err = json.Marshal(allProperties) + if err != nil{ + return err + } + } + varFruitJuice := _FruitJuice{} + + err = json.Unmarshal(data, &varFruitJuice) + + if err != nil { + return err + } + + *o = FruitJuice(varFruitJuice) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(data, &additionalProperties); err == nil { + delete(additionalProperties, "fruit") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableFruitJuice struct { + value *FruitJuice + isSet bool +} + +func (v NullableFruitJuice) Get() *FruitJuice { + return v.value +} + +func (v *NullableFruitJuice) Set(val *FruitJuice) { + v.value = val + v.isSet = true +} + +func (v NullableFruitJuice) IsSet() bool { + return v.isSet +} + +func (v *NullableFruitJuice) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableFruitJuice(val *FruitJuice) *NullableFruitJuice { + return &NullableFruitJuice{value: val, isSet: true} +} + +func (v NullableFruitJuice) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableFruitJuice) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_gm_fruit.go b/samples/openapi3/client/petstore/go/go-petstore/model_gm_fruit.go index 59c6cbea0d1b7..8823193a061b1 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_gm_fruit.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_gm_fruit.go @@ -55,7 +55,7 @@ func (dst *GmFruit) UnmarshalJSON(data []byte) error { } // Marshal data from the first non-nil pointers in the struct to JSON -func (src *GmFruit) MarshalJSON() ([]byte, error) { +func (src GmFruit) MarshalJSON() ([]byte, error) { if src.Apple != nil { return json.Marshal(&src.Apple) } diff --git a/samples/openapi3/client/petstore/go/go.mod b/samples/openapi3/client/petstore/go/go.mod index 6f52440961486..98cece85532f8 100644 --- a/samples/openapi3/client/petstore/go/go.mod +++ b/samples/openapi3/client/petstore/go/go.mod @@ -6,10 +6,10 @@ replace go-petstore => ./go-petstore require ( cloud.google.com/go/compute v1.20.1 // indirect - github.com/stretchr/testify v1.9.0 + github.com/stretchr/testify v1.10.0 go-petstore v0.0.0-00010101000000-000000000000 - golang.org/x/net v0.27.0 // indirect - golang.org/x/oauth2 v0.21.0 + golang.org/x/net v0.31.0 // indirect + golang.org/x/oauth2 v0.24.0 google.golang.org/protobuf v1.31.0 // indirect gopkg.in/validator.v2 v2.0.1 // indirect ) diff --git a/samples/openapi3/client/petstore/go/go.sum b/samples/openapi3/client/petstore/go/go.sum index 3dda4241110b0..857525aa9d07a 100644 --- a/samples/openapi3/client/petstore/go/go.sum +++ b/samples/openapi3/client/petstore/go/go.sum @@ -859,6 +859,8 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -898,6 +900,7 @@ golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1m golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= +golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -1040,6 +1043,8 @@ golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= +golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo= +golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -1087,6 +1092,8 @@ golang.org/x/oauth2 v0.20.0 h1:4mQdhULixXKP1rwYBW0vAijoXnkTG0BLCDRzfe1idMo= golang.org/x/oauth2 v0.20.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs= golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/oauth2 v0.24.0 h1:KTBBxWqUa0ykRPLtV69rRto9TLXcqYkeswu48x/gvNE= +golang.org/x/oauth2 v0.24.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -1107,6 +1114,7 @@ golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -1192,6 +1200,7 @@ golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -1209,6 +1218,7 @@ golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY= golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4= +golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1230,6 +1240,7 @@ golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= diff --git a/samples/openapi3/client/petstore/go/model_test.go b/samples/openapi3/client/petstore/go/model_test.go index cc6eabbeaa0a3..fe4dde50935e5 100644 --- a/samples/openapi3/client/petstore/go/model_test.go +++ b/samples/openapi3/client/petstore/go/model_test.go @@ -1,7 +1,9 @@ package main import ( + "bytes" "encoding/json" + "strings" "testing" sw "go-petstore" @@ -63,3 +65,19 @@ func TestRequiredFieldsAreValidated(t *testing.T) { assert.ErrorContains(err, expected, "Pet should return error when missing required fields") } + +func TestRequiredAnyOfMarshalling(t *testing.T) { + // Given + bodyBuf := &bytes.Buffer{} + bananaLengthCm := float32(23.4) + req := &sw.FruitJuice{Fruit: sw.GmFruit{ + Banana: &sw.Banana{LengthCm: &bananaLengthCm}, + }} + + // When + err := json.NewEncoder(bodyBuf).Encode(req) + + // Then + assert.Nil(t, err) + assert.Equal(t, strings.TrimSpace(bodyBuf.String()), "{\"fruit\":{\"lengthCm\":23.4}}") +} From 47665aaa97cb1975c5382165f9048eeb9918034f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ernesto=20Fern=C3=A1ndez?= Date: Wed, 27 Nov 2024 07:16:10 -0300 Subject: [PATCH 05/12] Fix a few issues with the C generator (part 1 version 2) (#14434) * C: add a template for an empty any_type.h header Some generated C apis fail to build because the source files get '#include "any_type.h"' lines, but no such header gets generated. As a simple fix, add a new template for an empty file with that name. This is enough to fix the problem for us, because all the generic type stuff is handled by object_t. * C: fix enums I'm guessing that enums have not been used much with the C generator before, because they always seem to produce code that doesn't build, or that tries to free them after use. This patch fixes all the problems we've encountered so far, except for those that need checking the return type. I'll come back to that later. * C: fix confusion of 'classname'/'classFilename' * C: fix issues with returned enums Currently, the C templates never check if a function returns an enum inside mustache, so when that happens the generated code has broken return types and doesn't build. I originally tried to fix this by extending CodegenOperation to implement a 'returnTypeIsEnum' check, but William Cheng suggested[1] that I use the existing 'returnProperty' instead: https://github.com/OpenAPITools/openapi-generator/pull/14379#discussion_r1064636735 So do that. * C: update the samples As required for a pull request, run the generate-samples.sh script and commit the changes. * update samples --------- Co-authored-by: William Cheng --- .../languages/CLibcurlClientCodegen.java | 1 + .../C-libcurl/CMakeLists.txt.mustache | 1 + .../C-libcurl/any_type-header.mustache | 5 +++ .../resources/C-libcurl/api-body.mustache | 14 ++++---- .../resources/C-libcurl/api-header.mustache | 2 +- .../resources/C-libcurl/model-body.mustache | 34 ++++++++++++++++--- .../resources/C-libcurl/model-header.mustache | 16 +++++++-- .../.openapi-generator/FILES | 1 + .../c-useJsonUnformatted/CMakeLists.txt | 1 + .../c-useJsonUnformatted/model/any_type.h | 5 +++ .../petstore/c/.openapi-generator/FILES | 1 + samples/client/petstore/c/model/any_type.h | 5 +++ 12 files changed, 73 insertions(+), 13 deletions(-) create mode 100644 modules/openapi-generator/src/main/resources/C-libcurl/any_type-header.mustache create mode 100644 samples/client/petstore/c-useJsonUnformatted/model/any_type.h create mode 100644 samples/client/petstore/c/model/any_type.h diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CLibcurlClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CLibcurlClientCodegen.java index b6864a92cc1e5..397c1c6660456 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CLibcurlClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CLibcurlClientCodegen.java @@ -368,6 +368,7 @@ public void processOpts() { // Object files in model folder supportingFiles.add(new SupportingFile("object-body.mustache", "model", "object.c")); supportingFiles.add(new SupportingFile("object-header.mustache", "model", "object.h")); + supportingFiles.add(new SupportingFile("any_type-header.mustache", "model", "any_type.h")); } @Override diff --git a/modules/openapi-generator/src/main/resources/C-libcurl/CMakeLists.txt.mustache b/modules/openapi-generator/src/main/resources/C-libcurl/CMakeLists.txt.mustache index 34c311601440d..eafd251fced45 100644 --- a/modules/openapi-generator/src/main/resources/C-libcurl/CMakeLists.txt.mustache +++ b/modules/openapi-generator/src/main/resources/C-libcurl/CMakeLists.txt.mustache @@ -76,6 +76,7 @@ set(HDRS include/keyValuePair.h external/cJSON.h model/object.h + model/any_type.h {{#models}} {{#model}} model/{{classFilename}}.h diff --git a/modules/openapi-generator/src/main/resources/C-libcurl/any_type-header.mustache b/modules/openapi-generator/src/main/resources/C-libcurl/any_type-header.mustache new file mode 100644 index 0000000000000..7bdc92487f5b7 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/C-libcurl/any_type-header.mustache @@ -0,0 +1,5 @@ +/* + * any_type.h + * + * A placeholder for now, this type isn't really needed. + */ diff --git a/modules/openapi-generator/src/main/resources/C-libcurl/api-body.mustache b/modules/openapi-generator/src/main/resources/C-libcurl/api-body.mustache index 8f04538fa1633..191a408cbd1e0 100644 --- a/modules/openapi-generator/src/main/resources/C-libcurl/api-body.mustache +++ b/modules/openapi-generator/src/main/resources/C-libcurl/api-body.mustache @@ -98,7 +98,7 @@ end: // {{{.}}} // {{/notes}} -{{#returnType}}{{#returnTypeIsPrimitive}}{{#returnSimpleType}}{{{.}}}*{{/returnSimpleType}}{{^returnSimpleType}}{{#isArray}}{{{.}}}_t*{{/isArray}}{{#isMap}}{{{.}}}{{/isMap}}{{/returnSimpleType}}{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}{{{.}}}_t*{{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}void{{/returnType}} +{{#returnType}}{{#returnTypeIsPrimitive}}{{#returnSimpleType}}{{{.}}}*{{/returnSimpleType}}{{^returnSimpleType}}{{#isArray}}{{{.}}}_t*{{/isArray}}{{#isMap}}{{{.}}}{{/isMap}}{{/returnSimpleType}}{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}{{#returnProperty}}{{^isEnum}}{{{returnType}}}_t*{{/isEnum}}{{#isEnum}}{{projectName}}_{{{returnType}}}_{{returnEnumName}}_e{{/isEnum}}{{/returnProperty}}{{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}void{{/returnType}} {{{classname}}}_{{{operationId}}}(apiClient_t *apiClient{{#allParams}}, {{#isPrimitiveType}}{{#isNumber}}{{{dataType}}} {{/isNumber}}{{#isLong}}{{{dataType}}} {{/isLong}}{{#isInteger}}{{{dataType}}} *{{/isInteger}}{{#isDouble}}{{{dataType}}} {{/isDouble}}{{#isFloat}}{{{dataType}}} {{/isFloat}}{{#isBoolean}}{{dataType}} *{{/isBoolean}}{{#isEnum}}{{#isString}}{{projectName}}_{{operationId}}_{{baseName}}_e {{/isString}}{{/isEnum}}{{^isEnum}}{{#isString}}{{{dataType}}} *{{/isString}}{{/isEnum}}{{#isByteArray}}{{{dataType}}} *{{/isByteArray}}{{#isDate}}{{{dataType}}} {{/isDate}}{{#isDateTime}}{{{dataType}}} {{/isDateTime}}{{#isFile}}{{{dataType}}} {{/isFile}}{{#isFreeFormObject}}{{dataType}}_t *{{/isFreeFormObject}}{{/isPrimitiveType}}{{^isArray}}{{^isPrimitiveType}}{{#isModel}}{{#isEnum}}{{datatypeWithEnum}}_e {{/isEnum}}{{^isEnum}}{{{dataType}}}_t *{{/isEnum}}{{/isModel}}{{^isModel}}{{#isEnum}}{{datatypeWithEnum}}_e {{/isEnum}}{{/isModel}}{{#isUuid}}{{dataType}} *{{/isUuid}}{{#isEmail}}{{dataType}} {{/isEmail}}{{/isPrimitiveType}}{{/isArray}}{{#isContainer}}{{#isArray}}{{dataType}}_t *{{/isArray}}{{#isMap}}{{dataType}} {{/isMap}}{{/isContainer}}{{{paramName}}}{{/allParams}}) { list_t *localVarQueryParameters = {{#hasQueryParams}}list_createList();{{/hasQueryParams}}{{^hasQueryParams}}NULL;{{/hasQueryParams}} @@ -263,7 +263,7 @@ end: {{#isPrimitiveType}}{{#isNumber}}{{{dataType}}}{{/isNumber}}{{#isLong}}{{{dataType}}}{{/isLong}}{{#isInteger}}{{{dataType}}}{{/isInteger}}{{#isDouble}}{{{dataType}}}{{/isDouble}}{{#isFloat}}{{{dataType}}}{{/isFloat}}{{#isBoolean}}{{dataType}}{{/isBoolean}}{{#isEnum}}{{#isString}}{{projectName}}_{{operationId}}_{{baseName}}_e{{/isString}}{{/isEnum}}{{^isEnum}}{{#isString}}{{{dataType}}} *{{/isString}}{{/isEnum}}{{#isByteArray}}{{{dataType}}} *{{/isByteArray}}{{#isDate}}{{{dataType}}}{{/isDate}}{{#isDateTime}}{{{dataType}}}{{/isDateTime}}{{#isFile}}{{{dataType}}}{{/isFile}}{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{^isEnum}}{{{dataType}}}_t *{{/isEnum}}{{/isModel}}{{^isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{/isModel}}{{#isUuid}}{{dataType}} *{{/isUuid}}{{#isEmail}}{{dataType}}{{/isEmail}}{{/isPrimitiveType}} valueForm_{{paramName}} = 0; keyValuePair_t *keyPairForm_{{paramName}} = 0; {{/isFile}} - if ({{paramName}} != NULL) + if ({{paramName}} != {{^isEnum}}NULL{{/isEnum}}{{#isEnum}}0{{/isEnum}}) { {{#isFile}} keyForm_{{paramName}} = strdup("{{{baseName}}}"); @@ -399,9 +399,9 @@ end: {{^returnContainer}} //nonprimitive not container cJSON *{{classname}}localVarJSON = cJSON_Parse(apiClient->dataReceived); - {{{returnBaseType}}}_t *elementToReturn = {{{returnBaseType}}}_parseFromJSON({{classname}}localVarJSON); + {{#returnProperty}}{{^isEnum}}{{{returnBaseType}}}_t *{{/isEnum}}{{#isEnum}}{{projectName}}_{{{returnType}}}_{{returnEnumName}}_e {{/isEnum}}{{/returnProperty}}elementToReturn = {{{returnBaseType}}}_parseFromJSON({{classname}}localVarJSON); cJSON_Delete({{classname}}localVarJSON); - if(elementToReturn == NULL) { + if(elementToReturn == {{#returnProperty}}{{^isEnum}}NULL{{/isEnum}}{{#isEnum}}0{{/isEnum}}{{/returnProperty}}) { // return 0; } @@ -524,8 +524,10 @@ end: keyForm_{{{paramName}}} = NULL; } if (valueForm_{{{paramName}}}) { + {{^isEnum}} free(valueForm_{{{paramName}}}); - valueForm_{{{paramName}}} = NULL; + {{/isEnum}} + valueForm_{{{paramName}}} = {{^isEnum}}NULL{{/isEnum}}{{#isEnum}}0{{/isEnum}}; } free(keyPairForm_{{paramName}}); {{/isString}} @@ -541,7 +543,7 @@ end: return elementToReturn; end: free(localVarPath); - return NULL; + return {{#returnProperty}}{{^isEnum}}NULL{{/isEnum}}{{#isEnum}}0{{/isEnum}}{{/returnProperty}}; {{/returnType}} {{^returnType}} //No return type diff --git a/modules/openapi-generator/src/main/resources/C-libcurl/api-header.mustache b/modules/openapi-generator/src/main/resources/C-libcurl/api-header.mustache index 223043ec1ed64..78ac5f5767823 100644 --- a/modules/openapi-generator/src/main/resources/C-libcurl/api-header.mustache +++ b/modules/openapi-generator/src/main/resources/C-libcurl/api-header.mustache @@ -32,7 +32,7 @@ typedef enum { {{projectName}}_{{operationId}}_{{enumName}}_NULL = 0{{#enumVars // {{{.}}} // {{/notes}} -{{#returnType}}{{#returnTypeIsPrimitive}}{{#returnSimpleType}}{{{.}}}*{{/returnSimpleType}}{{^returnSimpleType}}{{#isArray}}{{{.}}}_t*{{/isArray}}{{#isMap}}{{{.}}}{{/isMap}}{{/returnSimpleType}}{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}{{{.}}}_t*{{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}void{{/returnType}} +{{#returnType}}{{#returnTypeIsPrimitive}}{{#returnSimpleType}}{{{.}}}*{{/returnSimpleType}}{{^returnSimpleType}}{{#isArray}}{{{.}}}_t*{{/isArray}}{{#isMap}}{{{.}}}{{/isMap}}{{/returnSimpleType}}{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}{{#returnProperty}}{{^isEnum}}{{{returnType}}}_t*{{/isEnum}}{{#isEnum}}{{projectName}}_{{{returnType}}}_{{returnEnumName}}_e{{/isEnum}}{{/returnProperty}}{{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}void{{/returnType}} {{{classname}}}_{{{operationId}}}(apiClient_t *apiClient{{#allParams}}, {{#isPrimitiveType}}{{#isNumber}}{{{dataType}}} {{/isNumber}}{{#isLong}}{{{dataType}}} {{/isLong}}{{#isInteger}}{{{dataType}}} *{{/isInteger}}{{#isDouble}}{{{dataType}}} {{/isDouble}}{{#isFloat}}{{{dataType}}} {{/isFloat}}{{#isBoolean}}{{dataType}} *{{/isBoolean}}{{#isEnum}}{{#isString}}{{projectName}}_{{operationId}}_{{baseName}}_e {{/isString}}{{/isEnum}}{{^isEnum}}{{#isString}}{{{dataType}}} *{{/isString}}{{/isEnum}}{{#isByteArray}}{{{dataType}}} *{{/isByteArray}}{{#isDate}}{{{dataType}}} {{/isDate}}{{#isDateTime}}{{{dataType}}} {{/isDateTime}}{{#isFile}}{{{dataType}}} {{/isFile}}{{#isFreeFormObject}}{{dataType}}_t *{{/isFreeFormObject}}{{/isPrimitiveType}}{{^isArray}}{{^isPrimitiveType}}{{#isModel}}{{#isEnum}}{{datatypeWithEnum}}_e {{/isEnum}}{{^isEnum}}{{{dataType}}}_t *{{/isEnum}}{{/isModel}}{{^isModel}}{{#isEnum}}{{datatypeWithEnum}}_e {{/isEnum}}{{/isModel}}{{#isUuid}}{{dataType}} *{{/isUuid}}{{#isEmail}}{{dataType}} {{/isEmail}}{{/isPrimitiveType}}{{/isArray}}{{#isContainer}}{{#isArray}}{{dataType}}_t *{{/isArray}}{{#isMap}}{{dataType}} {{/isMap}}{{/isContainer}}{{{paramName}}}{{/allParams}}); diff --git a/modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache b/modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache index 028ea6db42023..af6e1127e5bbf 100644 --- a/modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache +++ b/modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache @@ -25,7 +25,7 @@ char* {{classFilename}}_{{classname}}_ToString({{projectName}}_{{classVarName}}_ return 0; } -cJSON *{{classFilename}}_{{classname}}_convertToJSON({{projectName}}_{{classVarName}}_{{enumName}}_e {{classname}}) { +cJSON *{{classname}}_convertToJSON({{projectName}}_{{classVarName}}_{{enumName}}_e {{classname}}) { cJSON *item = cJSON_CreateObject(); {{#isString}} if(cJSON_AddStringToObject(item, "{{{classname}}}", {{classFilename}}_{{{classname}}}_ToString({{{classname}}})) == NULL) { @@ -48,7 +48,7 @@ fail: return NULL; } -{{projectName}}_{{classVarName}}_{{enumName}}_e {{classFilename}}_{{classname}}_parseFromJSON(cJSON *{{classname}}JSON) { +{{projectName}}_{{classVarName}}_{{enumName}}_e {{classname}}_parseFromJSON(cJSON *{{classname}}JSON) { {{projectName}}_{{classVarName}}_{{enumName}}_e *{{classname}} = NULL; {{#isEnum}} {{#isNumeric}} @@ -75,6 +75,7 @@ end: {{^isEnum}} {{#vars}} {{^isContainer}} + {{#isPrimitiveType}} {{^isModel}} {{#isEnum}} char* {{classname}}_{{name}}_ToString({{projectName}}_{{classVarName}}_{{enumName}}_e {{name}}) { @@ -96,6 +97,7 @@ char* {{classname}}_{{name}}_ToString({{projectName}}_{{classVarName}}_{{enumNam } {{/isEnum}} {{/isModel}} + {{/isPrimitiveType}} {{/isContainer}} {{#isContainer}} {{#items}} @@ -138,7 +140,12 @@ char* {{classname}}_{{name}}_ToString({{projectName}}_{{classVarName}}_{{enumNam {{/isModel}} {{^isModel}} {{^isFreeFormObject}} + {{^isEnum}} {{datatype}}_t *{{name}}{{^-last}},{{/-last}} + {{/isEnum}} + {{#isEnum}} + {{projectName}}_{{dataType}}_{{enumName}}_e {{name}}{{^-last}},{{/-last}} + {{/isEnum}} {{/isFreeFormObject}} {{/isModel}} {{#isUuid}} @@ -227,10 +234,12 @@ void {{classname}}_free({{classname}}_t *{{classname}}) { {{/isModel}} {{^isModel}} {{^isFreeFormObject}} + {{^isEnum}} if ({{{classname}}}->{{{name}}}) { {{{complexType}}}_free({{{classname}}}->{{{name}}}); {{classname}}->{{name}} = NULL; } + {{/isEnum}} {{/isFreeFormObject}} {{/isModel}} {{#isUuid}} @@ -337,7 +346,12 @@ cJSON *{{classname}}_convertToJSON({{classname}}_t *{{classname}}) { } {{/isEnum}} {{#isEnum}} + {{#isPrimitiveType}} if ({{projectName}}_{{classVarName}}_{{enumName}}_NULL == {{{classname}}}->{{{name}}}) { + {{/isPrimitiveType}} + {{^isPrimitiveType}} + if ({{projectName}}_{{dataType}}_{{enumName}}_NULL == {{{classname}}}->{{{name}}}) { + {{/isPrimitiveType}} goto fail; } {{/isEnum}} @@ -347,7 +361,12 @@ cJSON *{{classname}}_convertToJSON({{classname}}_t *{{classname}}) { if({{{classname}}}->{{{name}}}) { {{/isEnum}} {{#isEnum}} + {{#isPrimitiveType}} if({{{classname}}}->{{{name}}} != {{projectName}}_{{classVarName}}_{{enumName}}_NULL) { + {{/isPrimitiveType}} + {{^isPrimitiveType}} + if({{{classname}}}->{{{name}}} != {{projectName}}_{{dataType}}_{{enumName}}_NULL) { + {{/isPrimitiveType}} {{/isEnum}} {{/required}} {{^isContainer}} @@ -589,7 +608,12 @@ fail: {{^isModel}} {{^isFreeFormObject}} // define the local variable for {{{classname}}}->{{{name}}} + {{^isEnum}} {{complexType}}_t *{{name}}_local_nonprim = NULL; + {{/isEnum}} + {{#isEnum}} + {{projectName}}_{{dataType}}_{{enumName}}_e {{name}}_local_nonprim = 0; + {{/isEnum}} {{/isFreeFormObject}} {{/isModel}} @@ -853,7 +877,7 @@ fail: {{/isModel}} {{^isModel}} {{^isFreeFormObject}} - {{^required}}{{{name}}} ? {{/required}}{{{name}}}_local_nonprim{{^required}} : NULL{{/required}}{{^-last}},{{/-last}} + {{^required}}{{{name}}} ? {{/required}}{{{name}}}_local_nonprim{{^required}} : {{^isEnum}}NULL{{/isEnum}}{{#isEnum}}0{{/isEnum}}{{/required}}{{^-last}},{{/-last}} {{/isFreeFormObject}} {{/isModel}} {{#isUuid}} @@ -929,8 +953,10 @@ end: {{^isModel}} {{^isFreeFormObject}} if ({{{name}}}_local_nonprim) { + {{^isEnum}} {{complexType}}_free({{{name}}}_local_nonprim); - {{{name}}}_local_nonprim = NULL; + {{/isEnum}} + {{{name}}}_local_nonprim = {{^isEnum}}NULL{{/isEnum}}{{#isEnum}}0{{/isEnum}}; } {{/isFreeFormObject}} {{/isModel}} diff --git a/modules/openapi-generator/src/main/resources/C-libcurl/model-header.mustache b/modules/openapi-generator/src/main/resources/C-libcurl/model-header.mustache index f86b1ba7edacf..d69dc8d5cd34c 100644 --- a/modules/openapi-generator/src/main/resources/C-libcurl/model-header.mustache +++ b/modules/openapi-generator/src/main/resources/C-libcurl/model-header.mustache @@ -30,14 +30,15 @@ char* {{classFilename}}_{{classname}}_ToString({{projectName}}_{{classVarName}}_ {{projectName}}_{{classVarName}}_{{enumName}}_e {{classFilename}}_{{classname}}_FromString(char* {{classname}}); -//cJSON *{{classFilename}}_{{classname}}_convertToJSON({{projectName}}_{{classVarName}}_{{enumName}}_e {{classname}}); +cJSON *{{classname}}_convertToJSON({{projectName}}_{{classVarName}}_{{enumName}}_e {{classname}}); -//{{projectName}}_{{classVarName}}_{{enumName}}_e {{classFilename}}_{{classname}}_parseFromJSON(cJSON *{{classname}}JSON); +{{projectName}}_{{classVarName}}_{{enumName}}_e {{classname}}_parseFromJSON(cJSON *{{classname}}JSON); {{/isEnum}} {{^isEnum}} {{#vars}} {{^isContainer}} + {{#isPrimitiveType}} {{^isModel}} {{#isEnum}} // Enum {{enumName}} for {{classVarName}} @@ -52,6 +53,7 @@ char* {{classFilename}}_{{name}}_ToString({{projectName}}_{{classVarName}}_{{enu {{/isEnum}} {{/isModel}} + {{/isPrimitiveType}} {{/isContainer}} {{#isContainer}} {{#items}} @@ -88,7 +90,12 @@ typedef struct {{classname}}_t { {{/isModel}} {{^isModel}} {{^isFreeFormObject}} + {{^isEnum}} {{datatype}}_t *{{name}}; // custom + {{/isEnum}} + {{#isEnum}} + {{projectName}}_{{dataType}}_{{enumName}}_e {{name}}; //referenced enum + {{/isEnum}} {{/isFreeFormObject}} {{/isModel}} {{#isUuid}} @@ -163,7 +170,12 @@ typedef struct {{classname}}_t { {{/isModel}} {{^isModel}} {{^isFreeFormObject}} + {{^isEnum}} {{datatype}}_t *{{name}}{{^-last}},{{/-last}} + {{/isEnum}} + {{#isEnum}} + {{projectName}}_{{dataType}}_{{enumName}}_e {{name}}{{^-last}},{{/-last}} + {{/isEnum}} {{/isFreeFormObject}} {{/isModel}} {{#isUuid}} diff --git a/samples/client/petstore/c-useJsonUnformatted/.openapi-generator/FILES b/samples/client/petstore/c-useJsonUnformatted/.openapi-generator/FILES index de78f2c09bb84..56afd08ac99d5 100644 --- a/samples/client/petstore/c-useJsonUnformatted/.openapi-generator/FILES +++ b/samples/client/petstore/c-useJsonUnformatted/.openapi-generator/FILES @@ -26,6 +26,7 @@ include/binary.h include/keyValuePair.h include/list.h libcurl.licence +model/any_type.h model/api_response.c model/api_response.h model/category.c diff --git a/samples/client/petstore/c-useJsonUnformatted/CMakeLists.txt b/samples/client/petstore/c-useJsonUnformatted/CMakeLists.txt index 9d01b09104dc6..e41b31d33abb1 100644 --- a/samples/client/petstore/c-useJsonUnformatted/CMakeLists.txt +++ b/samples/client/petstore/c-useJsonUnformatted/CMakeLists.txt @@ -75,6 +75,7 @@ set(HDRS include/keyValuePair.h external/cJSON.h model/object.h + model/any_type.h model/mapped_model.h model/api_response.h model/category.h diff --git a/samples/client/petstore/c-useJsonUnformatted/model/any_type.h b/samples/client/petstore/c-useJsonUnformatted/model/any_type.h new file mode 100644 index 0000000000000..7bdc92487f5b7 --- /dev/null +++ b/samples/client/petstore/c-useJsonUnformatted/model/any_type.h @@ -0,0 +1,5 @@ +/* + * any_type.h + * + * A placeholder for now, this type isn't really needed. + */ diff --git a/samples/client/petstore/c/.openapi-generator/FILES b/samples/client/petstore/c/.openapi-generator/FILES index 974bd47125f3c..4f6e6397e71e1 100644 --- a/samples/client/petstore/c/.openapi-generator/FILES +++ b/samples/client/petstore/c/.openapi-generator/FILES @@ -25,6 +25,7 @@ include/binary.h include/keyValuePair.h include/list.h libcurl.licence +model/any_type.h model/api_response.c model/api_response.h model/category.c diff --git a/samples/client/petstore/c/model/any_type.h b/samples/client/petstore/c/model/any_type.h new file mode 100644 index 0000000000000..7bdc92487f5b7 --- /dev/null +++ b/samples/client/petstore/c/model/any_type.h @@ -0,0 +1,5 @@ +/* + * any_type.h + * + * A placeholder for now, this type isn't really needed. + */ From f8ca36b97ede3f4b13ea0747a56c796b2f999a2d Mon Sep 17 00:00:00 2001 From: Nelson Vides Date: Wed, 27 Nov 2024 15:09:21 +0100 Subject: [PATCH 06/12] =?UTF-8?q?Erlang=20server=20=E2=80=93=20minor=20fix?= =?UTF-8?q?=20to=20return=20type=20and=20generated=20doc=20(#20197)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * erlang-server: add jesse to app.up release * erlang-server: remove dialyzer errors that might not be related to the program * erlang-server: minor fixes to return types and generated docs --- .../src/main/resources/erlang-server/api.mustache | 2 +- .../src/main/resources/erlang-server/logic_handler.mustache | 2 +- samples/server/echo_api/erlang-server/src/openapi_api.erl | 2 +- .../server/echo_api/erlang-server/src/openapi_logic_handler.erl | 2 +- samples/server/petstore/erlang-server/src/openapi_api.erl | 2 +- .../server/petstore/erlang-server/src/openapi_logic_handler.erl | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/erlang-server/api.mustache b/modules/openapi-generator/src/main/resources/erlang-server/api.mustache index 1f0a90e2cd965..157e2b7a39ef5 100644 --- a/modules/openapi-generator/src/main/resources/erlang-server/api.mustache +++ b/modules/openapi-generator/src/main/resources/erlang-server/api.mustache @@ -90,7 +90,7 @@ prepare_validator(SchemaVer) -> prepare_validator(get_openapi_path(), SchemaVer). -doc """ -Loads the JSON schema and the desired validation draft into a `t:jesse_state:state()`. +Loads the JSON schema and the desired validation draft into a `t:jesse_state:state/0`. """. -spec prepare_validator(file:name_all(), binary()) -> jesse_state:state(). prepare_validator(OpenApiPath, SchemaVer) -> diff --git a/modules/openapi-generator/src/main/resources/erlang-server/logic_handler.mustache b/modules/openapi-generator/src/main/resources/erlang-server/logic_handler.mustache index e69edcc81414e..3dcaea8c91b2b 100644 --- a/modules/openapi-generator/src/main/resources/erlang-server/logic_handler.mustache +++ b/modules/openapi-generator/src/main/resources/erlang-server/logic_handler.mustache @@ -34,7 +34,7 @@ {accept_callback_return(), cowboy_req:req(), context()}. -callback provide_callback({{packageName}}_api:class(), {{packageName}}_api:operation_id(), cowboy_req:req(), context()) -> - {cowboy_req:resp_body(), cowboy_req:req(), context()}. + {provide_callback_return(), cowboy_req:req(), context()}. -export([api_key_callback/2, accept_callback/4, provide_callback/4]). -ignore_xref([api_key_callback/2, accept_callback/4, provide_callback/4]). diff --git a/samples/server/echo_api/erlang-server/src/openapi_api.erl b/samples/server/echo_api/erlang-server/src/openapi_api.erl index 30e7447bcfbdb..f528518af8c54 100644 --- a/samples/server/echo_api/erlang-server/src/openapi_api.erl +++ b/samples/server/echo_api/erlang-server/src/openapi_api.erl @@ -121,7 +121,7 @@ prepare_validator(SchemaVer) -> prepare_validator(get_openapi_path(), SchemaVer). -doc """ -Loads the JSON schema and the desired validation draft into a `t:jesse_state:state()`. +Loads the JSON schema and the desired validation draft into a `t:jesse_state:state/0`. """. -spec prepare_validator(file:name_all(), binary()) -> jesse_state:state(). prepare_validator(OpenApiPath, SchemaVer) -> diff --git a/samples/server/echo_api/erlang-server/src/openapi_logic_handler.erl b/samples/server/echo_api/erlang-server/src/openapi_logic_handler.erl index d47132f08238a..b0daeb1f9f558 100644 --- a/samples/server/echo_api/erlang-server/src/openapi_logic_handler.erl +++ b/samples/server/echo_api/erlang-server/src/openapi_logic_handler.erl @@ -34,7 +34,7 @@ {accept_callback_return(), cowboy_req:req(), context()}. -callback provide_callback(openapi_api:class(), openapi_api:operation_id(), cowboy_req:req(), context()) -> - {cowboy_req:resp_body(), cowboy_req:req(), context()}. + {provide_callback_return(), cowboy_req:req(), context()}. -export([api_key_callback/2, accept_callback/4, provide_callback/4]). -ignore_xref([api_key_callback/2, accept_callback/4, provide_callback/4]). diff --git a/samples/server/petstore/erlang-server/src/openapi_api.erl b/samples/server/petstore/erlang-server/src/openapi_api.erl index 42c168b7a731f..f8922a379cf2e 100644 --- a/samples/server/petstore/erlang-server/src/openapi_api.erl +++ b/samples/server/petstore/erlang-server/src/openapi_api.erl @@ -111,7 +111,7 @@ prepare_validator(SchemaVer) -> prepare_validator(get_openapi_path(), SchemaVer). -doc """ -Loads the JSON schema and the desired validation draft into a `t:jesse_state:state()`. +Loads the JSON schema and the desired validation draft into a `t:jesse_state:state/0`. """. -spec prepare_validator(file:name_all(), binary()) -> jesse_state:state(). prepare_validator(OpenApiPath, SchemaVer) -> diff --git a/samples/server/petstore/erlang-server/src/openapi_logic_handler.erl b/samples/server/petstore/erlang-server/src/openapi_logic_handler.erl index d47132f08238a..b0daeb1f9f558 100644 --- a/samples/server/petstore/erlang-server/src/openapi_logic_handler.erl +++ b/samples/server/petstore/erlang-server/src/openapi_logic_handler.erl @@ -34,7 +34,7 @@ {accept_callback_return(), cowboy_req:req(), context()}. -callback provide_callback(openapi_api:class(), openapi_api:operation_id(), cowboy_req:req(), context()) -> - {cowboy_req:resp_body(), cowboy_req:req(), context()}. + {provide_callback_return(), cowboy_req:req(), context()}. -export([api_key_callback/2, accept_callback/4, provide_callback/4]). -ignore_xref([api_key_callback/2, accept_callback/4, provide_callback/4]). From 037cb12f348baa9afffb9d03545e1458e06670da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ernesto=20Fern=C3=A1ndez?= Date: Thu, 28 Nov 2024 05:27:42 -0300 Subject: [PATCH 07/12] Tests for recent C fixes (#20200) * [C] Add test schemas for the recent changes The recent commit 47665aaa97cb ("Fix a few issues with the C generator (part 1 version 2) (#14434)") didn't include any test schemas. Add them now, as requested: https://github.com/OpenAPITools/openapi-generator/pull/14434#issuecomment-2497497110 * Update samples * Fix sample update with missing files * More fixes for sample updates --- .../src/test/resources/2_0/c/petstore.yaml | 35 +++++++ .../.openapi-generator/FILES | 3 + .../c-useJsonUnformatted/CMakeLists.txt | 2 + .../petstore/c-useJsonUnformatted/README.md | 2 + .../c-useJsonUnformatted/api/PetAPI.c | 64 +++++++++++++ .../c-useJsonUnformatted/api/PetAPI.h | 9 ++ .../c-useJsonUnformatted/docs/PetAPI.md | 31 ++++++ .../c-useJsonUnformatted/docs/preference.md | 9 ++ .../c-useJsonUnformatted/docs/user.md | 2 + .../c-useJsonUnformatted/model/preference.c | 47 +++++++++ .../c-useJsonUnformatted/model/preference.h | 32 +++++++ .../c-useJsonUnformatted/model/user.c | 96 ++++++++++++++++++- .../c-useJsonUnformatted/model/user.h | 8 +- .../unit-test/test_preference.c | 56 +++++++++++ .../petstore/c/.openapi-generator/FILES | 3 + samples/client/petstore/c/README.md | 2 + samples/client/petstore/c/api/PetAPI.c | 64 +++++++++++++ samples/client/petstore/c/api/PetAPI.h | 9 ++ samples/client/petstore/c/docs/PetAPI.md | 31 ++++++ samples/client/petstore/c/docs/preference.md | 9 ++ samples/client/petstore/c/docs/user.md | 2 + samples/client/petstore/c/model/preference.c | 47 +++++++++ samples/client/petstore/c/model/preference.h | 32 +++++++ samples/client/petstore/c/model/user.c | 96 ++++++++++++++++++- samples/client/petstore/c/model/user.h | 8 +- .../petstore/c/unit-test/test_preference.c | 56 +++++++++++ 26 files changed, 749 insertions(+), 6 deletions(-) create mode 100644 samples/client/petstore/c-useJsonUnformatted/docs/preference.md create mode 100644 samples/client/petstore/c-useJsonUnformatted/model/preference.c create mode 100644 samples/client/petstore/c-useJsonUnformatted/model/preference.h create mode 100644 samples/client/petstore/c-useJsonUnformatted/unit-test/test_preference.c create mode 100644 samples/client/petstore/c/docs/preference.md create mode 100644 samples/client/petstore/c/model/preference.c create mode 100644 samples/client/petstore/c/model/preference.h create mode 100644 samples/client/petstore/c/unit-test/test_preference.c diff --git a/modules/openapi-generator/src/test/resources/2_0/c/petstore.yaml b/modules/openapi-generator/src/test/resources/2_0/c/petstore.yaml index c5125f976e749..082c039eadb95 100644 --- a/modules/openapi-generator/src/test/resources/2_0/c/petstore.yaml +++ b/modules/openapi-generator/src/test/resources/2_0/c/petstore.yaml @@ -75,6 +75,24 @@ paths: - petstore_auth: - 'write:pets' - 'read:pets' + /pet/specialty: + get: + tags: + - pet + summary: Specialty of the shop + description: Returns the kind of pet the store specializes in + operationId: specialtyPet + produces: + - application/xml + - application/json + parameters: [] + responses: + '200': + description: successful operation + schema: + $ref: '#/definitions/Preference' + security: + - api_key: [] /pet/findByStatus: get: tags: @@ -626,6 +644,17 @@ definitions: type: string xml: name: Category + Preference: + title: Pet preference + description: A user's preference in pets + type: string + enum: + - cats + - dogs + - birds + - fish + - snakes + - other User: title: a User description: A User who is purchasing from the pet store @@ -650,6 +679,12 @@ definitions: type: integer format: int32 description: User Status + extra: + type: object + nullable: true + additionalProperties: true + preference: + $ref: '#/definitions/Preference' xml: name: User Tag: diff --git a/samples/client/petstore/c-useJsonUnformatted/.openapi-generator/FILES b/samples/client/petstore/c-useJsonUnformatted/.openapi-generator/FILES index 56afd08ac99d5..043461c7a2e25 100644 --- a/samples/client/petstore/c-useJsonUnformatted/.openapi-generator/FILES +++ b/samples/client/petstore/c-useJsonUnformatted/.openapi-generator/FILES @@ -16,6 +16,7 @@ docs/category.md docs/model_with_set_propertes.md docs/order.md docs/pet.md +docs/preference.md docs/tag.md docs/user.md external/cJSON.c @@ -41,6 +42,8 @@ model/order.c model/order.h model/pet.c model/pet.h +model/preference.c +model/preference.h model/tag.c model/tag.h model/user.c diff --git a/samples/client/petstore/c-useJsonUnformatted/CMakeLists.txt b/samples/client/petstore/c-useJsonUnformatted/CMakeLists.txt index e41b31d33abb1..7eab107fda2f2 100644 --- a/samples/client/petstore/c-useJsonUnformatted/CMakeLists.txt +++ b/samples/client/petstore/c-useJsonUnformatted/CMakeLists.txt @@ -60,6 +60,7 @@ set(SRCS model/model_with_set_propertes.c model/order.c model/pet.c + model/preference.c model/tag.c model/user.c api/PetAPI.c @@ -82,6 +83,7 @@ set(HDRS model/model_with_set_propertes.h model/order.h model/pet.h + model/preference.h model/tag.h model/user.h api/PetAPI.h diff --git a/samples/client/petstore/c-useJsonUnformatted/README.md b/samples/client/petstore/c-useJsonUnformatted/README.md index a2724768f151c..707999204fbe2 100644 --- a/samples/client/petstore/c-useJsonUnformatted/README.md +++ b/samples/client/petstore/c-useJsonUnformatted/README.md @@ -70,6 +70,7 @@ Category | Method | HTTP request | Description *PetAPI* | [**PetAPI_findPetsByStatus**](docs/PetAPI.md#PetAPI_findPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status *PetAPI* | [**PetAPI_findPetsByTags**](docs/PetAPI.md#PetAPI_findPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags *PetAPI* | [**PetAPI_getPetById**](docs/PetAPI.md#PetAPI_getPetById) | **GET** /pet/{petId} | Find pet by ID +*PetAPI* | [**PetAPI_specialtyPet**](docs/PetAPI.md#PetAPI_specialtyPet) | **GET** /pet/specialty | Specialty of the shop *PetAPI* | [**PetAPI_updatePet**](docs/PetAPI.md#PetAPI_updatePet) | **PUT** /pet | Update an existing pet *PetAPI* | [**PetAPI_updatePetWithForm**](docs/PetAPI.md#PetAPI_updatePetWithForm) | **POST** /pet/{petId} | Updates a pet in the store with form data *PetAPI* | [**PetAPI_uploadFile**](docs/PetAPI.md#PetAPI_uploadFile) | **POST** /pet/{petId}/uploadImage | uploads an image @@ -96,6 +97,7 @@ Category | Method | HTTP request | Description - [model_with_set_propertes_t](docs/model_with_set_propertes.md) - [order_t](docs/order.md) - [pet_t](docs/pet.md) + - [preference_t](docs/preference.md) - [tag_t](docs/tag.md) - [user_t](docs/user.md) diff --git a/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.c b/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.c index f17d4fd0c26bf..6cb279c58bb38 100644 --- a/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.c +++ b/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.c @@ -460,6 +460,70 @@ PetAPI_getPetById(apiClient_t *apiClient, long petId) } +// Specialty of the shop +// +// Returns the kind of pet the store specializes in +// +openapi_petstore_preference__e +PetAPI_specialtyPet(apiClient_t *apiClient) +{ + list_t *localVarQueryParameters = NULL; + list_t *localVarHeaderParameters = NULL; + list_t *localVarFormParameters = NULL; + list_t *localVarHeaderType = list_createList(); + list_t *localVarContentType = NULL; + char *localVarBodyParameters = NULL; + + // create the path + long sizeOfPath = strlen("/pet/specialty")+1; + char *localVarPath = malloc(sizeOfPath); + snprintf(localVarPath, sizeOfPath, "/pet/specialty"); + + + + list_addElement(localVarHeaderType,"application/xml"); //produces + list_addElement(localVarHeaderType,"application/json"); //produces + apiClient_invoke(apiClient, + localVarPath, + localVarQueryParameters, + localVarHeaderParameters, + localVarFormParameters, + localVarHeaderType, + localVarContentType, + localVarBodyParameters, + "GET"); + + // uncomment below to debug the error response + //if (apiClient->response_code == 200) { + // printf("%s\n","successful operation"); + //} + //nonprimitive not container + cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); + openapi_petstore_preference__e elementToReturn = preference_parseFromJSON(PetAPIlocalVarJSON); + cJSON_Delete(PetAPIlocalVarJSON); + if(elementToReturn == 0) { + // return 0; + } + + //return type + if (apiClient->dataReceived) { + free(apiClient->dataReceived); + apiClient->dataReceived = NULL; + apiClient->dataReceivedLen = 0; + } + + + + list_freeList(localVarHeaderType); + + free(localVarPath); + return elementToReturn; +end: + free(localVarPath); + return 0; + +} + // Update an existing pet // void diff --git a/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.h b/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.h index 9b5c586fda78b..d33d0394b2d5b 100644 --- a/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.h +++ b/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.h @@ -7,6 +7,7 @@ #include "../include/binary.h" #include "../model/api_response.h" #include "../model/pet.h" +#include "../model/preference.h" // Enum STATUS for PetAPI_findPetsByStatus typedef enum { openapi_petstore_findPetsByStatus_STATUS_NULL = 0, openapi_petstore_findPetsByStatus_STATUS_available, openapi_petstore_findPetsByStatus_STATUS_pending, openapi_petstore_findPetsByStatus_STATUS_sold } openapi_petstore_findPetsByStatus_status_e; @@ -48,6 +49,14 @@ pet_t* PetAPI_getPetById(apiClient_t *apiClient, long petId); +// Specialty of the shop +// +// Returns the kind of pet the store specializes in +// +openapi_petstore_preference__e +PetAPI_specialtyPet(apiClient_t *apiClient); + + // Update an existing pet // void diff --git a/samples/client/petstore/c-useJsonUnformatted/docs/PetAPI.md b/samples/client/petstore/c-useJsonUnformatted/docs/PetAPI.md index 392ef4d08a7d9..bcdc9e8e1c362 100644 --- a/samples/client/petstore/c-useJsonUnformatted/docs/PetAPI.md +++ b/samples/client/petstore/c-useJsonUnformatted/docs/PetAPI.md @@ -9,6 +9,7 @@ Method | HTTP request | Description [**PetAPI_findPetsByStatus**](PetAPI.md#PetAPI_findPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status [**PetAPI_findPetsByTags**](PetAPI.md#PetAPI_findPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags [**PetAPI_getPetById**](PetAPI.md#PetAPI_getPetById) | **GET** /pet/{petId} | Find pet by ID +[**PetAPI_specialtyPet**](PetAPI.md#PetAPI_specialtyPet) | **GET** /pet/specialty | Specialty of the shop [**PetAPI_updatePet**](PetAPI.md#PetAPI_updatePet) | **PUT** /pet | Update an existing pet [**PetAPI_updatePetWithForm**](PetAPI.md#PetAPI_updatePetWithForm) | **POST** /pet/{petId} | Updates a pet in the store with form data [**PetAPI_uploadFile**](PetAPI.md#PetAPI_uploadFile) | **POST** /pet/{petId}/uploadImage | uploads an image @@ -153,6 +154,36 @@ Name | Type | Description | Notes [pet_t](pet.md) * +### Authorization + +[api_key](../README.md#api_key) + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/xml, application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + +# **PetAPI_specialtyPet** +```c +// Specialty of the shop +// +// Returns the kind of pet the store specializes in +// +preference_t* PetAPI_specialtyPet(apiClient_t *apiClient); +``` + +### Parameters +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- +**apiClient** | **apiClient_t \*** | context containing the client configuration | + +### Return type + +[preference_t](preference.md) * + + ### Authorization [api_key](../README.md#api_key) diff --git a/samples/client/petstore/c-useJsonUnformatted/docs/preference.md b/samples/client/petstore/c-useJsonUnformatted/docs/preference.md new file mode 100644 index 0000000000000..ab63d47cb7e8a --- /dev/null +++ b/samples/client/petstore/c-useJsonUnformatted/docs/preference.md @@ -0,0 +1,9 @@ +# preference_t + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/c-useJsonUnformatted/docs/user.md b/samples/client/petstore/c-useJsonUnformatted/docs/user.md index 3b9219c158b5a..22b807f47efa3 100644 --- a/samples/client/petstore/c-useJsonUnformatted/docs/user.md +++ b/samples/client/petstore/c-useJsonUnformatted/docs/user.md @@ -11,6 +11,8 @@ Name | Type | Description | Notes **password** | **char \*** | | [optional] **phone** | **char \*** | | [optional] **user_status** | **int** | User Status | [optional] +**extra** | **list_t*** | | [optional] +**preference** | **preference_t \*** | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/c-useJsonUnformatted/model/preference.c b/samples/client/petstore/c-useJsonUnformatted/model/preference.c new file mode 100644 index 0000000000000..ac7e600fed028 --- /dev/null +++ b/samples/client/petstore/c-useJsonUnformatted/model/preference.c @@ -0,0 +1,47 @@ +#include +#include +#include +#include "preference.h" + + +char* preference_preference_ToString(openapi_petstore_preference__e preference) { + char *preferenceArray[] = { "NULL", "cats", "dogs", "birds", "fish", "snakes", "other" }; + return preferenceArray[preference]; +} + +openapi_petstore_preference__e preference_preference_FromString(char* preference) { + int stringToReturn = 0; + char *preferenceArray[] = { "NULL", "cats", "dogs", "birds", "fish", "snakes", "other" }; + size_t sizeofArray = sizeof(preferenceArray) / sizeof(preferenceArray[0]); + while(stringToReturn < sizeofArray) { + if(strcmp(preference, preferenceArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; + } + return 0; +} + +cJSON *preference_convertToJSON(openapi_petstore_preference__e preference) { + cJSON *item = cJSON_CreateObject(); + if(cJSON_AddStringToObject(item, "preference", preference_preference_ToString(preference)) == NULL) { + goto fail; + } + return item; +fail: + cJSON_Delete(item); + return NULL; +} + +openapi_petstore_preference__e preference_parseFromJSON(cJSON *preferenceJSON) { + openapi_petstore_preference__e *preference = NULL; + openapi_petstore_preference__e preferenceVariable; + cJSON *preferenceVar = cJSON_GetObjectItemCaseSensitive(preferenceJSON, "preference"); + if(!cJSON_IsString(preferenceVar) || (preferenceVar->valuestring == NULL)){ + goto end; + } + preferenceVariable = preference_preference_FromString(preferenceVar->valuestring); + return preferenceVariable; +end: + return 0; +} diff --git a/samples/client/petstore/c-useJsonUnformatted/model/preference.h b/samples/client/petstore/c-useJsonUnformatted/model/preference.h new file mode 100644 index 0000000000000..1f6644f083619 --- /dev/null +++ b/samples/client/petstore/c-useJsonUnformatted/model/preference.h @@ -0,0 +1,32 @@ +/* + * preference.h + * + * A user's preference in pets + */ + +#ifndef _preference_H_ +#define _preference_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" + +typedef struct preference_t preference_t; + + +// Enum for preference + +typedef enum { openapi_petstore_preference__NULL = 0, openapi_petstore_preference__cats, openapi_petstore_preference__dogs, openapi_petstore_preference__birds, openapi_petstore_preference__fish, openapi_petstore_preference__snakes, openapi_petstore_preference__other } openapi_petstore_preference__e; + +char* preference_preference_ToString(openapi_petstore_preference__e preference); + +openapi_petstore_preference__e preference_preference_FromString(char* preference); + +cJSON *preference_convertToJSON(openapi_petstore_preference__e preference); + +openapi_petstore_preference__e preference_parseFromJSON(cJSON *preferenceJSON); + +#endif /* _preference_H_ */ + diff --git a/samples/client/petstore/c-useJsonUnformatted/model/user.c b/samples/client/petstore/c-useJsonUnformatted/model/user.c index eb188153ccf0d..b43d428e1ffa2 100644 --- a/samples/client/petstore/c-useJsonUnformatted/model/user.c +++ b/samples/client/petstore/c-useJsonUnformatted/model/user.c @@ -13,7 +13,9 @@ user_t *user_create( char *email, char *password, char *phone, - int user_status + int user_status, + list_t* extra, + openapi_petstore_preference__e preference ) { user_t *user_local_var = malloc(sizeof(user_t)); if (!user_local_var) { @@ -27,6 +29,8 @@ user_t *user_create( user_local_var->password = password; user_local_var->phone = phone; user_local_var->user_status = user_status; + user_local_var->extra = extra; + user_local_var->preference = preference; return user_local_var; } @@ -61,6 +65,16 @@ void user_free(user_t *user) { free(user->phone); user->phone = NULL; } + if (user->extra) { + list_ForEach(listEntry, user->extra) { + keyValuePair_t *localKeyValue = (keyValuePair_t*) listEntry->data; + free (localKeyValue->key); + free (localKeyValue->value); + keyValuePair_free(localKeyValue); + } + list_freeList(user->extra); + user->extra = NULL; + } free(user); } @@ -130,6 +144,35 @@ cJSON *user_convertToJSON(user_t *user) { } } + + // user->extra + if(user->extra) { + cJSON *extra = cJSON_AddObjectToObject(item, "extra"); + if(extra == NULL) { + goto fail; //primitive map container + } + cJSON *localMapObject = extra; + listEntry_t *extraListEntry; + if (user->extra) { + list_ForEach(extraListEntry, user->extra) { + keyValuePair_t *localKeyValue = (keyValuePair_t*)extraListEntry->data; + } + } + } + + + // user->preference + if(user->preference != openapi_petstore_preference__NULL) { + cJSON *preference_local_JSON = preference_convertToJSON(user->preference); + if(preference_local_JSON == NULL) { + goto fail; // custom + } + cJSON_AddItemToObject(item, "preference", preference_local_JSON); + if(item->child == NULL) { + goto fail; + } + } + return item; fail: if (item) { @@ -142,6 +185,12 @@ user_t *user_parseFromJSON(cJSON *userJSON){ user_t *user_local_var = NULL; + // define the local map for user->extra + list_t *extraList = NULL; + + // define the local variable for user->preference + openapi_petstore_preference__e preference_local_nonprim = 0; + // user->id cJSON *id = cJSON_GetObjectItemCaseSensitive(userJSON, "id"); if (id) { @@ -214,6 +263,32 @@ user_t *user_parseFromJSON(cJSON *userJSON){ } } + // user->extra + cJSON *extra = cJSON_GetObjectItemCaseSensitive(userJSON, "extra"); + if (extra) { + cJSON *extra_local_map = NULL; + if(!cJSON_IsObject(extra) && !cJSON_IsNull(extra)) + { + goto end;//primitive map container + } + if(cJSON_IsObject(extra)) + { + extraList = list_createList(); + keyValuePair_t *localMapKeyPair; + cJSON_ArrayForEach(extra_local_map, extra) + { + cJSON *localMapObject = extra_local_map; + list_addElement(extraList , localMapKeyPair); + } + } + } + + // user->preference + cJSON *preference = cJSON_GetObjectItemCaseSensitive(userJSON, "preference"); + if (preference) { + preference_local_nonprim = preference_parseFromJSON(preference); //custom + } + user_local_var = user_create ( id ? id->valuedouble : 0, @@ -223,11 +298,28 @@ user_t *user_parseFromJSON(cJSON *userJSON){ email && !cJSON_IsNull(email) ? strdup(email->valuestring) : NULL, password && !cJSON_IsNull(password) ? strdup(password->valuestring) : NULL, phone && !cJSON_IsNull(phone) ? strdup(phone->valuestring) : NULL, - user_status ? user_status->valuedouble : 0 + user_status ? user_status->valuedouble : 0, + extra ? extraList : NULL, + preference ? preference_local_nonprim : 0 ); return user_local_var; end: + if (extraList) { + listEntry_t *listEntry = NULL; + list_ForEach(listEntry, extraList) { + keyValuePair_t *localKeyValue = (keyValuePair_t*) listEntry->data; + free(localKeyValue->key); + localKeyValue->key = NULL; + keyValuePair_free(localKeyValue); + localKeyValue = NULL; + } + list_freeList(extraList); + extraList = NULL; + } + if (preference_local_nonprim) { + preference_local_nonprim = 0; + } return NULL; } diff --git a/samples/client/petstore/c-useJsonUnformatted/model/user.h b/samples/client/petstore/c-useJsonUnformatted/model/user.h index 45fa42c3f91c9..badbc747b3089 100644 --- a/samples/client/petstore/c-useJsonUnformatted/model/user.h +++ b/samples/client/petstore/c-useJsonUnformatted/model/user.h @@ -15,6 +15,8 @@ typedef struct user_t user_t; +#include "any_type.h" +#include "preference.h" @@ -27,6 +29,8 @@ typedef struct user_t { char *password; // string char *phone; // string int user_status; //numeric + list_t* extra; //map + openapi_petstore_preference__e preference; //referenced enum } user_t; @@ -38,7 +42,9 @@ user_t *user_create( char *email, char *password, char *phone, - int user_status + int user_status, + list_t* extra, + openapi_petstore_preference__e preference ); void user_free(user_t *user); diff --git a/samples/client/petstore/c-useJsonUnformatted/unit-test/test_preference.c b/samples/client/petstore/c-useJsonUnformatted/unit-test/test_preference.c new file mode 100644 index 0000000000000..96468361f582f --- /dev/null +++ b/samples/client/petstore/c-useJsonUnformatted/unit-test/test_preference.c @@ -0,0 +1,56 @@ +#ifndef preference_TEST +#define preference_TEST + +// the following is to include only the main from the first c file +#ifndef TEST_MAIN +#define TEST_MAIN +#define preference_MAIN +#endif // TEST_MAIN + +#include +#include +#include +#include +#include "../external/cJSON.h" + +#include "../model/preference.h" +preference_t* instantiate_preference(int include_optional); + + + +preference_t* instantiate_preference(int include_optional) { + preference_t* preference = NULL; + if (include_optional) { + preference = preference_create( + ); + } else { + preference = preference_create( + ); + } + + return preference; +} + + +#ifdef preference_MAIN + +void test_preference(int include_optional) { + preference_t* preference_1 = instantiate_preference(include_optional); + + cJSON* jsonpreference_1 = preference_convertToJSON(preference_1); + printf("preference :\n%s\n", cJSON_PrintUnformatted(jsonpreference_1)); + preference_t* preference_2 = preference_parseFromJSON(jsonpreference_1); + cJSON* jsonpreference_2 = preference_convertToJSON(preference_2); + printf("repeating preference:\n%s\n", cJSON_PrintUnformatted(jsonpreference_2)); +} + +int main() { + test_preference(1); + test_preference(0); + + printf("Hello world \n"); + return 0; +} + +#endif // preference_MAIN +#endif // preference_TEST diff --git a/samples/client/petstore/c/.openapi-generator/FILES b/samples/client/petstore/c/.openapi-generator/FILES index 4f6e6397e71e1..eff7ae714342b 100644 --- a/samples/client/petstore/c/.openapi-generator/FILES +++ b/samples/client/petstore/c/.openapi-generator/FILES @@ -15,6 +15,7 @@ docs/category.md docs/model_with_set_propertes.md docs/order.md docs/pet.md +docs/preference.md docs/tag.md docs/user.md external/cJSON.c @@ -40,6 +41,8 @@ model/order.c model/order.h model/pet.c model/pet.h +model/preference.c +model/preference.h model/tag.c model/tag.h model/user.c diff --git a/samples/client/petstore/c/README.md b/samples/client/petstore/c/README.md index a2724768f151c..707999204fbe2 100644 --- a/samples/client/petstore/c/README.md +++ b/samples/client/petstore/c/README.md @@ -70,6 +70,7 @@ Category | Method | HTTP request | Description *PetAPI* | [**PetAPI_findPetsByStatus**](docs/PetAPI.md#PetAPI_findPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status *PetAPI* | [**PetAPI_findPetsByTags**](docs/PetAPI.md#PetAPI_findPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags *PetAPI* | [**PetAPI_getPetById**](docs/PetAPI.md#PetAPI_getPetById) | **GET** /pet/{petId} | Find pet by ID +*PetAPI* | [**PetAPI_specialtyPet**](docs/PetAPI.md#PetAPI_specialtyPet) | **GET** /pet/specialty | Specialty of the shop *PetAPI* | [**PetAPI_updatePet**](docs/PetAPI.md#PetAPI_updatePet) | **PUT** /pet | Update an existing pet *PetAPI* | [**PetAPI_updatePetWithForm**](docs/PetAPI.md#PetAPI_updatePetWithForm) | **POST** /pet/{petId} | Updates a pet in the store with form data *PetAPI* | [**PetAPI_uploadFile**](docs/PetAPI.md#PetAPI_uploadFile) | **POST** /pet/{petId}/uploadImage | uploads an image @@ -96,6 +97,7 @@ Category | Method | HTTP request | Description - [model_with_set_propertes_t](docs/model_with_set_propertes.md) - [order_t](docs/order.md) - [pet_t](docs/pet.md) + - [preference_t](docs/preference.md) - [tag_t](docs/tag.md) - [user_t](docs/user.md) diff --git a/samples/client/petstore/c/api/PetAPI.c b/samples/client/petstore/c/api/PetAPI.c index 36303a0ef5e07..9cf09a2e4ad94 100644 --- a/samples/client/petstore/c/api/PetAPI.c +++ b/samples/client/petstore/c/api/PetAPI.c @@ -460,6 +460,70 @@ PetAPI_getPetById(apiClient_t *apiClient, long petId) } +// Specialty of the shop +// +// Returns the kind of pet the store specializes in +// +openapi_petstore_preference__e +PetAPI_specialtyPet(apiClient_t *apiClient) +{ + list_t *localVarQueryParameters = NULL; + list_t *localVarHeaderParameters = NULL; + list_t *localVarFormParameters = NULL; + list_t *localVarHeaderType = list_createList(); + list_t *localVarContentType = NULL; + char *localVarBodyParameters = NULL; + + // create the path + long sizeOfPath = strlen("/pet/specialty")+1; + char *localVarPath = malloc(sizeOfPath); + snprintf(localVarPath, sizeOfPath, "/pet/specialty"); + + + + list_addElement(localVarHeaderType,"application/xml"); //produces + list_addElement(localVarHeaderType,"application/json"); //produces + apiClient_invoke(apiClient, + localVarPath, + localVarQueryParameters, + localVarHeaderParameters, + localVarFormParameters, + localVarHeaderType, + localVarContentType, + localVarBodyParameters, + "GET"); + + // uncomment below to debug the error response + //if (apiClient->response_code == 200) { + // printf("%s\n","successful operation"); + //} + //nonprimitive not container + cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); + openapi_petstore_preference__e elementToReturn = preference_parseFromJSON(PetAPIlocalVarJSON); + cJSON_Delete(PetAPIlocalVarJSON); + if(elementToReturn == 0) { + // return 0; + } + + //return type + if (apiClient->dataReceived) { + free(apiClient->dataReceived); + apiClient->dataReceived = NULL; + apiClient->dataReceivedLen = 0; + } + + + + list_freeList(localVarHeaderType); + + free(localVarPath); + return elementToReturn; +end: + free(localVarPath); + return 0; + +} + // Update an existing pet // void diff --git a/samples/client/petstore/c/api/PetAPI.h b/samples/client/petstore/c/api/PetAPI.h index 9b5c586fda78b..d33d0394b2d5b 100644 --- a/samples/client/petstore/c/api/PetAPI.h +++ b/samples/client/petstore/c/api/PetAPI.h @@ -7,6 +7,7 @@ #include "../include/binary.h" #include "../model/api_response.h" #include "../model/pet.h" +#include "../model/preference.h" // Enum STATUS for PetAPI_findPetsByStatus typedef enum { openapi_petstore_findPetsByStatus_STATUS_NULL = 0, openapi_petstore_findPetsByStatus_STATUS_available, openapi_petstore_findPetsByStatus_STATUS_pending, openapi_petstore_findPetsByStatus_STATUS_sold } openapi_petstore_findPetsByStatus_status_e; @@ -48,6 +49,14 @@ pet_t* PetAPI_getPetById(apiClient_t *apiClient, long petId); +// Specialty of the shop +// +// Returns the kind of pet the store specializes in +// +openapi_petstore_preference__e +PetAPI_specialtyPet(apiClient_t *apiClient); + + // Update an existing pet // void diff --git a/samples/client/petstore/c/docs/PetAPI.md b/samples/client/petstore/c/docs/PetAPI.md index 392ef4d08a7d9..bcdc9e8e1c362 100644 --- a/samples/client/petstore/c/docs/PetAPI.md +++ b/samples/client/petstore/c/docs/PetAPI.md @@ -9,6 +9,7 @@ Method | HTTP request | Description [**PetAPI_findPetsByStatus**](PetAPI.md#PetAPI_findPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status [**PetAPI_findPetsByTags**](PetAPI.md#PetAPI_findPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags [**PetAPI_getPetById**](PetAPI.md#PetAPI_getPetById) | **GET** /pet/{petId} | Find pet by ID +[**PetAPI_specialtyPet**](PetAPI.md#PetAPI_specialtyPet) | **GET** /pet/specialty | Specialty of the shop [**PetAPI_updatePet**](PetAPI.md#PetAPI_updatePet) | **PUT** /pet | Update an existing pet [**PetAPI_updatePetWithForm**](PetAPI.md#PetAPI_updatePetWithForm) | **POST** /pet/{petId} | Updates a pet in the store with form data [**PetAPI_uploadFile**](PetAPI.md#PetAPI_uploadFile) | **POST** /pet/{petId}/uploadImage | uploads an image @@ -153,6 +154,36 @@ Name | Type | Description | Notes [pet_t](pet.md) * +### Authorization + +[api_key](../README.md#api_key) + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/xml, application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + +# **PetAPI_specialtyPet** +```c +// Specialty of the shop +// +// Returns the kind of pet the store specializes in +// +preference_t* PetAPI_specialtyPet(apiClient_t *apiClient); +``` + +### Parameters +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- +**apiClient** | **apiClient_t \*** | context containing the client configuration | + +### Return type + +[preference_t](preference.md) * + + ### Authorization [api_key](../README.md#api_key) diff --git a/samples/client/petstore/c/docs/preference.md b/samples/client/petstore/c/docs/preference.md new file mode 100644 index 0000000000000..ab63d47cb7e8a --- /dev/null +++ b/samples/client/petstore/c/docs/preference.md @@ -0,0 +1,9 @@ +# preference_t + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/c/docs/user.md b/samples/client/petstore/c/docs/user.md index 3b9219c158b5a..22b807f47efa3 100644 --- a/samples/client/petstore/c/docs/user.md +++ b/samples/client/petstore/c/docs/user.md @@ -11,6 +11,8 @@ Name | Type | Description | Notes **password** | **char \*** | | [optional] **phone** | **char \*** | | [optional] **user_status** | **int** | User Status | [optional] +**extra** | **list_t*** | | [optional] +**preference** | **preference_t \*** | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/c/model/preference.c b/samples/client/petstore/c/model/preference.c new file mode 100644 index 0000000000000..ac7e600fed028 --- /dev/null +++ b/samples/client/petstore/c/model/preference.c @@ -0,0 +1,47 @@ +#include +#include +#include +#include "preference.h" + + +char* preference_preference_ToString(openapi_petstore_preference__e preference) { + char *preferenceArray[] = { "NULL", "cats", "dogs", "birds", "fish", "snakes", "other" }; + return preferenceArray[preference]; +} + +openapi_petstore_preference__e preference_preference_FromString(char* preference) { + int stringToReturn = 0; + char *preferenceArray[] = { "NULL", "cats", "dogs", "birds", "fish", "snakes", "other" }; + size_t sizeofArray = sizeof(preferenceArray) / sizeof(preferenceArray[0]); + while(stringToReturn < sizeofArray) { + if(strcmp(preference, preferenceArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; + } + return 0; +} + +cJSON *preference_convertToJSON(openapi_petstore_preference__e preference) { + cJSON *item = cJSON_CreateObject(); + if(cJSON_AddStringToObject(item, "preference", preference_preference_ToString(preference)) == NULL) { + goto fail; + } + return item; +fail: + cJSON_Delete(item); + return NULL; +} + +openapi_petstore_preference__e preference_parseFromJSON(cJSON *preferenceJSON) { + openapi_petstore_preference__e *preference = NULL; + openapi_petstore_preference__e preferenceVariable; + cJSON *preferenceVar = cJSON_GetObjectItemCaseSensitive(preferenceJSON, "preference"); + if(!cJSON_IsString(preferenceVar) || (preferenceVar->valuestring == NULL)){ + goto end; + } + preferenceVariable = preference_preference_FromString(preferenceVar->valuestring); + return preferenceVariable; +end: + return 0; +} diff --git a/samples/client/petstore/c/model/preference.h b/samples/client/petstore/c/model/preference.h new file mode 100644 index 0000000000000..1f6644f083619 --- /dev/null +++ b/samples/client/petstore/c/model/preference.h @@ -0,0 +1,32 @@ +/* + * preference.h + * + * A user's preference in pets + */ + +#ifndef _preference_H_ +#define _preference_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" + +typedef struct preference_t preference_t; + + +// Enum for preference + +typedef enum { openapi_petstore_preference__NULL = 0, openapi_petstore_preference__cats, openapi_petstore_preference__dogs, openapi_petstore_preference__birds, openapi_petstore_preference__fish, openapi_petstore_preference__snakes, openapi_petstore_preference__other } openapi_petstore_preference__e; + +char* preference_preference_ToString(openapi_petstore_preference__e preference); + +openapi_petstore_preference__e preference_preference_FromString(char* preference); + +cJSON *preference_convertToJSON(openapi_petstore_preference__e preference); + +openapi_petstore_preference__e preference_parseFromJSON(cJSON *preferenceJSON); + +#endif /* _preference_H_ */ + diff --git a/samples/client/petstore/c/model/user.c b/samples/client/petstore/c/model/user.c index eb188153ccf0d..b43d428e1ffa2 100644 --- a/samples/client/petstore/c/model/user.c +++ b/samples/client/petstore/c/model/user.c @@ -13,7 +13,9 @@ user_t *user_create( char *email, char *password, char *phone, - int user_status + int user_status, + list_t* extra, + openapi_petstore_preference__e preference ) { user_t *user_local_var = malloc(sizeof(user_t)); if (!user_local_var) { @@ -27,6 +29,8 @@ user_t *user_create( user_local_var->password = password; user_local_var->phone = phone; user_local_var->user_status = user_status; + user_local_var->extra = extra; + user_local_var->preference = preference; return user_local_var; } @@ -61,6 +65,16 @@ void user_free(user_t *user) { free(user->phone); user->phone = NULL; } + if (user->extra) { + list_ForEach(listEntry, user->extra) { + keyValuePair_t *localKeyValue = (keyValuePair_t*) listEntry->data; + free (localKeyValue->key); + free (localKeyValue->value); + keyValuePair_free(localKeyValue); + } + list_freeList(user->extra); + user->extra = NULL; + } free(user); } @@ -130,6 +144,35 @@ cJSON *user_convertToJSON(user_t *user) { } } + + // user->extra + if(user->extra) { + cJSON *extra = cJSON_AddObjectToObject(item, "extra"); + if(extra == NULL) { + goto fail; //primitive map container + } + cJSON *localMapObject = extra; + listEntry_t *extraListEntry; + if (user->extra) { + list_ForEach(extraListEntry, user->extra) { + keyValuePair_t *localKeyValue = (keyValuePair_t*)extraListEntry->data; + } + } + } + + + // user->preference + if(user->preference != openapi_petstore_preference__NULL) { + cJSON *preference_local_JSON = preference_convertToJSON(user->preference); + if(preference_local_JSON == NULL) { + goto fail; // custom + } + cJSON_AddItemToObject(item, "preference", preference_local_JSON); + if(item->child == NULL) { + goto fail; + } + } + return item; fail: if (item) { @@ -142,6 +185,12 @@ user_t *user_parseFromJSON(cJSON *userJSON){ user_t *user_local_var = NULL; + // define the local map for user->extra + list_t *extraList = NULL; + + // define the local variable for user->preference + openapi_petstore_preference__e preference_local_nonprim = 0; + // user->id cJSON *id = cJSON_GetObjectItemCaseSensitive(userJSON, "id"); if (id) { @@ -214,6 +263,32 @@ user_t *user_parseFromJSON(cJSON *userJSON){ } } + // user->extra + cJSON *extra = cJSON_GetObjectItemCaseSensitive(userJSON, "extra"); + if (extra) { + cJSON *extra_local_map = NULL; + if(!cJSON_IsObject(extra) && !cJSON_IsNull(extra)) + { + goto end;//primitive map container + } + if(cJSON_IsObject(extra)) + { + extraList = list_createList(); + keyValuePair_t *localMapKeyPair; + cJSON_ArrayForEach(extra_local_map, extra) + { + cJSON *localMapObject = extra_local_map; + list_addElement(extraList , localMapKeyPair); + } + } + } + + // user->preference + cJSON *preference = cJSON_GetObjectItemCaseSensitive(userJSON, "preference"); + if (preference) { + preference_local_nonprim = preference_parseFromJSON(preference); //custom + } + user_local_var = user_create ( id ? id->valuedouble : 0, @@ -223,11 +298,28 @@ user_t *user_parseFromJSON(cJSON *userJSON){ email && !cJSON_IsNull(email) ? strdup(email->valuestring) : NULL, password && !cJSON_IsNull(password) ? strdup(password->valuestring) : NULL, phone && !cJSON_IsNull(phone) ? strdup(phone->valuestring) : NULL, - user_status ? user_status->valuedouble : 0 + user_status ? user_status->valuedouble : 0, + extra ? extraList : NULL, + preference ? preference_local_nonprim : 0 ); return user_local_var; end: + if (extraList) { + listEntry_t *listEntry = NULL; + list_ForEach(listEntry, extraList) { + keyValuePair_t *localKeyValue = (keyValuePair_t*) listEntry->data; + free(localKeyValue->key); + localKeyValue->key = NULL; + keyValuePair_free(localKeyValue); + localKeyValue = NULL; + } + list_freeList(extraList); + extraList = NULL; + } + if (preference_local_nonprim) { + preference_local_nonprim = 0; + } return NULL; } diff --git a/samples/client/petstore/c/model/user.h b/samples/client/petstore/c/model/user.h index 45fa42c3f91c9..badbc747b3089 100644 --- a/samples/client/petstore/c/model/user.h +++ b/samples/client/petstore/c/model/user.h @@ -15,6 +15,8 @@ typedef struct user_t user_t; +#include "any_type.h" +#include "preference.h" @@ -27,6 +29,8 @@ typedef struct user_t { char *password; // string char *phone; // string int user_status; //numeric + list_t* extra; //map + openapi_petstore_preference__e preference; //referenced enum } user_t; @@ -38,7 +42,9 @@ user_t *user_create( char *email, char *password, char *phone, - int user_status + int user_status, + list_t* extra, + openapi_petstore_preference__e preference ); void user_free(user_t *user); diff --git a/samples/client/petstore/c/unit-test/test_preference.c b/samples/client/petstore/c/unit-test/test_preference.c new file mode 100644 index 0000000000000..8b1e2163fb345 --- /dev/null +++ b/samples/client/petstore/c/unit-test/test_preference.c @@ -0,0 +1,56 @@ +#ifndef preference_TEST +#define preference_TEST + +// the following is to include only the main from the first c file +#ifndef TEST_MAIN +#define TEST_MAIN +#define preference_MAIN +#endif // TEST_MAIN + +#include +#include +#include +#include +#include "../external/cJSON.h" + +#include "../model/preference.h" +preference_t* instantiate_preference(int include_optional); + + + +preference_t* instantiate_preference(int include_optional) { + preference_t* preference = NULL; + if (include_optional) { + preference = preference_create( + ); + } else { + preference = preference_create( + ); + } + + return preference; +} + + +#ifdef preference_MAIN + +void test_preference(int include_optional) { + preference_t* preference_1 = instantiate_preference(include_optional); + + cJSON* jsonpreference_1 = preference_convertToJSON(preference_1); + printf("preference :\n%s\n", cJSON_Print(jsonpreference_1)); + preference_t* preference_2 = preference_parseFromJSON(jsonpreference_1); + cJSON* jsonpreference_2 = preference_convertToJSON(preference_2); + printf("repeating preference:\n%s\n", cJSON_Print(jsonpreference_2)); +} + +int main() { + test_preference(1); + test_preference(0); + + printf("Hello world \n"); + return 0; +} + +#endif // preference_MAIN +#endif // preference_TEST From e3e06af5f4af3e0ac96ee2aa822fe8efe3ead529 Mon Sep 17 00:00:00 2001 From: Matt Pollock Date: Thu, 28 Nov 2024 03:31:21 -0500 Subject: [PATCH 08/12] [R] fix to-list and to-json functionality (#20132) * [r client] fix to-list and to-json functionality * fix type of json string * wip * refactor pr * regenerate samples * update to-dataframe example to use non-superceded tidyverse functions * fix typo --- .../src/main/resources/r/api.mustache | 2 +- .../src/main/resources/r/modelAnyOf.mustache | 29 +-- .../src/main/resources/r/modelEnum.mustache | 22 ++- .../main/resources/r/modelGeneric.mustache | 111 ++++-------- .../src/main/resources/r/modelOneOf.mustache | 28 ++- samples/client/echo_api/r/R/bird.R | 61 ++++--- samples/client/echo_api/r/R/body_api.R | 14 +- samples/client/echo_api/r/R/category.R | 61 ++++--- samples/client/echo_api/r/R/data_query.R | 85 ++++----- samples/client/echo_api/r/R/default_value.R | 111 ++++-------- .../echo_api/r/R/number_properties_only.R | 69 +++---- samples/client/echo_api/r/R/pet.R | 97 ++++------ samples/client/echo_api/r/R/query.R | 61 ++++--- samples/client/echo_api/r/R/string_enum_ref.R | 22 ++- samples/client/echo_api/r/R/tag.R | 61 ++++--- ...est_form_object_multipart_request_marker.R | 53 ++++-- ...rue_object_all_of_query_object_parameter.R | 77 ++++---- ...true_array_string_query_object_parameter.R | 53 ++++-- .../R/allof_tag_api_response.R | 89 ++++----- .../petstore/R-httr2-wrapper/R/animal.R | 65 ++++--- .../petstore/R-httr2-wrapper/R/any_of_pig.R | 29 +-- .../R/any_of_primitive_type_test.R | 28 ++- .../petstore/R-httr2-wrapper/R/basque_pig.R | 65 ++++--- .../client/petstore/R-httr2-wrapper/R/cat.R | 73 ++++---- .../petstore/R-httr2-wrapper/R/category.R | 65 ++++--- .../petstore/R-httr2-wrapper/R/danish_pig.R | 65 ++++--- .../client/petstore/R-httr2-wrapper/R/date.R | 73 ++++---- .../client/petstore/R-httr2-wrapper/R/dog.R | 73 ++++---- .../petstore/R-httr2-wrapper/R/dummy_model.R | 57 +++--- .../petstore/R-httr2-wrapper/R/fake_api.R | 2 +- .../petstore/R-httr2-wrapper/R/format_test.R | 169 ++++-------------- .../petstore/R-httr2-wrapper/R/mammal.R | 28 ++- .../R-httr2-wrapper/R/model_api_response.R | 73 ++++---- .../R-httr2-wrapper/R/nested_one_of.R | 67 +++---- .../R/one_of_primitive_type_test.R | 28 ++- .../client/petstore/R-httr2-wrapper/R/order.R | 97 ++++------ .../client/petstore/R-httr2-wrapper/R/pet.R | 101 ++++------- .../petstore/R-httr2-wrapper/R/pet_api.R | 4 +- .../petstore/R-httr2-wrapper/R/pet_map.R | 57 +++--- .../client/petstore/R-httr2-wrapper/R/pig.R | 28 ++- .../petstore/R-httr2-wrapper/R/special.R | 105 ++++------- .../petstore/R-httr2-wrapper/R/store_api.R | 2 +- .../client/petstore/R-httr2-wrapper/R/tag.R | 65 ++++--- .../R-httr2-wrapper/R/update_pet_request.R | 67 +++---- .../client/petstore/R-httr2-wrapper/R/user.R | 113 ++++-------- .../petstore/R-httr2-wrapper/R/user_api.R | 8 +- .../client/petstore/R-httr2-wrapper/R/whale.R | 73 ++++---- .../client/petstore/R-httr2-wrapper/R/zebra.R | 65 ++++--- .../tests/testthat/test_petstore.R | 6 +- .../R-httr2/R/allof_tag_api_response.R | 85 ++++----- samples/client/petstore/R-httr2/R/animal.R | 61 ++++--- .../client/petstore/R-httr2/R/any_of_pig.R | 29 +-- .../R-httr2/R/any_of_primitive_type_test.R | 28 ++- .../client/petstore/R-httr2/R/basque_pig.R | 61 ++++--- samples/client/petstore/R-httr2/R/cat.R | 69 +++---- samples/client/petstore/R-httr2/R/category.R | 61 ++++--- .../client/petstore/R-httr2/R/danish_pig.R | 61 ++++--- samples/client/petstore/R-httr2/R/date.R | 69 +++---- samples/client/petstore/R-httr2/R/dog.R | 69 +++---- samples/client/petstore/R-httr2/R/fake_api.R | 2 +- .../client/petstore/R-httr2/R/format_test.R | 165 ++++------------- .../client/petstore/R-httr2/R/just_model.R | 53 ++++-- samples/client/petstore/R-httr2/R/mammal.R | 28 ++- .../petstore/R-httr2/R/model_api_response.R | 69 +++---- .../client/petstore/R-httr2/R/nested_one_of.R | 63 ++++--- .../R-httr2/R/one_of_primitive_type_test.R | 28 ++- samples/client/petstore/R-httr2/R/order.R | 93 ++++------ samples/client/petstore/R-httr2/R/pet.R | 97 ++++------ samples/client/petstore/R-httr2/R/pet_api.R | 4 +- samples/client/petstore/R-httr2/R/pet_map.R | 53 ++++-- samples/client/petstore/R-httr2/R/pig.R | 28 ++- samples/client/petstore/R-httr2/R/special.R | 101 ++++------- samples/client/petstore/R-httr2/R/store_api.R | 2 +- samples/client/petstore/R-httr2/R/tag.R | 61 ++++--- .../petstore/R-httr2/R/update_pet_request.R | 63 ++++--- samples/client/petstore/R-httr2/R/user.R | 109 ++++------- samples/client/petstore/R-httr2/R/user_api.R | 8 +- samples/client/petstore/R-httr2/R/whale.R | 69 +++---- samples/client/petstore/R-httr2/R/zebra.R | 61 ++++--- .../R-httr2/tests/testthat/test_petstore.R | 6 +- .../petstore/R/R/allof_tag_api_response.R | 89 ++++----- samples/client/petstore/R/R/animal.R | 65 ++++--- samples/client/petstore/R/R/any_of_pig.R | 29 +-- .../petstore/R/R/any_of_primitive_type_test.R | 28 ++- samples/client/petstore/R/R/basque_pig.R | 65 ++++--- samples/client/petstore/R/R/cat.R | 73 ++++---- samples/client/petstore/R/R/category.R | 65 ++++--- samples/client/petstore/R/R/danish_pig.R | 65 ++++--- samples/client/petstore/R/R/date.R | 73 ++++---- samples/client/petstore/R/R/dog.R | 73 ++++---- samples/client/petstore/R/R/dummy_model.R | 57 +++--- samples/client/petstore/R/R/fake_api.R | 2 +- samples/client/petstore/R/R/format_test.R | 169 ++++-------------- samples/client/petstore/R/R/mammal.R | 28 ++- .../client/petstore/R/R/model_api_response.R | 73 ++++---- samples/client/petstore/R/R/nested_one_of.R | 67 +++---- .../petstore/R/R/one_of_primitive_type_test.R | 28 ++- samples/client/petstore/R/R/order.R | 97 ++++------ samples/client/petstore/R/R/pet.R | 101 ++++------- samples/client/petstore/R/R/pet_api.R | 4 +- samples/client/petstore/R/R/pet_map.R | 57 +++--- samples/client/petstore/R/R/pig.R | 28 ++- samples/client/petstore/R/R/special.R | 105 ++++------- samples/client/petstore/R/R/store_api.R | 2 +- samples/client/petstore/R/R/tag.R | 65 ++++--- .../client/petstore/R/R/update_pet_request.R | 67 +++---- samples/client/petstore/R/R/user.R | 113 ++++-------- samples/client/petstore/R/R/user_api.R | 8 +- samples/client/petstore/R/R/whale.R | 73 ++++---- samples/client/petstore/R/R/zebra.R | 65 ++++--- .../petstore/R/tests/testthat/test_petstore.R | 6 +- 111 files changed, 3072 insertions(+), 3381 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/r/api.mustache b/modules/openapi-generator/src/main/resources/r/api.mustache index 2895328c09c9a..4f18c214f11a0 100644 --- a/modules/openapi-generator/src/main/resources/r/api.mustache +++ b/modules/openapi-generator/src/main/resources/r/api.mustache @@ -456,7 +456,7 @@ local_var_body <- `{{paramName}}`$toJSONString() {{/isArray}} } else { - body <- NULL + local_var_body <- NULL } {{/bodyParams}} diff --git a/modules/openapi-generator/src/main/resources/r/modelAnyOf.mustache b/modules/openapi-generator/src/main/resources/r/modelAnyOf.mustache index 62e6dd7e41c17..1cdb306be667e 100644 --- a/modules/openapi-generator/src/main/resources/r/modelAnyOf.mustache +++ b/modules/openapi-generator/src/main/resources/r/modelAnyOf.mustache @@ -86,27 +86,32 @@ }, #' @description - #' Serialize {{{classname}}} to JSON string. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. + toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert {{{classname}}} to a base R type #' - #' @return JSON string representation of the {{{classname}}}. - toJSONString = function() { + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify((self$actual_instance$toJSONString()))) + return(self$actual_instance$toSimpleType()) } else { NULL } }, #' @description - #' Serialize {{{classname}}} to JSON. + #' Serialize {{{classname}}} to JSON string. #' - #' @return JSON representation of the {{{classname}}}. - toJSON = function() { - if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() - } else { - NULL - } + #' @param ... Parameters passed to `jsonlite::toJSON` + #' @return JSON string representation of the {{{classname}}}. + toJSONString = function(...) { + json <- jsonlite::toJSON(self$toSimpleType(), auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/modules/openapi-generator/src/main/resources/r/modelEnum.mustache b/modules/openapi-generator/src/main/resources/r/modelEnum.mustache index 64d136449be16..c0dc60149aa12 100644 --- a/modules/openapi-generator/src/main/resources/r/modelEnum.mustache +++ b/modules/openapi-generator/src/main/resources/r/modelEnum.mustache @@ -38,11 +38,18 @@ }, #' @description - #' To JSON String - #' - #' @return {{{classname}}} in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { - jsonlite::toJSON(private$value, auto_unbox = TRUE) + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert {{{classname}}} to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { + return(private$value) }, #' @description @@ -60,10 +67,11 @@ #' @description #' To JSON String #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return {{{classname}}} in JSON format - toJSONString = function() { - as.character(jsonlite::toJSON(private$value, - auto_unbox = TRUE)) + toJSONString = function(...) { + json <- jsonlite::toJSON(self$toSimpleType(), auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/modules/openapi-generator/src/main/resources/r/modelGeneric.mustache b/modules/openapi-generator/src/main/resources/r/modelGeneric.mustache index 24f0ddf8c8f00..0da6607925aa5 100644 --- a/modules/openapi-generator/src/main/resources/r/modelGeneric.mustache +++ b/modules/openapi-generator/src/main/resources/r/modelGeneric.mustache @@ -203,10 +203,35 @@ }, #' @description - #' To JSON String - #' - #' @return {{{classname}}} in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return {{{classname}}} as a base R list. + #' @examples + #' # convert array of {{{classname}}} (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert {{{classname}}} to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { {{classname}}Object <- list() {{#vars}} if (!is.null(self$`{{name}}`)) { @@ -217,7 +242,7 @@ self$`{{name}}` {{/isPrimitiveType}} {{^isPrimitiveType}} - lapply(self$`{{name}}`, function(x) x$toJSON()) + lapply(self$`{{name}}`, function(x) x$toSimpleType()) {{/isPrimitiveType}} {{/isArray}} {{#isMap}} @@ -225,7 +250,7 @@ self$`{{name}}` {{/isPrimitiveType}} {{^isPrimitiveType}} - lapply(self$`{{name}}`, function(x) x$toJSON()) + lapply(self$`{{name}}`, function(x) x$toSimpleType()) {{/isPrimitiveType}} {{/isMap}} {{/isContainer}} @@ -234,7 +259,7 @@ self$`{{name}}` {{/isPrimitiveType}} {{^isPrimitiveType}} - self$`{{name}}`$toJSON() + self$`{{name}}`$toSimpleType() {{/isPrimitiveType}} {{/isContainer}} } @@ -245,7 +270,7 @@ } {{/isAdditionalPropertiesTrue}} - {{classname}}Object + return({{classname}}Object) }, #' @description @@ -304,76 +329,18 @@ #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return {{{classname}}} in JSON format - toJSONString = function() { - jsoncontent <- c( - {{#vars}} - if (!is.null(self$`{{name}}`)) { - sprintf( - '"{{baseName}}": - {{#isContainer}} - {{#isArray}} - {{#isPrimitiveType}} - {{#isNumeric}}[%d]{{/isNumeric}}{{^isNumeric}}[%s]{{/isNumeric}} - {{/isPrimitiveType}} - {{^isPrimitiveType}}[%s] - {{/isPrimitiveType}} - {{/isArray}} - {{#isMap}} - {{#isPrimitiveType}} - {{#isNumeric}}%d{{/isNumeric}}{{^isNumeric}}{{^isBoolean}}{{/isBoolean}}%s{{^isBoolean}}{{/isBoolean}}{{/isNumeric}} - {{/isPrimitiveType}} - {{^isPrimitiveType}}%s - {{/isPrimitiveType}} - {{/isMap}} - {{/isContainer}} - {{^isContainer}} - {{#isPrimitiveType}} - {{#isNumeric}}%d{{/isNumeric}}{{^isNumeric}}{{^isBoolean}}"{{/isBoolean}}%s{{^isBoolean}}"{{/isBoolean}}{{/isNumeric}} - {{/isPrimitiveType}} - {{^isPrimitiveType}}%s - {{/isPrimitiveType}} - {{/isContainer}}', - {{#isContainer}} - {{#isArray}} - {{#isPrimitiveType}} - paste(unlist(lapply(self$`{{{name}}}`, function(x) paste0('"', x, '"'))), collapse = ",") - {{/isPrimitiveType}} - {{^isPrimitiveType}} - paste(sapply(self$`{{{name}}}`, function(x) jsonlite::toJSON(x$toJSON(), auto_unbox = TRUE, digits = NA)), collapse = ",") - {{/isPrimitiveType}} - {{/isArray}} - {{#isMap}} - {{#isPrimitiveType}} - jsonlite::toJSON(lapply(self$`{{{name}}}`, function(x){ x }), auto_unbox = TRUE, digits = NA) - {{/isPrimitiveType}} - {{^isPrimitiveType}} - jsonlite::toJSON(lapply(self$`{{{name}}}`, function(x){ x$toJSON() }), auto_unbox = TRUE, digits = NA) - {{/isPrimitiveType}} - {{/isMap}} - {{/isContainer}} - {{^isContainer}} - {{#isPrimitiveType}} - {{#isBoolean}}tolower({{/isBoolean}}self$`{{name}}`{{#isBoolean}}){{/isBoolean}} - {{/isPrimitiveType}} - {{^isPrimitiveType}} - jsonlite::toJSON(self$`{{name}}`$toJSON(), auto_unbox = TRUE, digits = NA) - {{/isPrimitiveType}} - {{/isContainer}} - ) - }{{^-last}},{{/-last}} - {{/vars}} - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() {{#isAdditionalPropertiesTrue}} - json_obj <- jsonlite::fromJSON(json_string) for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) {{/isAdditionalPropertiesTrue}} + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/modules/openapi-generator/src/main/resources/r/modelOneOf.mustache b/modules/openapi-generator/src/main/resources/r/modelOneOf.mustache index 4fe94c4ad0432..998687b5efb54 100644 --- a/modules/openapi-generator/src/main/resources/r/modelOneOf.mustache +++ b/modules/openapi-generator/src/main/resources/r/modelOneOf.mustache @@ -139,25 +139,35 @@ #' @description #' Serialize {{{classname}}} to JSON string. - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return JSON string representation of the {{{classname}}}. - toJSONString = function() { + toJSONString = function(...) { + simple <- self$toSimpleType() if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify(self$actual_instance$toJSONString())) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) } else { - NULL + return(NULL) } }, #' @description - #' Serialize {{{classname}}} to JSON. - #' - #' @return JSON representation of the {{{classname}}}. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert {{{classname}}} to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() + return(self$actual_instance$toSimpleType()) } else { - NULL + return(NULL) } }, diff --git a/samples/client/echo_api/r/R/bird.R b/samples/client/echo_api/r/R/bird.R index 5132beb3788c8..97921b1c4c894 100644 --- a/samples/client/echo_api/r/R/bird.R +++ b/samples/client/echo_api/r/R/bird.R @@ -40,10 +40,35 @@ Bird <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Bird in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Bird as a base R list. + #' @examples + #' # convert array of Bird (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Bird to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { BirdObject <- list() if (!is.null(self$`size`)) { BirdObject[["size"]] <- @@ -53,7 +78,7 @@ Bird <- R6::R6Class( BirdObject[["color"]] <- self$`color` } - BirdObject + return(BirdObject) }, #' @description @@ -74,29 +99,13 @@ Bird <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Bird in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`size`)) { - sprintf( - '"size": - "%s" - ', - self$`size` - ) - }, - if (!is.null(self$`color`)) { - sprintf( - '"color": - "%s" - ', - self$`color` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/echo_api/r/R/body_api.R b/samples/client/echo_api/r/R/body_api.R index 1be1cafba8b4e..9f16d197edc04 100644 --- a/samples/client/echo_api/r/R/body_api.R +++ b/samples/client/echo_api/r/R/body_api.R @@ -304,7 +304,7 @@ BodyApi <- R6::R6Class( if (!is.null(`body`)) { local_var_body <- `body`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/body/application/octetstream/binary" @@ -586,7 +586,7 @@ BodyApi <- R6::R6Class( if (!is.null(`pet`)) { local_var_body <- `pet`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/echo/body/allOf/Pet" @@ -682,7 +682,7 @@ BodyApi <- R6::R6Class( if (!is.null(`body`)) { local_var_body <- `body`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/echo/body/FreeFormObject/response_string" @@ -778,7 +778,7 @@ BodyApi <- R6::R6Class( if (!is.null(`pet`)) { local_var_body <- `pet`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/echo/body/Pet" @@ -874,7 +874,7 @@ BodyApi <- R6::R6Class( if (!is.null(`pet`)) { local_var_body <- `pet`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/echo/body/Pet/response_string" @@ -970,7 +970,7 @@ BodyApi <- R6::R6Class( if (!is.null(`body`)) { local_var_body <- `body`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/echo/body/string_enum" @@ -1066,7 +1066,7 @@ BodyApi <- R6::R6Class( if (!is.null(`tag`)) { local_var_body <- `tag`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/echo/body/Tag/response_string" diff --git a/samples/client/echo_api/r/R/category.R b/samples/client/echo_api/r/R/category.R index cbf3a88b9ddc8..56aa69671774e 100644 --- a/samples/client/echo_api/r/R/category.R +++ b/samples/client/echo_api/r/R/category.R @@ -40,10 +40,35 @@ Category <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Category in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Category as a base R list. + #' @examples + #' # convert array of Category (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Category to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { CategoryObject <- list() if (!is.null(self$`id`)) { CategoryObject[["id"]] <- @@ -53,7 +78,7 @@ Category <- R6::R6Class( CategoryObject[["name"]] <- self$`name` } - CategoryObject + return(CategoryObject) }, #' @description @@ -74,29 +99,13 @@ Category <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Category in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/echo_api/r/R/data_query.R b/samples/client/echo_api/r/R/data_query.R index edc0bcda0a726..1340544416d08 100644 --- a/samples/client/echo_api/r/R/data_query.R +++ b/samples/client/echo_api/r/R/data_query.R @@ -67,10 +67,35 @@ DataQuery <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return DataQuery in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return DataQuery as a base R list. + #' @examples + #' # convert array of DataQuery (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert DataQuery to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { DataQueryObject <- list() if (!is.null(self$`id`)) { DataQueryObject[["id"]] <- @@ -92,7 +117,7 @@ DataQuery <- R6::R6Class( DataQueryObject[["date"]] <- self$`date` } - DataQueryObject + return(DataQueryObject) }, #' @description @@ -122,53 +147,13 @@ DataQuery <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return DataQuery in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`outcomes`)) { - sprintf( - '"outcomes": - [%s] - ', - paste(unlist(lapply(self$`outcomes`, function(x) paste0('"', x, '"'))), collapse = ",") - ) - }, - if (!is.null(self$`suffix`)) { - sprintf( - '"suffix": - "%s" - ', - self$`suffix` - ) - }, - if (!is.null(self$`text`)) { - sprintf( - '"text": - "%s" - ', - self$`text` - ) - }, - if (!is.null(self$`date`)) { - sprintf( - '"date": - "%s" - ', - self$`date` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/echo_api/r/R/default_value.R b/samples/client/echo_api/r/R/default_value.R index 4456d7fcea03b..2a3a83f326555 100644 --- a/samples/client/echo_api/r/R/default_value.R +++ b/samples/client/echo_api/r/R/default_value.R @@ -87,14 +87,39 @@ DefaultValue <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return DefaultValue in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return DefaultValue as a base R list. + #' @examples + #' # convert array of DefaultValue (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert DefaultValue to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { DefaultValueObject <- list() if (!is.null(self$`array_string_enum_ref_default`)) { DefaultValueObject[["array_string_enum_ref_default"]] <- - lapply(self$`array_string_enum_ref_default`, function(x) x$toJSON()) + lapply(self$`array_string_enum_ref_default`, function(x) x$toSimpleType()) } if (!is.null(self$`array_string_enum_default`)) { DefaultValueObject[["array_string_enum_default"]] <- @@ -124,7 +149,7 @@ DefaultValue <- R6::R6Class( DefaultValueObject[["string_nullable"]] <- self$`string_nullable` } - DefaultValueObject + return(DefaultValueObject) }, #' @description @@ -163,77 +188,13 @@ DefaultValue <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return DefaultValue in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`array_string_enum_ref_default`)) { - sprintf( - '"array_string_enum_ref_default": - [%s] -', - paste(sapply(self$`array_string_enum_ref_default`, function(x) jsonlite::toJSON(x$toJSON(), auto_unbox = TRUE, digits = NA)), collapse = ",") - ) - }, - if (!is.null(self$`array_string_enum_default`)) { - sprintf( - '"array_string_enum_default": - [%s] - ', - paste(unlist(lapply(self$`array_string_enum_default`, function(x) paste0('"', x, '"'))), collapse = ",") - ) - }, - if (!is.null(self$`array_string_default`)) { - sprintf( - '"array_string_default": - [%s] - ', - paste(unlist(lapply(self$`array_string_default`, function(x) paste0('"', x, '"'))), collapse = ",") - ) - }, - if (!is.null(self$`array_integer_default`)) { - sprintf( - '"array_integer_default": - [%s] - ', - paste(unlist(lapply(self$`array_integer_default`, function(x) paste0('"', x, '"'))), collapse = ",") - ) - }, - if (!is.null(self$`array_string`)) { - sprintf( - '"array_string": - [%s] - ', - paste(unlist(lapply(self$`array_string`, function(x) paste0('"', x, '"'))), collapse = ",") - ) - }, - if (!is.null(self$`array_string_nullable`)) { - sprintf( - '"array_string_nullable": - [%s] - ', - paste(unlist(lapply(self$`array_string_nullable`, function(x) paste0('"', x, '"'))), collapse = ",") - ) - }, - if (!is.null(self$`array_string_extension_nullable`)) { - sprintf( - '"array_string_extension_nullable": - [%s] - ', - paste(unlist(lapply(self$`array_string_extension_nullable`, function(x) paste0('"', x, '"'))), collapse = ",") - ) - }, - if (!is.null(self$`string_nullable`)) { - sprintf( - '"string_nullable": - "%s" - ', - self$`string_nullable` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/echo_api/r/R/number_properties_only.R b/samples/client/echo_api/r/R/number_properties_only.R index 7b0b698630fd9..7b146800ad342 100644 --- a/samples/client/echo_api/r/R/number_properties_only.R +++ b/samples/client/echo_api/r/R/number_properties_only.R @@ -46,10 +46,35 @@ NumberPropertiesOnly <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return NumberPropertiesOnly in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return NumberPropertiesOnly as a base R list. + #' @examples + #' # convert array of NumberPropertiesOnly (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert NumberPropertiesOnly to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { NumberPropertiesOnlyObject <- list() if (!is.null(self$`number`)) { NumberPropertiesOnlyObject[["number"]] <- @@ -63,7 +88,7 @@ NumberPropertiesOnly <- R6::R6Class( NumberPropertiesOnlyObject[["double"]] <- self$`double` } - NumberPropertiesOnlyObject + return(NumberPropertiesOnlyObject) }, #' @description @@ -87,37 +112,13 @@ NumberPropertiesOnly <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return NumberPropertiesOnly in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`number`)) { - sprintf( - '"number": - %d - ', - self$`number` - ) - }, - if (!is.null(self$`float`)) { - sprintf( - '"float": - %d - ', - self$`float` - ) - }, - if (!is.null(self$`double`)) { - sprintf( - '"double": - %d - ', - self$`double` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/echo_api/r/R/pet.R b/samples/client/echo_api/r/R/pet.R index b03d04e66cd67..6f59d7ea1f6cd 100644 --- a/samples/client/echo_api/r/R/pet.R +++ b/samples/client/echo_api/r/R/pet.R @@ -75,10 +75,35 @@ Pet <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Pet in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Pet as a base R list. + #' @examples + #' # convert array of Pet (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Pet to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { PetObject <- list() if (!is.null(self$`id`)) { PetObject[["id"]] <- @@ -90,7 +115,7 @@ Pet <- R6::R6Class( } if (!is.null(self$`category`)) { PetObject[["category"]] <- - self$`category`$toJSON() + self$`category`$toSimpleType() } if (!is.null(self$`photoUrls`)) { PetObject[["photoUrls"]] <- @@ -98,13 +123,13 @@ Pet <- R6::R6Class( } if (!is.null(self$`tags`)) { PetObject[["tags"]] <- - lapply(self$`tags`, function(x) x$toJSON()) + lapply(self$`tags`, function(x) x$toSimpleType()) } if (!is.null(self$`status`)) { PetObject[["status"]] <- self$`status` } - PetObject + return(PetObject) }, #' @description @@ -142,61 +167,13 @@ Pet <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Pet in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - }, - if (!is.null(self$`category`)) { - sprintf( - '"category": - %s - ', - jsonlite::toJSON(self$`category`$toJSON(), auto_unbox = TRUE, digits = NA) - ) - }, - if (!is.null(self$`photoUrls`)) { - sprintf( - '"photoUrls": - [%s] - ', - paste(unlist(lapply(self$`photoUrls`, function(x) paste0('"', x, '"'))), collapse = ",") - ) - }, - if (!is.null(self$`tags`)) { - sprintf( - '"tags": - [%s] -', - paste(sapply(self$`tags`, function(x) jsonlite::toJSON(x$toJSON(), auto_unbox = TRUE, digits = NA)), collapse = ",") - ) - }, - if (!is.null(self$`status`)) { - sprintf( - '"status": - "%s" - ', - self$`status` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/echo_api/r/R/query.R b/samples/client/echo_api/r/R/query.R index 527a97226b1d2..fd286ab3016d2 100644 --- a/samples/client/echo_api/r/R/query.R +++ b/samples/client/echo_api/r/R/query.R @@ -39,10 +39,35 @@ Query <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Query in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Query as a base R list. + #' @examples + #' # convert array of Query (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Query to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { QueryObject <- list() if (!is.null(self$`id`)) { QueryObject[["id"]] <- @@ -52,7 +77,7 @@ Query <- R6::R6Class( QueryObject[["outcomes"]] <- self$`outcomes` } - QueryObject + return(QueryObject) }, #' @description @@ -73,29 +98,13 @@ Query <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Query in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`outcomes`)) { - sprintf( - '"outcomes": - [%s] - ', - paste(unlist(lapply(self$`outcomes`, function(x) paste0('"', x, '"'))), collapse = ",") - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/echo_api/r/R/string_enum_ref.R b/samples/client/echo_api/r/R/string_enum_ref.R index 1be463a16552b..ee9afe6cf4a17 100644 --- a/samples/client/echo_api/r/R/string_enum_ref.R +++ b/samples/client/echo_api/r/R/string_enum_ref.R @@ -37,11 +37,18 @@ StringEnumRef <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return StringEnumRef in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { - jsonlite::toJSON(private$value, auto_unbox = TRUE) + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert StringEnumRef to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { + return(private$value) }, #' @description @@ -59,10 +66,11 @@ StringEnumRef <- R6::R6Class( #' @description #' To JSON String #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return StringEnumRef in JSON format - toJSONString = function() { - as.character(jsonlite::toJSON(private$value, - auto_unbox = TRUE)) + toJSONString = function(...) { + json <- jsonlite::toJSON(self$toSimpleType(), auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/echo_api/r/R/tag.R b/samples/client/echo_api/r/R/tag.R index b23305a43afc0..3a0d3c1d23909 100644 --- a/samples/client/echo_api/r/R/tag.R +++ b/samples/client/echo_api/r/R/tag.R @@ -40,10 +40,35 @@ Tag <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Tag in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Tag as a base R list. + #' @examples + #' # convert array of Tag (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Tag to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { TagObject <- list() if (!is.null(self$`id`)) { TagObject[["id"]] <- @@ -53,7 +78,7 @@ Tag <- R6::R6Class( TagObject[["name"]] <- self$`name` } - TagObject + return(TagObject) }, #' @description @@ -74,29 +99,13 @@ Tag <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Tag in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/echo_api/r/R/test_form_object_multipart_request_marker.R b/samples/client/echo_api/r/R/test_form_object_multipart_request_marker.R index 6c523622cde04..5c9776f78ebe3 100644 --- a/samples/client/echo_api/r/R/test_form_object_multipart_request_marker.R +++ b/samples/client/echo_api/r/R/test_form_object_multipart_request_marker.R @@ -31,16 +31,41 @@ TestFormObjectMultipartRequestMarker <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return TestFormObjectMultipartRequestMarker in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return TestFormObjectMultipartRequestMarker as a base R list. + #' @examples + #' # convert array of TestFormObjectMultipartRequestMarker (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert TestFormObjectMultipartRequestMarker to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { TestFormObjectMultipartRequestMarkerObject <- list() if (!is.null(self$`name`)) { TestFormObjectMultipartRequestMarkerObject[["name"]] <- self$`name` } - TestFormObjectMultipartRequestMarkerObject + return(TestFormObjectMultipartRequestMarkerObject) }, #' @description @@ -58,21 +83,13 @@ TestFormObjectMultipartRequestMarker <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return TestFormObjectMultipartRequestMarker in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/echo_api/r/R/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.R b/samples/client/echo_api/r/R/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.R index 8616e605bf931..a441c20a8be36 100644 --- a/samples/client/echo_api/r/R/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.R +++ b/samples/client/echo_api/r/R/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.R @@ -58,10 +58,35 @@ TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter <- R6::R6Clas }, #' @description - #' To JSON String - #' - #' @return TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter as a base R list. + #' @examples + #' # convert array of TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameterObject <- list() if (!is.null(self$`size`)) { TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameterObject[["size"]] <- @@ -79,7 +104,7 @@ TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter <- R6::R6Clas TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameterObject[["name"]] <- self$`name` } - TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameterObject + return(TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameterObject) }, #' @description @@ -106,45 +131,13 @@ TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter <- R6::R6Clas #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`size`)) { - sprintf( - '"size": - "%s" - ', - self$`size` - ) - }, - if (!is.null(self$`color`)) { - sprintf( - '"color": - "%s" - ', - self$`color` - ) - }, - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/echo_api/r/R/test_query_style_form_explode_true_array_string_query_object_parameter.R b/samples/client/echo_api/r/R/test_query_style_form_explode_true_array_string_query_object_parameter.R index a6e69b27f3bed..9a874c05c0d1f 100644 --- a/samples/client/echo_api/r/R/test_query_style_form_explode_true_array_string_query_object_parameter.R +++ b/samples/client/echo_api/r/R/test_query_style_form_explode_true_array_string_query_object_parameter.R @@ -30,16 +30,41 @@ TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter as a base R list. + #' @examples + #' # convert array of TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameterObject <- list() if (!is.null(self$`values`)) { TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameterObject[["values"]] <- self$`values` } - TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameterObject + return(TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameterObject) }, #' @description @@ -57,21 +82,13 @@ TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`values`)) { - sprintf( - '"values": - [%s] - ', - paste(unlist(lapply(self$`values`, function(x) paste0('"', x, '"'))), collapse = ",") - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/allof_tag_api_response.R b/samples/client/petstore/R-httr2-wrapper/R/allof_tag_api_response.R index 454e378a5c16f..018600362d38c 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/allof_tag_api_response.R +++ b/samples/client/petstore/R-httr2-wrapper/R/allof_tag_api_response.R @@ -77,10 +77,35 @@ AllofTagApiResponse <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return AllofTagApiResponse in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return AllofTagApiResponse as a base R list. + #' @examples + #' # convert array of AllofTagApiResponse (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert AllofTagApiResponse to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { AllofTagApiResponseObject <- list() if (!is.null(self$`id`)) { AllofTagApiResponseObject[["id"]] <- @@ -106,7 +131,7 @@ AllofTagApiResponse <- R6::R6Class( AllofTagApiResponseObject[[key]] <- self$additional_properties[[key]] } - AllofTagApiResponseObject + return(AllofTagApiResponseObject) }, #' @description @@ -143,58 +168,16 @@ AllofTagApiResponse <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return AllofTagApiResponse in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - }, - if (!is.null(self$`code`)) { - sprintf( - '"code": - %d - ', - self$`code` - ) - }, - if (!is.null(self$`type`)) { - sprintf( - '"type": - "%s" - ', - self$`type` - ) - }, - if (!is.null(self$`message`)) { - sprintf( - '"message": - "%s" - ', - self$`message` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/animal.R b/samples/client/petstore/R-httr2-wrapper/R/animal.R index 471a01afef3bb..cf2e97f9af306 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/animal.R +++ b/samples/client/petstore/R-httr2-wrapper/R/animal.R @@ -52,10 +52,35 @@ Animal <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Animal in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Animal as a base R list. + #' @examples + #' # convert array of Animal (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Animal to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { AnimalObject <- list() if (!is.null(self$`className`)) { AnimalObject[["className"]] <- @@ -69,7 +94,7 @@ Animal <- R6::R6Class( AnimalObject[[key]] <- self$additional_properties[[key]] } - AnimalObject + return(AnimalObject) }, #' @description @@ -97,34 +122,16 @@ Animal <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Animal in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`color`)) { - sprintf( - '"color": - "%s" - ', - self$`color` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/any_of_pig.R b/samples/client/petstore/R-httr2-wrapper/R/any_of_pig.R index ba3c8ea856d9d..7480eec76961a 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/any_of_pig.R +++ b/samples/client/petstore/R-httr2-wrapper/R/any_of_pig.R @@ -91,27 +91,32 @@ AnyOfPig <- R6::R6Class( }, #' @description - #' Serialize AnyOfPig to JSON string. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. + toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert AnyOfPig to a base R type #' - #' @return JSON string representation of the AnyOfPig. - toJSONString = function() { + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify((self$actual_instance$toJSONString()))) + return(self$actual_instance$toSimpleType()) } else { NULL } }, #' @description - #' Serialize AnyOfPig to JSON. + #' Serialize AnyOfPig to JSON string. #' - #' @return JSON representation of the AnyOfPig. - toJSON = function() { - if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() - } else { - NULL - } + #' @param ... Parameters passed to `jsonlite::toJSON` + #' @return JSON string representation of the AnyOfPig. + toJSONString = function(...) { + json <- jsonlite::toJSON(self$toSimpleType(), auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/any_of_primitive_type_test.R b/samples/client/petstore/R-httr2-wrapper/R/any_of_primitive_type_test.R index 99aa52c734276..f76defe9f4aa5 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/any_of_primitive_type_test.R +++ b/samples/client/petstore/R-httr2-wrapper/R/any_of_primitive_type_test.R @@ -111,25 +111,35 @@ AnyOfPrimitiveTypeTest <- R6::R6Class( #' @description #' Serialize AnyOfPrimitiveTypeTest to JSON string. - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return JSON string representation of the AnyOfPrimitiveTypeTest. - toJSONString = function() { + toJSONString = function(...) { + simple <- self$toSimpleType() if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify(self$actual_instance$toJSONString())) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) } else { - NULL + return(NULL) } }, #' @description - #' Serialize AnyOfPrimitiveTypeTest to JSON. - #' - #' @return JSON representation of the AnyOfPrimitiveTypeTest. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert AnyOfPrimitiveTypeTest to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() + return(self$actual_instance$toSimpleType()) } else { - NULL + return(NULL) } }, diff --git a/samples/client/petstore/R-httr2-wrapper/R/basque_pig.R b/samples/client/petstore/R-httr2-wrapper/R/basque_pig.R index cce82cd7d9323..ca8601f4c3b16 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/basque_pig.R +++ b/samples/client/petstore/R-httr2-wrapper/R/basque_pig.R @@ -50,10 +50,35 @@ BasquePig <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return BasquePig in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return BasquePig as a base R list. + #' @examples + #' # convert array of BasquePig (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert BasquePig to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { BasquePigObject <- list() if (!is.null(self$`className`)) { BasquePigObject[["className"]] <- @@ -67,7 +92,7 @@ BasquePig <- R6::R6Class( BasquePigObject[[key]] <- self$additional_properties[[key]] } - BasquePigObject + return(BasquePigObject) }, #' @description @@ -95,34 +120,16 @@ BasquePig <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return BasquePig in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`color`)) { - sprintf( - '"color": - "%s" - ', - self$`color` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/cat.R b/samples/client/petstore/R-httr2-wrapper/R/cat.R index b4014681ba49a..270b87c21643c 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/cat.R +++ b/samples/client/petstore/R-httr2-wrapper/R/cat.R @@ -60,10 +60,35 @@ Cat <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Cat in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Cat as a base R list. + #' @examples + #' # convert array of Cat (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Cat to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { CatObject <- list() if (!is.null(self$`className`)) { CatObject[["className"]] <- @@ -81,7 +106,7 @@ Cat <- R6::R6Class( CatObject[[key]] <- self$additional_properties[[key]] } - CatObject + return(CatObject) }, #' @description @@ -112,42 +137,16 @@ Cat <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Cat in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`color`)) { - sprintf( - '"color": - "%s" - ', - self$`color` - ) - }, - if (!is.null(self$`declawed`)) { - sprintf( - '"declawed": - %s - ', - tolower(self$`declawed`) - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/category.R b/samples/client/petstore/R-httr2-wrapper/R/category.R index 31106a3bc9e2a..0dcbd1b816109 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/category.R +++ b/samples/client/petstore/R-httr2-wrapper/R/category.R @@ -50,10 +50,35 @@ Category <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Category in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Category as a base R list. + #' @examples + #' # convert array of Category (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Category to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { CategoryObject <- list() if (!is.null(self$`id`)) { CategoryObject[["id"]] <- @@ -67,7 +92,7 @@ Category <- R6::R6Class( CategoryObject[[key]] <- self$additional_properties[[key]] } - CategoryObject + return(CategoryObject) }, #' @description @@ -95,34 +120,16 @@ Category <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Category in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/danish_pig.R b/samples/client/petstore/R-httr2-wrapper/R/danish_pig.R index 08ca2b9e3eea2..02d2208639b02 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/danish_pig.R +++ b/samples/client/petstore/R-httr2-wrapper/R/danish_pig.R @@ -50,10 +50,35 @@ DanishPig <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return DanishPig in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return DanishPig as a base R list. + #' @examples + #' # convert array of DanishPig (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert DanishPig to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { DanishPigObject <- list() if (!is.null(self$`className`)) { DanishPigObject[["className"]] <- @@ -67,7 +92,7 @@ DanishPig <- R6::R6Class( DanishPigObject[[key]] <- self$additional_properties[[key]] } - DanishPigObject + return(DanishPigObject) }, #' @description @@ -95,34 +120,16 @@ DanishPig <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return DanishPig in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`size`)) { - sprintf( - '"size": - %d - ', - self$`size` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/date.R b/samples/client/petstore/R-httr2-wrapper/R/date.R index d9b6ec0beb1be..411249d3fba1b 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/date.R +++ b/samples/client/petstore/R-httr2-wrapper/R/date.R @@ -63,10 +63,35 @@ Date <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Date in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Date as a base R list. + #' @examples + #' # convert array of Date (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Date to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { DateObject <- list() if (!is.null(self$`className`)) { DateObject[["className"]] <- @@ -84,7 +109,7 @@ Date <- R6::R6Class( DateObject[[key]] <- self$additional_properties[[key]] } - DateObject + return(DateObject) }, #' @description @@ -119,42 +144,16 @@ Date <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Date in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`percent_description`)) { - sprintf( - '"percent_description": - "%s" - ', - self$`percent_description` - ) - }, - if (!is.null(self$`url_property`)) { - sprintf( - '"url_property": - "%s" - ', - self$`url_property` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/dog.R b/samples/client/petstore/R-httr2-wrapper/R/dog.R index 34ae291211633..4d6dab71c61bc 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/dog.R +++ b/samples/client/petstore/R-httr2-wrapper/R/dog.R @@ -60,10 +60,35 @@ Dog <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Dog in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Dog as a base R list. + #' @examples + #' # convert array of Dog (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Dog to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { DogObject <- list() if (!is.null(self$`className`)) { DogObject[["className"]] <- @@ -81,7 +106,7 @@ Dog <- R6::R6Class( DogObject[[key]] <- self$additional_properties[[key]] } - DogObject + return(DogObject) }, #' @description @@ -112,42 +137,16 @@ Dog <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Dog in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`color`)) { - sprintf( - '"color": - "%s" - ', - self$`color` - ) - }, - if (!is.null(self$`breed`)) { - sprintf( - '"breed": - "%s" - ', - self$`breed` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/dummy_model.R b/samples/client/petstore/R-httr2-wrapper/R/dummy_model.R index 12d3ab52a1552..cbea7830b8247 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/dummy_model.R +++ b/samples/client/petstore/R-httr2-wrapper/R/dummy_model.R @@ -41,10 +41,35 @@ DummyModel <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return DummyModel in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return DummyModel as a base R list. + #' @examples + #' # convert array of DummyModel (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert DummyModel to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { DummyModelObject <- list() if (!is.null(self$`property`)) { DummyModelObject[["property"]] <- @@ -54,7 +79,7 @@ DummyModel <- R6::R6Class( DummyModelObject[[key]] <- self$additional_properties[[key]] } - DummyModelObject + return(DummyModelObject) }, #' @description @@ -79,26 +104,16 @@ DummyModel <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return DummyModel in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`property`)) { - sprintf( - '"property": - "%s" - ', - self$`property` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/fake_api.R b/samples/client/petstore/R-httr2-wrapper/R/fake_api.R index 5dae105c228b4..b314363f4b68a 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/fake_api.R +++ b/samples/client/petstore/R-httr2-wrapper/R/fake_api.R @@ -225,7 +225,7 @@ FakeApi <- R6::R6Class( if (!is.null(`pet`)) { local_var_body <- `pet`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/fake/test_optional_body_parameter" diff --git a/samples/client/petstore/R-httr2-wrapper/R/format_test.R b/samples/client/petstore/R-httr2-wrapper/R/format_test.R index f93bf1435c9a9..7d1bded3c5a80 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/format_test.R +++ b/samples/client/petstore/R-httr2-wrapper/R/format_test.R @@ -158,10 +158,35 @@ FormatTest <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return FormatTest in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return FormatTest as a base R list. + #' @examples + #' # convert array of FormatTest (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert FormatTest to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { FormatTestObject <- list() if (!is.null(self$`integer`)) { FormatTestObject[["integer"]] <- @@ -227,7 +252,7 @@ FormatTest <- R6::R6Class( FormatTestObject[[key]] <- self$additional_properties[[key]] } - FormatTestObject + return(FormatTestObject) }, #' @description @@ -294,138 +319,16 @@ FormatTest <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return FormatTest in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`integer`)) { - sprintf( - '"integer": - %d - ', - self$`integer` - ) - }, - if (!is.null(self$`int32`)) { - sprintf( - '"int32": - %d - ', - self$`int32` - ) - }, - if (!is.null(self$`int64`)) { - sprintf( - '"int64": - %d - ', - self$`int64` - ) - }, - if (!is.null(self$`number`)) { - sprintf( - '"number": - %d - ', - self$`number` - ) - }, - if (!is.null(self$`float`)) { - sprintf( - '"float": - %d - ', - self$`float` - ) - }, - if (!is.null(self$`double`)) { - sprintf( - '"double": - %d - ', - self$`double` - ) - }, - if (!is.null(self$`string`)) { - sprintf( - '"string": - "%s" - ', - self$`string` - ) - }, - if (!is.null(self$`byte`)) { - sprintf( - '"byte": - "%s" - ', - self$`byte` - ) - }, - if (!is.null(self$`binary`)) { - sprintf( - '"binary": - "%s" - ', - self$`binary` - ) - }, - if (!is.null(self$`date`)) { - sprintf( - '"date": - "%s" - ', - self$`date` - ) - }, - if (!is.null(self$`dateTime`)) { - sprintf( - '"dateTime": - "%s" - ', - self$`dateTime` - ) - }, - if (!is.null(self$`uuid`)) { - sprintf( - '"uuid": - "%s" - ', - self$`uuid` - ) - }, - if (!is.null(self$`password`)) { - sprintf( - '"password": - "%s" - ', - self$`password` - ) - }, - if (!is.null(self$`pattern_with_digits`)) { - sprintf( - '"pattern_with_digits": - "%s" - ', - self$`pattern_with_digits` - ) - }, - if (!is.null(self$`pattern_with_digits_and_delimiter`)) { - sprintf( - '"pattern_with_digits_and_delimiter": - "%s" - ', - self$`pattern_with_digits_and_delimiter` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/mammal.R b/samples/client/petstore/R-httr2-wrapper/R/mammal.R index fe4f3577d0ce0..29b32a31bcb8c 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/mammal.R +++ b/samples/client/petstore/R-httr2-wrapper/R/mammal.R @@ -135,25 +135,35 @@ Mammal <- R6::R6Class( #' @description #' Serialize Mammal to JSON string. - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return JSON string representation of the Mammal. - toJSONString = function() { + toJSONString = function(...) { + simple <- self$toSimpleType() if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify(self$actual_instance$toJSONString())) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) } else { - NULL + return(NULL) } }, #' @description - #' Serialize Mammal to JSON. - #' - #' @return JSON representation of the Mammal. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert Mammal to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() + return(self$actual_instance$toSimpleType()) } else { - NULL + return(NULL) } }, diff --git a/samples/client/petstore/R-httr2-wrapper/R/model_api_response.R b/samples/client/petstore/R-httr2-wrapper/R/model_api_response.R index 9116e438fedc0..a3a46dfb79072 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/model_api_response.R +++ b/samples/client/petstore/R-httr2-wrapper/R/model_api_response.R @@ -59,10 +59,35 @@ ModelApiResponse <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return ModelApiResponse in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return ModelApiResponse as a base R list. + #' @examples + #' # convert array of ModelApiResponse (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert ModelApiResponse to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { ModelApiResponseObject <- list() if (!is.null(self$`code`)) { ModelApiResponseObject[["code"]] <- @@ -80,7 +105,7 @@ ModelApiResponse <- R6::R6Class( ModelApiResponseObject[[key]] <- self$additional_properties[[key]] } - ModelApiResponseObject + return(ModelApiResponseObject) }, #' @description @@ -111,42 +136,16 @@ ModelApiResponse <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return ModelApiResponse in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`code`)) { - sprintf( - '"code": - %d - ', - self$`code` - ) - }, - if (!is.null(self$`type`)) { - sprintf( - '"type": - "%s" - ', - self$`type` - ) - }, - if (!is.null(self$`message`)) { - sprintf( - '"message": - "%s" - ', - self$`message` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/nested_one_of.R b/samples/client/petstore/R-httr2-wrapper/R/nested_one_of.R index e04a31a69acd9..31dcc2f10d01f 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/nested_one_of.R +++ b/samples/client/petstore/R-httr2-wrapper/R/nested_one_of.R @@ -48,10 +48,35 @@ NestedOneOf <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return NestedOneOf in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return NestedOneOf as a base R list. + #' @examples + #' # convert array of NestedOneOf (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert NestedOneOf to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { NestedOneOfObject <- list() if (!is.null(self$`size`)) { NestedOneOfObject[["size"]] <- @@ -59,13 +84,13 @@ NestedOneOf <- R6::R6Class( } if (!is.null(self$`nested_pig`)) { NestedOneOfObject[["nested_pig"]] <- - self$`nested_pig`$toJSON() + self$`nested_pig`$toSimpleType() } for (key in names(self$additional_properties)) { NestedOneOfObject[[key]] <- self$additional_properties[[key]] } - NestedOneOfObject + return(NestedOneOfObject) }, #' @description @@ -95,34 +120,16 @@ NestedOneOf <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return NestedOneOf in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`size`)) { - sprintf( - '"size": - %d - ', - self$`size` - ) - }, - if (!is.null(self$`nested_pig`)) { - sprintf( - '"nested_pig": - %s - ', - jsonlite::toJSON(self$`nested_pig`$toJSON(), auto_unbox = TRUE, digits = NA) - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/one_of_primitive_type_test.R b/samples/client/petstore/R-httr2-wrapper/R/one_of_primitive_type_test.R index 8a9280a9b213f..e5b5669856201 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/one_of_primitive_type_test.R +++ b/samples/client/petstore/R-httr2-wrapper/R/one_of_primitive_type_test.R @@ -111,25 +111,35 @@ OneOfPrimitiveTypeTest <- R6::R6Class( #' @description #' Serialize OneOfPrimitiveTypeTest to JSON string. - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return JSON string representation of the OneOfPrimitiveTypeTest. - toJSONString = function() { + toJSONString = function(...) { + simple <- self$toSimpleType() if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify(self$actual_instance$toJSONString())) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) } else { - NULL + return(NULL) } }, #' @description - #' Serialize OneOfPrimitiveTypeTest to JSON. - #' - #' @return JSON representation of the OneOfPrimitiveTypeTest. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert OneOfPrimitiveTypeTest to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() + return(self$actual_instance$toSimpleType()) } else { - NULL + return(NULL) } }, diff --git a/samples/client/petstore/R-httr2-wrapper/R/order.R b/samples/client/petstore/R-httr2-wrapper/R/order.R index cd84eed74eef0..07378f03666c3 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/order.R +++ b/samples/client/petstore/R-httr2-wrapper/R/order.R @@ -89,10 +89,35 @@ Order <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Order in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Order as a base R list. + #' @examples + #' # convert array of Order (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Order to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { OrderObject <- list() if (!is.null(self$`id`)) { OrderObject[["id"]] <- @@ -122,7 +147,7 @@ Order <- R6::R6Class( OrderObject[[key]] <- self$additional_properties[[key]] } - OrderObject + return(OrderObject) }, #' @description @@ -165,66 +190,16 @@ Order <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Order in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`petId`)) { - sprintf( - '"petId": - %d - ', - self$`petId` - ) - }, - if (!is.null(self$`quantity`)) { - sprintf( - '"quantity": - %d - ', - self$`quantity` - ) - }, - if (!is.null(self$`shipDate`)) { - sprintf( - '"shipDate": - "%s" - ', - self$`shipDate` - ) - }, - if (!is.null(self$`status`)) { - sprintf( - '"status": - "%s" - ', - self$`status` - ) - }, - if (!is.null(self$`complete`)) { - sprintf( - '"complete": - %s - ', - tolower(self$`complete`) - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/pet.R b/samples/client/petstore/R-httr2-wrapper/R/pet.R index 28e1693c419f0..27db68d8fdbdb 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/pet.R +++ b/samples/client/petstore/R-httr2-wrapper/R/pet.R @@ -85,10 +85,35 @@ Pet <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Pet in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Pet as a base R list. + #' @examples + #' # convert array of Pet (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Pet to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { PetObject <- list() if (!is.null(self$`id`)) { PetObject[["id"]] <- @@ -96,7 +121,7 @@ Pet <- R6::R6Class( } if (!is.null(self$`category`)) { PetObject[["category"]] <- - self$`category`$toJSON() + self$`category`$toSimpleType() } if (!is.null(self$`name`)) { PetObject[["name"]] <- @@ -108,7 +133,7 @@ Pet <- R6::R6Class( } if (!is.null(self$`tags`)) { PetObject[["tags"]] <- - lapply(self$`tags`, function(x) x$toJSON()) + lapply(self$`tags`, function(x) x$toSimpleType()) } if (!is.null(self$`status`)) { PetObject[["status"]] <- @@ -118,7 +143,7 @@ Pet <- R6::R6Class( PetObject[[key]] <- self$additional_properties[[key]] } - PetObject + return(PetObject) }, #' @description @@ -163,66 +188,16 @@ Pet <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Pet in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`category`)) { - sprintf( - '"category": - %s - ', - jsonlite::toJSON(self$`category`$toJSON(), auto_unbox = TRUE, digits = NA) - ) - }, - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - }, - if (!is.null(self$`photoUrls`)) { - sprintf( - '"photoUrls": - [%s] - ', - paste(unlist(lapply(self$`photoUrls`, function(x) paste0('"', x, '"'))), collapse = ",") - ) - }, - if (!is.null(self$`tags`)) { - sprintf( - '"tags": - [%s] -', - paste(sapply(self$`tags`, function(x) jsonlite::toJSON(x$toJSON(), auto_unbox = TRUE, digits = NA)), collapse = ",") - ) - }, - if (!is.null(self$`status`)) { - sprintf( - '"status": - "%s" - ', - self$`status` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/pet_api.R b/samples/client/petstore/R-httr2-wrapper/R/pet_api.R index b19e01d9d8abc..e32bd6cea7117 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/pet_api.R +++ b/samples/client/petstore/R-httr2-wrapper/R/pet_api.R @@ -435,7 +435,7 @@ PetApi <- R6::R6Class( if (!is.null(`pet`)) { local_var_body <- `pet`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/pet" @@ -1288,7 +1288,7 @@ PetApi <- R6::R6Class( if (!is.null(`pet`)) { local_var_body <- `pet`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/pet" diff --git a/samples/client/petstore/R-httr2-wrapper/R/pet_map.R b/samples/client/petstore/R-httr2-wrapper/R/pet_map.R index 1fc910ac1da2b..aa59c50a09c06 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/pet_map.R +++ b/samples/client/petstore/R-httr2-wrapper/R/pet_map.R @@ -40,10 +40,35 @@ PetMap <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return PetMap in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return PetMap as a base R list. + #' @examples + #' # convert array of PetMap (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert PetMap to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { PetMapObject <- list() if (!is.null(self$`pet`)) { PetMapObject[["pet"]] <- @@ -53,7 +78,7 @@ PetMap <- R6::R6Class( PetMapObject[[key]] <- self$additional_properties[[key]] } - PetMapObject + return(PetMapObject) }, #' @description @@ -78,26 +103,16 @@ PetMap <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return PetMap in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`pet`)) { - sprintf( - '"pet": - %s - ', - jsonlite::toJSON(lapply(self$`pet`, function(x){ x }), auto_unbox = TRUE, digits = NA) - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/pig.R b/samples/client/petstore/R-httr2-wrapper/R/pig.R index 6e0242ca3e9e7..11c4f531b94f3 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/pig.R +++ b/samples/client/petstore/R-httr2-wrapper/R/pig.R @@ -135,25 +135,35 @@ Pig <- R6::R6Class( #' @description #' Serialize Pig to JSON string. - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return JSON string representation of the Pig. - toJSONString = function() { + toJSONString = function(...) { + simple <- self$toSimpleType() if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify(self$actual_instance$toJSONString())) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) } else { - NULL + return(NULL) } }, #' @description - #' Serialize Pig to JSON. - #' - #' @return JSON representation of the Pig. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert Pig to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() + return(self$actual_instance$toSimpleType()) } else { - NULL + return(NULL) } }, diff --git a/samples/client/petstore/R-httr2-wrapper/R/special.R b/samples/client/petstore/R-httr2-wrapper/R/special.R index 5841fc79dd39c..4c27190313fb2 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/special.R +++ b/samples/client/petstore/R-httr2-wrapper/R/special.R @@ -97,10 +97,35 @@ Special <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Special in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Special as a base R list. + #' @examples + #' # convert array of Special (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Special to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { SpecialObject <- list() if (!is.null(self$`set_test`)) { SpecialObject[["set_test"]] <- @@ -134,7 +159,7 @@ Special <- R6::R6Class( SpecialObject[[key]] <- self$additional_properties[[key]] } - SpecialObject + return(SpecialObject) }, #' @description @@ -180,74 +205,16 @@ Special <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Special in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`set_test`)) { - sprintf( - '"set_test": - [%s] - ', - paste(unlist(lapply(self$`set_test`, function(x) paste0('"', x, '"'))), collapse = ",") - ) - }, - if (!is.null(self$`item_self`)) { - sprintf( - '"self": - %d - ', - self$`item_self` - ) - }, - if (!is.null(self$`item_private`)) { - sprintf( - '"private": - "%s" - ', - self$`item_private` - ) - }, - if (!is.null(self$`item_super`)) { - sprintf( - '"super": - "%s" - ', - self$`item_super` - ) - }, - if (!is.null(self$`123_number`)) { - sprintf( - '"123_number": - "%s" - ', - self$`123_number` - ) - }, - if (!is.null(self$`array[test]`)) { - sprintf( - '"array[test]": - "%s" - ', - self$`array[test]` - ) - }, - if (!is.null(self$`empty_string`)) { - sprintf( - '"empty_string": - "%s" - ', - self$`empty_string` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/store_api.R b/samples/client/petstore/R-httr2-wrapper/R/store_api.R index e49457700c0b2..bbf86c4f21c0c 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/store_api.R +++ b/samples/client/petstore/R-httr2-wrapper/R/store_api.R @@ -546,7 +546,7 @@ StoreApi <- R6::R6Class( if (!is.null(`order`)) { local_var_body <- `order`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/store/order" diff --git a/samples/client/petstore/R-httr2-wrapper/R/tag.R b/samples/client/petstore/R-httr2-wrapper/R/tag.R index c9ec58ae6b82e..b4c893dfe77e5 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/tag.R +++ b/samples/client/petstore/R-httr2-wrapper/R/tag.R @@ -50,10 +50,35 @@ Tag <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Tag in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Tag as a base R list. + #' @examples + #' # convert array of Tag (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Tag to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { TagObject <- list() if (!is.null(self$`id`)) { TagObject[["id"]] <- @@ -67,7 +92,7 @@ Tag <- R6::R6Class( TagObject[[key]] <- self$additional_properties[[key]] } - TagObject + return(TagObject) }, #' @description @@ -95,34 +120,16 @@ Tag <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Tag in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/update_pet_request.R b/samples/client/petstore/R-httr2-wrapper/R/update_pet_request.R index 47369030cfac2..3559d3c4d8380 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/update_pet_request.R +++ b/samples/client/petstore/R-httr2-wrapper/R/update_pet_request.R @@ -45,14 +45,39 @@ UpdatePetRequest <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return UpdatePetRequest in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return UpdatePetRequest as a base R list. + #' @examples + #' # convert array of UpdatePetRequest (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert UpdatePetRequest to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { UpdatePetRequestObject <- list() if (!is.null(self$`jsonData`)) { UpdatePetRequestObject[["jsonData"]] <- - self$`jsonData`$toJSON() + self$`jsonData`$toSimpleType() } if (!is.null(self$`binaryDataN2Information`)) { UpdatePetRequestObject[["binaryDataN2Information"]] <- @@ -62,7 +87,7 @@ UpdatePetRequest <- R6::R6Class( UpdatePetRequestObject[[key]] <- self$additional_properties[[key]] } - UpdatePetRequestObject + return(UpdatePetRequestObject) }, #' @description @@ -92,34 +117,16 @@ UpdatePetRequest <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return UpdatePetRequest in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`jsonData`)) { - sprintf( - '"jsonData": - %s - ', - jsonlite::toJSON(self$`jsonData`$toJSON(), auto_unbox = TRUE, digits = NA) - ) - }, - if (!is.null(self$`binaryDataN2Information`)) { - sprintf( - '"binaryDataN2Information": - "%s" - ', - self$`binaryDataN2Information` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/user.R b/samples/client/petstore/R-httr2-wrapper/R/user.R index df4396abb2ca7..361d0d454f210 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/user.R +++ b/samples/client/petstore/R-httr2-wrapper/R/user.R @@ -104,10 +104,35 @@ User <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return User in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return User as a base R list. + #' @examples + #' # convert array of User (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert User to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { UserObject <- list() if (!is.null(self$`id`)) { UserObject[["id"]] <- @@ -145,7 +170,7 @@ User <- R6::R6Class( UserObject[[key]] <- self$additional_properties[[key]] } - UserObject + return(UserObject) }, #' @description @@ -191,82 +216,16 @@ User <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return User in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`username`)) { - sprintf( - '"username": - "%s" - ', - self$`username` - ) - }, - if (!is.null(self$`firstName`)) { - sprintf( - '"firstName": - "%s" - ', - self$`firstName` - ) - }, - if (!is.null(self$`lastName`)) { - sprintf( - '"lastName": - "%s" - ', - self$`lastName` - ) - }, - if (!is.null(self$`email`)) { - sprintf( - '"email": - "%s" - ', - self$`email` - ) - }, - if (!is.null(self$`password`)) { - sprintf( - '"password": - "%s" - ', - self$`password` - ) - }, - if (!is.null(self$`phone`)) { - sprintf( - '"phone": - "%s" - ', - self$`phone` - ) - }, - if (!is.null(self$`userStatus`)) { - sprintf( - '"userStatus": - %d - ', - self$`userStatus` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/user_api.R b/samples/client/petstore/R-httr2-wrapper/R/user_api.R index 4c938c7ee3ada..a99c036736f80 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/user_api.R +++ b/samples/client/petstore/R-httr2-wrapper/R/user_api.R @@ -318,7 +318,7 @@ UserApi <- R6::R6Class( if (!is.null(`user`)) { local_var_body <- `user`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/user" @@ -428,7 +428,7 @@ UserApi <- R6::R6Class( })), collapse = ",") local_var_body <- paste0("[", body.items, "]") } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/user/createWithArray" @@ -538,7 +538,7 @@ UserApi <- R6::R6Class( })), collapse = ",") local_var_body <- paste0("[", body.items, "]") } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/user/createWithList" @@ -1099,7 +1099,7 @@ UserApi <- R6::R6Class( if (!is.null(`user`)) { local_var_body <- `user`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/user/{username}" diff --git a/samples/client/petstore/R-httr2-wrapper/R/whale.R b/samples/client/petstore/R-httr2-wrapper/R/whale.R index e39211045a76f..ea54d3bdf71c4 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/whale.R +++ b/samples/client/petstore/R-httr2-wrapper/R/whale.R @@ -59,10 +59,35 @@ Whale <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Whale in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Whale as a base R list. + #' @examples + #' # convert array of Whale (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Whale to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { WhaleObject <- list() if (!is.null(self$`hasBaleen`)) { WhaleObject[["hasBaleen"]] <- @@ -80,7 +105,7 @@ Whale <- R6::R6Class( WhaleObject[[key]] <- self$additional_properties[[key]] } - WhaleObject + return(WhaleObject) }, #' @description @@ -111,42 +136,16 @@ Whale <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Whale in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`hasBaleen`)) { - sprintf( - '"hasBaleen": - %s - ', - tolower(self$`hasBaleen`) - ) - }, - if (!is.null(self$`hasTeeth`)) { - sprintf( - '"hasTeeth": - %s - ', - tolower(self$`hasTeeth`) - ) - }, - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/R/zebra.R b/samples/client/petstore/R-httr2-wrapper/R/zebra.R index fb6d90d4d983d..6b85dbff40930 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/zebra.R +++ b/samples/client/petstore/R-httr2-wrapper/R/zebra.R @@ -53,10 +53,35 @@ Zebra <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Zebra in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Zebra as a base R list. + #' @examples + #' # convert array of Zebra (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Zebra to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { ZebraObject <- list() if (!is.null(self$`type`)) { ZebraObject[["type"]] <- @@ -70,7 +95,7 @@ Zebra <- R6::R6Class( ZebraObject[[key]] <- self$additional_properties[[key]] } - ZebraObject + return(ZebraObject) }, #' @description @@ -101,34 +126,16 @@ Zebra <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Zebra in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`type`)) { - sprintf( - '"type": - "%s" - ', - self$`type` - ) - }, - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2-wrapper/tests/testthat/test_petstore.R b/samples/client/petstore/R-httr2-wrapper/tests/testthat/test_petstore.R index 917d3fb00ec45..f5c8c4edabf49 100644 --- a/samples/client/petstore/R-httr2-wrapper/tests/testthat/test_petstore.R +++ b/samples/client/petstore/R-httr2-wrapper/tests/testthat/test_petstore.R @@ -70,7 +70,7 @@ test_that("Test toJSON toJSONString fromJSON fromJSONString print", { # tests for other pet objects pet0 <- Pet$new() - jsonpet <- pet0$toJSON() + jsonpet <- pet0$toSimpleType() pet2 <- pet0$fromJSON( jsonlite::toJSON(jsonpet, auto_unbox = TRUE) ) @@ -96,7 +96,7 @@ test_that("Test toJSON toJSONString fromJSON fromJSONString print", { ), status = "available" ) - jsonpet <- pet1$toJSON() + jsonpet <- pet1$toSimpleType() pet2 <- pet1$fromJSON( jsonlite::toJSON(jsonpet, auto_unbox = TRUE) ) @@ -118,7 +118,7 @@ test_that("Test toJSON toJSONString fromJSON fromJSONString print", { test_that("Test Category", { c1 <- Category$new(id = 450, name = "test_cat") c2 <- Category$new() - c2$fromJSON(jsonlite::toJSON(c1$toJSON(), auto_unbox = TRUE)) + c2$fromJSON(jsonlite::toJSON(c1$toSimpleType(), auto_unbox = TRUE)) expect_equal(c1, c2) c2$fromJSONString(c1$toJSONString()) expect_equal(c1, c2) diff --git a/samples/client/petstore/R-httr2/R/allof_tag_api_response.R b/samples/client/petstore/R-httr2/R/allof_tag_api_response.R index ff239b9cda9ed..37fa07aaa4758 100644 --- a/samples/client/petstore/R-httr2/R/allof_tag_api_response.R +++ b/samples/client/petstore/R-httr2/R/allof_tag_api_response.R @@ -67,10 +67,35 @@ AllofTagApiResponse <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return AllofTagApiResponse in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return AllofTagApiResponse as a base R list. + #' @examples + #' # convert array of AllofTagApiResponse (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert AllofTagApiResponse to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { AllofTagApiResponseObject <- list() if (!is.null(self$`id`)) { AllofTagApiResponseObject[["id"]] <- @@ -92,7 +117,7 @@ AllofTagApiResponse <- R6::R6Class( AllofTagApiResponseObject[["message"]] <- self$`message` } - AllofTagApiResponseObject + return(AllofTagApiResponseObject) }, #' @description @@ -122,53 +147,13 @@ AllofTagApiResponse <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return AllofTagApiResponse in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - }, - if (!is.null(self$`code`)) { - sprintf( - '"code": - %d - ', - self$`code` - ) - }, - if (!is.null(self$`type`)) { - sprintf( - '"type": - "%s" - ', - self$`type` - ) - }, - if (!is.null(self$`message`)) { - sprintf( - '"message": - "%s" - ', - self$`message` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/animal.R b/samples/client/petstore/R-httr2/R/animal.R index 4f1f8ab507c6d..8b7e9dba4ffe7 100644 --- a/samples/client/petstore/R-httr2/R/animal.R +++ b/samples/client/petstore/R-httr2/R/animal.R @@ -42,10 +42,35 @@ Animal <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Animal in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Animal as a base R list. + #' @examples + #' # convert array of Animal (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Animal to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { AnimalObject <- list() if (!is.null(self$`className`)) { AnimalObject[["className"]] <- @@ -55,7 +80,7 @@ Animal <- R6::R6Class( AnimalObject[["color"]] <- self$`color` } - AnimalObject + return(AnimalObject) }, #' @description @@ -76,29 +101,13 @@ Animal <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Animal in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`color`)) { - sprintf( - '"color": - "%s" - ', - self$`color` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/any_of_pig.R b/samples/client/petstore/R-httr2/R/any_of_pig.R index ba3c8ea856d9d..7480eec76961a 100644 --- a/samples/client/petstore/R-httr2/R/any_of_pig.R +++ b/samples/client/petstore/R-httr2/R/any_of_pig.R @@ -91,27 +91,32 @@ AnyOfPig <- R6::R6Class( }, #' @description - #' Serialize AnyOfPig to JSON string. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. + toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert AnyOfPig to a base R type #' - #' @return JSON string representation of the AnyOfPig. - toJSONString = function() { + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify((self$actual_instance$toJSONString()))) + return(self$actual_instance$toSimpleType()) } else { NULL } }, #' @description - #' Serialize AnyOfPig to JSON. + #' Serialize AnyOfPig to JSON string. #' - #' @return JSON representation of the AnyOfPig. - toJSON = function() { - if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() - } else { - NULL - } + #' @param ... Parameters passed to `jsonlite::toJSON` + #' @return JSON string representation of the AnyOfPig. + toJSONString = function(...) { + json <- jsonlite::toJSON(self$toSimpleType(), auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/any_of_primitive_type_test.R b/samples/client/petstore/R-httr2/R/any_of_primitive_type_test.R index 99aa52c734276..f76defe9f4aa5 100644 --- a/samples/client/petstore/R-httr2/R/any_of_primitive_type_test.R +++ b/samples/client/petstore/R-httr2/R/any_of_primitive_type_test.R @@ -111,25 +111,35 @@ AnyOfPrimitiveTypeTest <- R6::R6Class( #' @description #' Serialize AnyOfPrimitiveTypeTest to JSON string. - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return JSON string representation of the AnyOfPrimitiveTypeTest. - toJSONString = function() { + toJSONString = function(...) { + simple <- self$toSimpleType() if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify(self$actual_instance$toJSONString())) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) } else { - NULL + return(NULL) } }, #' @description - #' Serialize AnyOfPrimitiveTypeTest to JSON. - #' - #' @return JSON representation of the AnyOfPrimitiveTypeTest. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert AnyOfPrimitiveTypeTest to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() + return(self$actual_instance$toSimpleType()) } else { - NULL + return(NULL) } }, diff --git a/samples/client/petstore/R-httr2/R/basque_pig.R b/samples/client/petstore/R-httr2/R/basque_pig.R index 6833f264bc7a7..77af09db6a040 100644 --- a/samples/client/petstore/R-httr2/R/basque_pig.R +++ b/samples/client/petstore/R-httr2/R/basque_pig.R @@ -40,10 +40,35 @@ BasquePig <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return BasquePig in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return BasquePig as a base R list. + #' @examples + #' # convert array of BasquePig (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert BasquePig to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { BasquePigObject <- list() if (!is.null(self$`className`)) { BasquePigObject[["className"]] <- @@ -53,7 +78,7 @@ BasquePig <- R6::R6Class( BasquePigObject[["color"]] <- self$`color` } - BasquePigObject + return(BasquePigObject) }, #' @description @@ -74,29 +99,13 @@ BasquePig <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return BasquePig in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`color`)) { - sprintf( - '"color": - "%s" - ', - self$`color` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/cat.R b/samples/client/petstore/R-httr2/R/cat.R index d50bf428d8ebc..54784f94e2b5b 100644 --- a/samples/client/petstore/R-httr2/R/cat.R +++ b/samples/client/petstore/R-httr2/R/cat.R @@ -50,10 +50,35 @@ Cat <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Cat in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Cat as a base R list. + #' @examples + #' # convert array of Cat (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Cat to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { CatObject <- list() if (!is.null(self$`className`)) { CatObject[["className"]] <- @@ -67,7 +92,7 @@ Cat <- R6::R6Class( CatObject[["declawed"]] <- self$`declawed` } - CatObject + return(CatObject) }, #' @description @@ -91,37 +116,13 @@ Cat <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Cat in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`color`)) { - sprintf( - '"color": - "%s" - ', - self$`color` - ) - }, - if (!is.null(self$`declawed`)) { - sprintf( - '"declawed": - %s - ', - tolower(self$`declawed`) - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/category.R b/samples/client/petstore/R-httr2/R/category.R index 752d9b8024b16..9448df38190e5 100644 --- a/samples/client/petstore/R-httr2/R/category.R +++ b/samples/client/petstore/R-httr2/R/category.R @@ -40,10 +40,35 @@ Category <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Category in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Category as a base R list. + #' @examples + #' # convert array of Category (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Category to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { CategoryObject <- list() if (!is.null(self$`id`)) { CategoryObject[["id"]] <- @@ -53,7 +78,7 @@ Category <- R6::R6Class( CategoryObject[["name"]] <- self$`name` } - CategoryObject + return(CategoryObject) }, #' @description @@ -74,29 +99,13 @@ Category <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Category in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/danish_pig.R b/samples/client/petstore/R-httr2/R/danish_pig.R index d7e35b52e5e6a..e5eeb44461468 100644 --- a/samples/client/petstore/R-httr2/R/danish_pig.R +++ b/samples/client/petstore/R-httr2/R/danish_pig.R @@ -40,10 +40,35 @@ DanishPig <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return DanishPig in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return DanishPig as a base R list. + #' @examples + #' # convert array of DanishPig (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert DanishPig to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { DanishPigObject <- list() if (!is.null(self$`className`)) { DanishPigObject[["className"]] <- @@ -53,7 +78,7 @@ DanishPig <- R6::R6Class( DanishPigObject[["size"]] <- self$`size` } - DanishPigObject + return(DanishPigObject) }, #' @description @@ -74,29 +99,13 @@ DanishPig <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return DanishPig in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`size`)) { - sprintf( - '"size": - %d - ', - self$`size` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/date.R b/samples/client/petstore/R-httr2/R/date.R index a822606b6b7b6..81dc68d4feec0 100644 --- a/samples/client/petstore/R-httr2/R/date.R +++ b/samples/client/petstore/R-httr2/R/date.R @@ -53,10 +53,35 @@ Date <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Date in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Date as a base R list. + #' @examples + #' # convert array of Date (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Date to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { DateObject <- list() if (!is.null(self$`className`)) { DateObject[["className"]] <- @@ -70,7 +95,7 @@ Date <- R6::R6Class( DateObject[["url_property"]] <- self$`url_property` } - DateObject + return(DateObject) }, #' @description @@ -98,37 +123,13 @@ Date <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Date in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`percent`)) { - sprintf( - '"percent_description": - "%s" - ', - self$`percent` - ) - }, - if (!is.null(self$`url_property`)) { - sprintf( - '"url_property": - "%s" - ', - self$`url_property` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/dog.R b/samples/client/petstore/R-httr2/R/dog.R index 0851d7461d996..1928ffc3985c0 100644 --- a/samples/client/petstore/R-httr2/R/dog.R +++ b/samples/client/petstore/R-httr2/R/dog.R @@ -50,10 +50,35 @@ Dog <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Dog in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Dog as a base R list. + #' @examples + #' # convert array of Dog (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Dog to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { DogObject <- list() if (!is.null(self$`className`)) { DogObject[["className"]] <- @@ -67,7 +92,7 @@ Dog <- R6::R6Class( DogObject[["breed"]] <- self$`breed` } - DogObject + return(DogObject) }, #' @description @@ -91,37 +116,13 @@ Dog <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Dog in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`color`)) { - sprintf( - '"color": - "%s" - ', - self$`color` - ) - }, - if (!is.null(self$`breed`)) { - sprintf( - '"breed": - "%s" - ', - self$`breed` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/fake_api.R b/samples/client/petstore/R-httr2/R/fake_api.R index 175540cf5ee68..2038aabaf7ee0 100644 --- a/samples/client/petstore/R-httr2/R/fake_api.R +++ b/samples/client/petstore/R-httr2/R/fake_api.R @@ -225,7 +225,7 @@ FakeApi <- R6::R6Class( if (!is.null(`pet`)) { local_var_body <- `pet`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/fake/test_optional_body_parameter" diff --git a/samples/client/petstore/R-httr2/R/format_test.R b/samples/client/petstore/R-httr2/R/format_test.R index 1174973049809..1e8a62b2fd9cd 100644 --- a/samples/client/petstore/R-httr2/R/format_test.R +++ b/samples/client/petstore/R-httr2/R/format_test.R @@ -148,10 +148,35 @@ FormatTest <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return FormatTest in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return FormatTest as a base R list. + #' @examples + #' # convert array of FormatTest (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert FormatTest to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { FormatTestObject <- list() if (!is.null(self$`integer`)) { FormatTestObject[["integer"]] <- @@ -213,7 +238,7 @@ FormatTest <- R6::R6Class( FormatTestObject[["pattern_with_digits_and_delimiter"]] <- self$`pattern_with_digits_and_delimiter` } - FormatTestObject + return(FormatTestObject) }, #' @description @@ -273,133 +298,13 @@ FormatTest <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return FormatTest in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`integer`)) { - sprintf( - '"integer": - %d - ', - self$`integer` - ) - }, - if (!is.null(self$`int32`)) { - sprintf( - '"int32": - %d - ', - self$`int32` - ) - }, - if (!is.null(self$`int64`)) { - sprintf( - '"int64": - %d - ', - self$`int64` - ) - }, - if (!is.null(self$`number`)) { - sprintf( - '"number": - %d - ', - self$`number` - ) - }, - if (!is.null(self$`float`)) { - sprintf( - '"float": - %d - ', - self$`float` - ) - }, - if (!is.null(self$`double`)) { - sprintf( - '"double": - %d - ', - self$`double` - ) - }, - if (!is.null(self$`string`)) { - sprintf( - '"string": - "%s" - ', - self$`string` - ) - }, - if (!is.null(self$`byte`)) { - sprintf( - '"byte": - "%s" - ', - self$`byte` - ) - }, - if (!is.null(self$`binary`)) { - sprintf( - '"binary": - "%s" - ', - self$`binary` - ) - }, - if (!is.null(self$`date`)) { - sprintf( - '"date": - "%s" - ', - self$`date` - ) - }, - if (!is.null(self$`dateTime`)) { - sprintf( - '"dateTime": - "%s" - ', - self$`dateTime` - ) - }, - if (!is.null(self$`uuid`)) { - sprintf( - '"uuid": - "%s" - ', - self$`uuid` - ) - }, - if (!is.null(self$`password`)) { - sprintf( - '"password": - "%s" - ', - self$`password` - ) - }, - if (!is.null(self$`pattern_with_digits`)) { - sprintf( - '"pattern_with_digits": - "%s" - ', - self$`pattern_with_digits` - ) - }, - if (!is.null(self$`pattern_with_digits_and_delimiter`)) { - sprintf( - '"pattern_with_digits_and_delimiter": - "%s" - ', - self$`pattern_with_digits_and_delimiter` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/just_model.R b/samples/client/petstore/R-httr2/R/just_model.R index 780533eb3db03..89d14ef99c3ac 100644 --- a/samples/client/petstore/R-httr2/R/just_model.R +++ b/samples/client/petstore/R-httr2/R/just_model.R @@ -31,16 +31,41 @@ JustModel <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return JustModel in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return JustModel as a base R list. + #' @examples + #' # convert array of JustModel (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert JustModel to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { JustModelObject <- list() if (!is.null(self$`property`)) { JustModelObject[["property"]] <- self$`property` } - JustModelObject + return(JustModelObject) }, #' @description @@ -58,21 +83,13 @@ JustModel <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return JustModel in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`property`)) { - sprintf( - '"property": - "%s" - ', - self$`property` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/mammal.R b/samples/client/petstore/R-httr2/R/mammal.R index bbd57ed00acbe..3d93ab765e399 100644 --- a/samples/client/petstore/R-httr2/R/mammal.R +++ b/samples/client/petstore/R-httr2/R/mammal.R @@ -109,25 +109,35 @@ Mammal <- R6::R6Class( #' @description #' Serialize Mammal to JSON string. - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return JSON string representation of the Mammal. - toJSONString = function() { + toJSONString = function(...) { + simple <- self$toSimpleType() if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify(self$actual_instance$toJSONString())) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) } else { - NULL + return(NULL) } }, #' @description - #' Serialize Mammal to JSON. - #' - #' @return JSON representation of the Mammal. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert Mammal to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() + return(self$actual_instance$toSimpleType()) } else { - NULL + return(NULL) } }, diff --git a/samples/client/petstore/R-httr2/R/model_api_response.R b/samples/client/petstore/R-httr2/R/model_api_response.R index 98814bedafbb1..d65c1860ce2c4 100644 --- a/samples/client/petstore/R-httr2/R/model_api_response.R +++ b/samples/client/petstore/R-httr2/R/model_api_response.R @@ -49,10 +49,35 @@ ModelApiResponse <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return ModelApiResponse in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return ModelApiResponse as a base R list. + #' @examples + #' # convert array of ModelApiResponse (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert ModelApiResponse to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { ModelApiResponseObject <- list() if (!is.null(self$`code`)) { ModelApiResponseObject[["code"]] <- @@ -66,7 +91,7 @@ ModelApiResponse <- R6::R6Class( ModelApiResponseObject[["message"]] <- self$`message` } - ModelApiResponseObject + return(ModelApiResponseObject) }, #' @description @@ -90,37 +115,13 @@ ModelApiResponse <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return ModelApiResponse in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`code`)) { - sprintf( - '"code": - %d - ', - self$`code` - ) - }, - if (!is.null(self$`type`)) { - sprintf( - '"type": - "%s" - ', - self$`type` - ) - }, - if (!is.null(self$`message`)) { - sprintf( - '"message": - "%s" - ', - self$`message` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/nested_one_of.R b/samples/client/petstore/R-httr2/R/nested_one_of.R index c1abefcacd8b1..d0ef1f9b67a51 100644 --- a/samples/client/petstore/R-httr2/R/nested_one_of.R +++ b/samples/client/petstore/R-httr2/R/nested_one_of.R @@ -38,10 +38,35 @@ NestedOneOf <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return NestedOneOf in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return NestedOneOf as a base R list. + #' @examples + #' # convert array of NestedOneOf (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert NestedOneOf to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { NestedOneOfObject <- list() if (!is.null(self$`size`)) { NestedOneOfObject[["size"]] <- @@ -49,9 +74,9 @@ NestedOneOf <- R6::R6Class( } if (!is.null(self$`nested_pig`)) { NestedOneOfObject[["nested_pig"]] <- - self$`nested_pig`$toJSON() + self$`nested_pig`$toSimpleType() } - NestedOneOfObject + return(NestedOneOfObject) }, #' @description @@ -74,29 +99,13 @@ NestedOneOf <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return NestedOneOf in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`size`)) { - sprintf( - '"size": - %d - ', - self$`size` - ) - }, - if (!is.null(self$`nested_pig`)) { - sprintf( - '"nested_pig": - %s - ', - jsonlite::toJSON(self$`nested_pig`$toJSON(), auto_unbox = TRUE, digits = NA) - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/one_of_primitive_type_test.R b/samples/client/petstore/R-httr2/R/one_of_primitive_type_test.R index 8a9280a9b213f..e5b5669856201 100644 --- a/samples/client/petstore/R-httr2/R/one_of_primitive_type_test.R +++ b/samples/client/petstore/R-httr2/R/one_of_primitive_type_test.R @@ -111,25 +111,35 @@ OneOfPrimitiveTypeTest <- R6::R6Class( #' @description #' Serialize OneOfPrimitiveTypeTest to JSON string. - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return JSON string representation of the OneOfPrimitiveTypeTest. - toJSONString = function() { + toJSONString = function(...) { + simple <- self$toSimpleType() if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify(self$actual_instance$toJSONString())) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) } else { - NULL + return(NULL) } }, #' @description - #' Serialize OneOfPrimitiveTypeTest to JSON. - #' - #' @return JSON representation of the OneOfPrimitiveTypeTest. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert OneOfPrimitiveTypeTest to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() + return(self$actual_instance$toSimpleType()) } else { - NULL + return(NULL) } }, diff --git a/samples/client/petstore/R-httr2/R/order.R b/samples/client/petstore/R-httr2/R/order.R index 4155b311f3164..cf6bcb48bc858 100644 --- a/samples/client/petstore/R-httr2/R/order.R +++ b/samples/client/petstore/R-httr2/R/order.R @@ -79,10 +79,35 @@ Order <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Order in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Order as a base R list. + #' @examples + #' # convert array of Order (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Order to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { OrderObject <- list() if (!is.null(self$`id`)) { OrderObject[["id"]] <- @@ -108,7 +133,7 @@ Order <- R6::R6Class( OrderObject[["complete"]] <- self$`complete` } - OrderObject + return(OrderObject) }, #' @description @@ -144,61 +169,13 @@ Order <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Order in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`petId`)) { - sprintf( - '"petId": - %d - ', - self$`petId` - ) - }, - if (!is.null(self$`quantity`)) { - sprintf( - '"quantity": - %d - ', - self$`quantity` - ) - }, - if (!is.null(self$`shipDate`)) { - sprintf( - '"shipDate": - "%s" - ', - self$`shipDate` - ) - }, - if (!is.null(self$`status`)) { - sprintf( - '"status": - "%s" - ', - self$`status` - ) - }, - if (!is.null(self$`complete`)) { - sprintf( - '"complete": - %s - ', - tolower(self$`complete`) - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/pet.R b/samples/client/petstore/R-httr2/R/pet.R index e3f3274dbc834..c3d0bc32fd61f 100644 --- a/samples/client/petstore/R-httr2/R/pet.R +++ b/samples/client/petstore/R-httr2/R/pet.R @@ -75,10 +75,35 @@ Pet <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Pet in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Pet as a base R list. + #' @examples + #' # convert array of Pet (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Pet to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { PetObject <- list() if (!is.null(self$`id`)) { PetObject[["id"]] <- @@ -86,7 +111,7 @@ Pet <- R6::R6Class( } if (!is.null(self$`category`)) { PetObject[["category"]] <- - self$`category`$toJSON() + self$`category`$toSimpleType() } if (!is.null(self$`name`)) { PetObject[["name"]] <- @@ -98,13 +123,13 @@ Pet <- R6::R6Class( } if (!is.null(self$`tags`)) { PetObject[["tags"]] <- - lapply(self$`tags`, function(x) x$toJSON()) + lapply(self$`tags`, function(x) x$toSimpleType()) } if (!is.null(self$`status`)) { PetObject[["status"]] <- self$`status` } - PetObject + return(PetObject) }, #' @description @@ -142,61 +167,13 @@ Pet <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Pet in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`category`)) { - sprintf( - '"category": - %s - ', - jsonlite::toJSON(self$`category`$toJSON(), auto_unbox = TRUE, digits = NA) - ) - }, - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - }, - if (!is.null(self$`photoUrls`)) { - sprintf( - '"photoUrls": - [%s] - ', - paste(unlist(lapply(self$`photoUrls`, function(x) paste0('"', x, '"'))), collapse = ",") - ) - }, - if (!is.null(self$`tags`)) { - sprintf( - '"tags": - [%s] -', - paste(sapply(self$`tags`, function(x) jsonlite::toJSON(x$toJSON(), auto_unbox = TRUE, digits = NA)), collapse = ",") - ) - }, - if (!is.null(self$`status`)) { - sprintf( - '"status": - "%s" - ', - self$`status` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/pet_api.R b/samples/client/petstore/R-httr2/R/pet_api.R index f832c2ea5cbc7..12e65404d9144 100644 --- a/samples/client/petstore/R-httr2/R/pet_api.R +++ b/samples/client/petstore/R-httr2/R/pet_api.R @@ -435,7 +435,7 @@ PetApi <- R6::R6Class( if (!is.null(`pet`)) { local_var_body <- `pet`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/pet" @@ -1288,7 +1288,7 @@ PetApi <- R6::R6Class( if (!is.null(`pet`)) { local_var_body <- `pet`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/pet" diff --git a/samples/client/petstore/R-httr2/R/pet_map.R b/samples/client/petstore/R-httr2/R/pet_map.R index 6a8b62a0a6953..e0e63305d0fda 100644 --- a/samples/client/petstore/R-httr2/R/pet_map.R +++ b/samples/client/petstore/R-httr2/R/pet_map.R @@ -30,16 +30,41 @@ PetMap <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return PetMap in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return PetMap as a base R list. + #' @examples + #' # convert array of PetMap (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert PetMap to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { PetMapObject <- list() if (!is.null(self$`pet`)) { PetMapObject[["pet"]] <- self$`pet` } - PetMapObject + return(PetMapObject) }, #' @description @@ -57,21 +82,13 @@ PetMap <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return PetMap in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`pet`)) { - sprintf( - '"pet": - %s - ', - jsonlite::toJSON(lapply(self$`pet`, function(x){ x }), auto_unbox = TRUE, digits = NA) - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/pig.R b/samples/client/petstore/R-httr2/R/pig.R index 596a9307d4dce..94067ec4d7201 100644 --- a/samples/client/petstore/R-httr2/R/pig.R +++ b/samples/client/petstore/R-httr2/R/pig.R @@ -109,25 +109,35 @@ Pig <- R6::R6Class( #' @description #' Serialize Pig to JSON string. - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return JSON string representation of the Pig. - toJSONString = function() { + toJSONString = function(...) { + simple <- self$toSimpleType() if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify(self$actual_instance$toJSONString())) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) } else { - NULL + return(NULL) } }, #' @description - #' Serialize Pig to JSON. - #' - #' @return JSON representation of the Pig. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert Pig to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() + return(self$actual_instance$toSimpleType()) } else { - NULL + return(NULL) } }, diff --git a/samples/client/petstore/R-httr2/R/special.R b/samples/client/petstore/R-httr2/R/special.R index 4e4250f78d3cd..2e4c8ccdc0cf0 100644 --- a/samples/client/petstore/R-httr2/R/special.R +++ b/samples/client/petstore/R-httr2/R/special.R @@ -87,10 +87,35 @@ Special <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Special in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Special as a base R list. + #' @examples + #' # convert array of Special (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Special to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { SpecialObject <- list() if (!is.null(self$`set_test`)) { SpecialObject[["set_test"]] <- @@ -120,7 +145,7 @@ Special <- R6::R6Class( SpecialObject[["empty_string"]] <- self$`empty_string` } - SpecialObject + return(SpecialObject) }, #' @description @@ -159,69 +184,13 @@ Special <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Special in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`set_test`)) { - sprintf( - '"set_test": - [%s] - ', - paste(unlist(lapply(self$`set_test`, function(x) paste0('"', x, '"'))), collapse = ",") - ) - }, - if (!is.null(self$`item_self`)) { - sprintf( - '"self": - %d - ', - self$`item_self` - ) - }, - if (!is.null(self$`item_private`)) { - sprintf( - '"private": - "%s" - ', - self$`item_private` - ) - }, - if (!is.null(self$`item_super`)) { - sprintf( - '"super": - "%s" - ', - self$`item_super` - ) - }, - if (!is.null(self$`123_number`)) { - sprintf( - '"123_number": - "%s" - ', - self$`123_number` - ) - }, - if (!is.null(self$`array[test]`)) { - sprintf( - '"array[test]": - "%s" - ', - self$`array[test]` - ) - }, - if (!is.null(self$`empty_string`)) { - sprintf( - '"empty_string": - "%s" - ', - self$`empty_string` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/store_api.R b/samples/client/petstore/R-httr2/R/store_api.R index f445fabf3c2b2..fc4ff66dcab1d 100644 --- a/samples/client/petstore/R-httr2/R/store_api.R +++ b/samples/client/petstore/R-httr2/R/store_api.R @@ -546,7 +546,7 @@ StoreApi <- R6::R6Class( if (!is.null(`order`)) { local_var_body <- `order`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/store/order" diff --git a/samples/client/petstore/R-httr2/R/tag.R b/samples/client/petstore/R-httr2/R/tag.R index 574b5c0395af0..96383b87f07f4 100644 --- a/samples/client/petstore/R-httr2/R/tag.R +++ b/samples/client/petstore/R-httr2/R/tag.R @@ -40,10 +40,35 @@ Tag <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Tag in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Tag as a base R list. + #' @examples + #' # convert array of Tag (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Tag to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { TagObject <- list() if (!is.null(self$`id`)) { TagObject[["id"]] <- @@ -53,7 +78,7 @@ Tag <- R6::R6Class( TagObject[["name"]] <- self$`name` } - TagObject + return(TagObject) }, #' @description @@ -74,29 +99,13 @@ Tag <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Tag in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/update_pet_request.R b/samples/client/petstore/R-httr2/R/update_pet_request.R index a5070554b03b5..e42c9a114546f 100644 --- a/samples/client/petstore/R-httr2/R/update_pet_request.R +++ b/samples/client/petstore/R-httr2/R/update_pet_request.R @@ -35,20 +35,45 @@ UpdatePetRequest <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return UpdatePetRequest in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return UpdatePetRequest as a base R list. + #' @examples + #' # convert array of UpdatePetRequest (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert UpdatePetRequest to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { UpdatePetRequestObject <- list() if (!is.null(self$`jsonData`)) { UpdatePetRequestObject[["jsonData"]] <- - self$`jsonData`$toJSON() + self$`jsonData`$toSimpleType() } if (!is.null(self$`binaryDataN2Information`)) { UpdatePetRequestObject[["binaryDataN2Information"]] <- self$`binaryDataN2Information` } - UpdatePetRequestObject + return(UpdatePetRequestObject) }, #' @description @@ -71,29 +96,13 @@ UpdatePetRequest <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return UpdatePetRequest in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`jsonData`)) { - sprintf( - '"jsonData": - %s - ', - jsonlite::toJSON(self$`jsonData`$toJSON(), auto_unbox = TRUE, digits = NA) - ) - }, - if (!is.null(self$`binaryDataN2Information`)) { - sprintf( - '"binaryDataN2Information": - "%s" - ', - self$`binaryDataN2Information` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/user.R b/samples/client/petstore/R-httr2/R/user.R index e7b911abc3123..76c4970a45d65 100644 --- a/samples/client/petstore/R-httr2/R/user.R +++ b/samples/client/petstore/R-httr2/R/user.R @@ -94,10 +94,35 @@ User <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return User in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return User as a base R list. + #' @examples + #' # convert array of User (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert User to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { UserObject <- list() if (!is.null(self$`id`)) { UserObject[["id"]] <- @@ -131,7 +156,7 @@ User <- R6::R6Class( UserObject[["userStatus"]] <- self$`userStatus` } - UserObject + return(UserObject) }, #' @description @@ -170,77 +195,13 @@ User <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return User in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`username`)) { - sprintf( - '"username": - "%s" - ', - self$`username` - ) - }, - if (!is.null(self$`firstName`)) { - sprintf( - '"firstName": - "%s" - ', - self$`firstName` - ) - }, - if (!is.null(self$`lastName`)) { - sprintf( - '"lastName": - "%s" - ', - self$`lastName` - ) - }, - if (!is.null(self$`email`)) { - sprintf( - '"email": - "%s" - ', - self$`email` - ) - }, - if (!is.null(self$`password`)) { - sprintf( - '"password": - "%s" - ', - self$`password` - ) - }, - if (!is.null(self$`phone`)) { - sprintf( - '"phone": - "%s" - ', - self$`phone` - ) - }, - if (!is.null(self$`userStatus`)) { - sprintf( - '"userStatus": - %d - ', - self$`userStatus` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/user_api.R b/samples/client/petstore/R-httr2/R/user_api.R index 9487ca7835b06..a1496d504727b 100644 --- a/samples/client/petstore/R-httr2/R/user_api.R +++ b/samples/client/petstore/R-httr2/R/user_api.R @@ -318,7 +318,7 @@ UserApi <- R6::R6Class( if (!is.null(`user`)) { local_var_body <- `user`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/user" @@ -428,7 +428,7 @@ UserApi <- R6::R6Class( })), collapse = ",") local_var_body <- paste0("[", body.items, "]") } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/user/createWithArray" @@ -538,7 +538,7 @@ UserApi <- R6::R6Class( })), collapse = ",") local_var_body <- paste0("[", body.items, "]") } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/user/createWithList" @@ -1099,7 +1099,7 @@ UserApi <- R6::R6Class( if (!is.null(`user`)) { local_var_body <- `user`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/user/{username}" diff --git a/samples/client/petstore/R-httr2/R/whale.R b/samples/client/petstore/R-httr2/R/whale.R index 4656c11680d5f..fef88a7c63752 100644 --- a/samples/client/petstore/R-httr2/R/whale.R +++ b/samples/client/petstore/R-httr2/R/whale.R @@ -49,10 +49,35 @@ Whale <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Whale in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Whale as a base R list. + #' @examples + #' # convert array of Whale (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Whale to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { WhaleObject <- list() if (!is.null(self$`hasBaleen`)) { WhaleObject[["hasBaleen"]] <- @@ -66,7 +91,7 @@ Whale <- R6::R6Class( WhaleObject[["className"]] <- self$`className` } - WhaleObject + return(WhaleObject) }, #' @description @@ -90,37 +115,13 @@ Whale <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Whale in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`hasBaleen`)) { - sprintf( - '"hasBaleen": - %s - ', - tolower(self$`hasBaleen`) - ) - }, - if (!is.null(self$`hasTeeth`)) { - sprintf( - '"hasTeeth": - %s - ', - tolower(self$`hasTeeth`) - ) - }, - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/R/zebra.R b/samples/client/petstore/R-httr2/R/zebra.R index 95f216c3ce52b..c5165a867082f 100644 --- a/samples/client/petstore/R-httr2/R/zebra.R +++ b/samples/client/petstore/R-httr2/R/zebra.R @@ -43,10 +43,35 @@ Zebra <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Zebra in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Zebra as a base R list. + #' @examples + #' # convert array of Zebra (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Zebra to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { ZebraObject <- list() if (!is.null(self$`type`)) { ZebraObject[["type"]] <- @@ -56,7 +81,7 @@ Zebra <- R6::R6Class( ZebraObject[["className"]] <- self$`className` } - ZebraObject + return(ZebraObject) }, #' @description @@ -80,29 +105,13 @@ Zebra <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Zebra in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`type`)) { - sprintf( - '"type": - "%s" - ', - self$`type` - ) - }, - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) + toJSONString = function(...) { + simple <- self$toSimpleType() + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R-httr2/tests/testthat/test_petstore.R b/samples/client/petstore/R-httr2/tests/testthat/test_petstore.R index b612714b81227..ec1816d3c39df 100644 --- a/samples/client/petstore/R-httr2/tests/testthat/test_petstore.R +++ b/samples/client/petstore/R-httr2/tests/testthat/test_petstore.R @@ -23,7 +23,7 @@ test_that("Test toJSON toJSONString fromJSON fromJSONString", { # tests for other pet objects pet0 <- Pet$new() - jsonpet <- pet0$toJSON() + jsonpet <- pet0$toSimpleType() pet2 <- pet0$fromJSON( jsonlite::toJSON(jsonpet, auto_unbox = TRUE) ) @@ -49,7 +49,7 @@ test_that("Test toJSON toJSONString fromJSON fromJSONString", { ), status = "available" ) - jsonpet <- pet1$toJSON() + jsonpet <- pet1$toSimpleType() pet2 <- pet1$fromJSON( jsonlite::toJSON(jsonpet, auto_unbox = TRUE) ) @@ -71,7 +71,7 @@ test_that("Test toJSON toJSONString fromJSON fromJSONString", { test_that("Test Category", { c1 <- Category$new(id = 450, name = "test_cat") c2 <- Category$new() - c2$fromJSON(jsonlite::toJSON(c1$toJSON(), auto_unbox = TRUE)) + c2$fromJSON(jsonlite::toJSON(c1$toSimpleType(), auto_unbox = TRUE)) expect_equal(c1, c2) c2$fromJSONString(c1$toJSONString()) expect_equal(c1, c2) diff --git a/samples/client/petstore/R/R/allof_tag_api_response.R b/samples/client/petstore/R/R/allof_tag_api_response.R index 454e378a5c16f..018600362d38c 100644 --- a/samples/client/petstore/R/R/allof_tag_api_response.R +++ b/samples/client/petstore/R/R/allof_tag_api_response.R @@ -77,10 +77,35 @@ AllofTagApiResponse <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return AllofTagApiResponse in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return AllofTagApiResponse as a base R list. + #' @examples + #' # convert array of AllofTagApiResponse (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert AllofTagApiResponse to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { AllofTagApiResponseObject <- list() if (!is.null(self$`id`)) { AllofTagApiResponseObject[["id"]] <- @@ -106,7 +131,7 @@ AllofTagApiResponse <- R6::R6Class( AllofTagApiResponseObject[[key]] <- self$additional_properties[[key]] } - AllofTagApiResponseObject + return(AllofTagApiResponseObject) }, #' @description @@ -143,58 +168,16 @@ AllofTagApiResponse <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return AllofTagApiResponse in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - }, - if (!is.null(self$`code`)) { - sprintf( - '"code": - %d - ', - self$`code` - ) - }, - if (!is.null(self$`type`)) { - sprintf( - '"type": - "%s" - ', - self$`type` - ) - }, - if (!is.null(self$`message`)) { - sprintf( - '"message": - "%s" - ', - self$`message` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/animal.R b/samples/client/petstore/R/R/animal.R index 471a01afef3bb..cf2e97f9af306 100644 --- a/samples/client/petstore/R/R/animal.R +++ b/samples/client/petstore/R/R/animal.R @@ -52,10 +52,35 @@ Animal <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Animal in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Animal as a base R list. + #' @examples + #' # convert array of Animal (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Animal to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { AnimalObject <- list() if (!is.null(self$`className`)) { AnimalObject[["className"]] <- @@ -69,7 +94,7 @@ Animal <- R6::R6Class( AnimalObject[[key]] <- self$additional_properties[[key]] } - AnimalObject + return(AnimalObject) }, #' @description @@ -97,34 +122,16 @@ Animal <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Animal in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`color`)) { - sprintf( - '"color": - "%s" - ', - self$`color` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/any_of_pig.R b/samples/client/petstore/R/R/any_of_pig.R index ba3c8ea856d9d..7480eec76961a 100644 --- a/samples/client/petstore/R/R/any_of_pig.R +++ b/samples/client/petstore/R/R/any_of_pig.R @@ -91,27 +91,32 @@ AnyOfPig <- R6::R6Class( }, #' @description - #' Serialize AnyOfPig to JSON string. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. + toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert AnyOfPig to a base R type #' - #' @return JSON string representation of the AnyOfPig. - toJSONString = function() { + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify((self$actual_instance$toJSONString()))) + return(self$actual_instance$toSimpleType()) } else { NULL } }, #' @description - #' Serialize AnyOfPig to JSON. + #' Serialize AnyOfPig to JSON string. #' - #' @return JSON representation of the AnyOfPig. - toJSON = function() { - if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() - } else { - NULL - } + #' @param ... Parameters passed to `jsonlite::toJSON` + #' @return JSON string representation of the AnyOfPig. + toJSONString = function(...) { + json <- jsonlite::toJSON(self$toSimpleType(), auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/any_of_primitive_type_test.R b/samples/client/petstore/R/R/any_of_primitive_type_test.R index 99aa52c734276..f76defe9f4aa5 100644 --- a/samples/client/petstore/R/R/any_of_primitive_type_test.R +++ b/samples/client/petstore/R/R/any_of_primitive_type_test.R @@ -111,25 +111,35 @@ AnyOfPrimitiveTypeTest <- R6::R6Class( #' @description #' Serialize AnyOfPrimitiveTypeTest to JSON string. - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return JSON string representation of the AnyOfPrimitiveTypeTest. - toJSONString = function() { + toJSONString = function(...) { + simple <- self$toSimpleType() if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify(self$actual_instance$toJSONString())) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) } else { - NULL + return(NULL) } }, #' @description - #' Serialize AnyOfPrimitiveTypeTest to JSON. - #' - #' @return JSON representation of the AnyOfPrimitiveTypeTest. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert AnyOfPrimitiveTypeTest to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() + return(self$actual_instance$toSimpleType()) } else { - NULL + return(NULL) } }, diff --git a/samples/client/petstore/R/R/basque_pig.R b/samples/client/petstore/R/R/basque_pig.R index cce82cd7d9323..ca8601f4c3b16 100644 --- a/samples/client/petstore/R/R/basque_pig.R +++ b/samples/client/petstore/R/R/basque_pig.R @@ -50,10 +50,35 @@ BasquePig <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return BasquePig in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return BasquePig as a base R list. + #' @examples + #' # convert array of BasquePig (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert BasquePig to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { BasquePigObject <- list() if (!is.null(self$`className`)) { BasquePigObject[["className"]] <- @@ -67,7 +92,7 @@ BasquePig <- R6::R6Class( BasquePigObject[[key]] <- self$additional_properties[[key]] } - BasquePigObject + return(BasquePigObject) }, #' @description @@ -95,34 +120,16 @@ BasquePig <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return BasquePig in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`color`)) { - sprintf( - '"color": - "%s" - ', - self$`color` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/cat.R b/samples/client/petstore/R/R/cat.R index b4014681ba49a..270b87c21643c 100644 --- a/samples/client/petstore/R/R/cat.R +++ b/samples/client/petstore/R/R/cat.R @@ -60,10 +60,35 @@ Cat <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Cat in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Cat as a base R list. + #' @examples + #' # convert array of Cat (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Cat to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { CatObject <- list() if (!is.null(self$`className`)) { CatObject[["className"]] <- @@ -81,7 +106,7 @@ Cat <- R6::R6Class( CatObject[[key]] <- self$additional_properties[[key]] } - CatObject + return(CatObject) }, #' @description @@ -112,42 +137,16 @@ Cat <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Cat in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`color`)) { - sprintf( - '"color": - "%s" - ', - self$`color` - ) - }, - if (!is.null(self$`declawed`)) { - sprintf( - '"declawed": - %s - ', - tolower(self$`declawed`) - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/category.R b/samples/client/petstore/R/R/category.R index 31106a3bc9e2a..0dcbd1b816109 100644 --- a/samples/client/petstore/R/R/category.R +++ b/samples/client/petstore/R/R/category.R @@ -50,10 +50,35 @@ Category <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Category in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Category as a base R list. + #' @examples + #' # convert array of Category (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Category to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { CategoryObject <- list() if (!is.null(self$`id`)) { CategoryObject[["id"]] <- @@ -67,7 +92,7 @@ Category <- R6::R6Class( CategoryObject[[key]] <- self$additional_properties[[key]] } - CategoryObject + return(CategoryObject) }, #' @description @@ -95,34 +120,16 @@ Category <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Category in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/danish_pig.R b/samples/client/petstore/R/R/danish_pig.R index 08ca2b9e3eea2..02d2208639b02 100644 --- a/samples/client/petstore/R/R/danish_pig.R +++ b/samples/client/petstore/R/R/danish_pig.R @@ -50,10 +50,35 @@ DanishPig <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return DanishPig in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return DanishPig as a base R list. + #' @examples + #' # convert array of DanishPig (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert DanishPig to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { DanishPigObject <- list() if (!is.null(self$`className`)) { DanishPigObject[["className"]] <- @@ -67,7 +92,7 @@ DanishPig <- R6::R6Class( DanishPigObject[[key]] <- self$additional_properties[[key]] } - DanishPigObject + return(DanishPigObject) }, #' @description @@ -95,34 +120,16 @@ DanishPig <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return DanishPig in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`size`)) { - sprintf( - '"size": - %d - ', - self$`size` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/date.R b/samples/client/petstore/R/R/date.R index d9b6ec0beb1be..411249d3fba1b 100644 --- a/samples/client/petstore/R/R/date.R +++ b/samples/client/petstore/R/R/date.R @@ -63,10 +63,35 @@ Date <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Date in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Date as a base R list. + #' @examples + #' # convert array of Date (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Date to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { DateObject <- list() if (!is.null(self$`className`)) { DateObject[["className"]] <- @@ -84,7 +109,7 @@ Date <- R6::R6Class( DateObject[[key]] <- self$additional_properties[[key]] } - DateObject + return(DateObject) }, #' @description @@ -119,42 +144,16 @@ Date <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Date in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`percent_description`)) { - sprintf( - '"percent_description": - "%s" - ', - self$`percent_description` - ) - }, - if (!is.null(self$`url_property`)) { - sprintf( - '"url_property": - "%s" - ', - self$`url_property` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/dog.R b/samples/client/petstore/R/R/dog.R index 34ae291211633..4d6dab71c61bc 100644 --- a/samples/client/petstore/R/R/dog.R +++ b/samples/client/petstore/R/R/dog.R @@ -60,10 +60,35 @@ Dog <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Dog in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Dog as a base R list. + #' @examples + #' # convert array of Dog (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Dog to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { DogObject <- list() if (!is.null(self$`className`)) { DogObject[["className"]] <- @@ -81,7 +106,7 @@ Dog <- R6::R6Class( DogObject[[key]] <- self$additional_properties[[key]] } - DogObject + return(DogObject) }, #' @description @@ -112,42 +137,16 @@ Dog <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Dog in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - }, - if (!is.null(self$`color`)) { - sprintf( - '"color": - "%s" - ', - self$`color` - ) - }, - if (!is.null(self$`breed`)) { - sprintf( - '"breed": - "%s" - ', - self$`breed` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/dummy_model.R b/samples/client/petstore/R/R/dummy_model.R index 12d3ab52a1552..cbea7830b8247 100644 --- a/samples/client/petstore/R/R/dummy_model.R +++ b/samples/client/petstore/R/R/dummy_model.R @@ -41,10 +41,35 @@ DummyModel <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return DummyModel in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return DummyModel as a base R list. + #' @examples + #' # convert array of DummyModel (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert DummyModel to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { DummyModelObject <- list() if (!is.null(self$`property`)) { DummyModelObject[["property"]] <- @@ -54,7 +79,7 @@ DummyModel <- R6::R6Class( DummyModelObject[[key]] <- self$additional_properties[[key]] } - DummyModelObject + return(DummyModelObject) }, #' @description @@ -79,26 +104,16 @@ DummyModel <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return DummyModel in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`property`)) { - sprintf( - '"property": - "%s" - ', - self$`property` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/fake_api.R b/samples/client/petstore/R/R/fake_api.R index ee88e7eba7895..452eab587dedc 100644 --- a/samples/client/petstore/R/R/fake_api.R +++ b/samples/client/petstore/R/R/fake_api.R @@ -225,7 +225,7 @@ FakeApi <- R6::R6Class( if (!is.null(`pet`)) { local_var_body <- `pet`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/fake/test_optional_body_parameter" diff --git a/samples/client/petstore/R/R/format_test.R b/samples/client/petstore/R/R/format_test.R index f93bf1435c9a9..7d1bded3c5a80 100644 --- a/samples/client/petstore/R/R/format_test.R +++ b/samples/client/petstore/R/R/format_test.R @@ -158,10 +158,35 @@ FormatTest <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return FormatTest in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return FormatTest as a base R list. + #' @examples + #' # convert array of FormatTest (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert FormatTest to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { FormatTestObject <- list() if (!is.null(self$`integer`)) { FormatTestObject[["integer"]] <- @@ -227,7 +252,7 @@ FormatTest <- R6::R6Class( FormatTestObject[[key]] <- self$additional_properties[[key]] } - FormatTestObject + return(FormatTestObject) }, #' @description @@ -294,138 +319,16 @@ FormatTest <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return FormatTest in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`integer`)) { - sprintf( - '"integer": - %d - ', - self$`integer` - ) - }, - if (!is.null(self$`int32`)) { - sprintf( - '"int32": - %d - ', - self$`int32` - ) - }, - if (!is.null(self$`int64`)) { - sprintf( - '"int64": - %d - ', - self$`int64` - ) - }, - if (!is.null(self$`number`)) { - sprintf( - '"number": - %d - ', - self$`number` - ) - }, - if (!is.null(self$`float`)) { - sprintf( - '"float": - %d - ', - self$`float` - ) - }, - if (!is.null(self$`double`)) { - sprintf( - '"double": - %d - ', - self$`double` - ) - }, - if (!is.null(self$`string`)) { - sprintf( - '"string": - "%s" - ', - self$`string` - ) - }, - if (!is.null(self$`byte`)) { - sprintf( - '"byte": - "%s" - ', - self$`byte` - ) - }, - if (!is.null(self$`binary`)) { - sprintf( - '"binary": - "%s" - ', - self$`binary` - ) - }, - if (!is.null(self$`date`)) { - sprintf( - '"date": - "%s" - ', - self$`date` - ) - }, - if (!is.null(self$`dateTime`)) { - sprintf( - '"dateTime": - "%s" - ', - self$`dateTime` - ) - }, - if (!is.null(self$`uuid`)) { - sprintf( - '"uuid": - "%s" - ', - self$`uuid` - ) - }, - if (!is.null(self$`password`)) { - sprintf( - '"password": - "%s" - ', - self$`password` - ) - }, - if (!is.null(self$`pattern_with_digits`)) { - sprintf( - '"pattern_with_digits": - "%s" - ', - self$`pattern_with_digits` - ) - }, - if (!is.null(self$`pattern_with_digits_and_delimiter`)) { - sprintf( - '"pattern_with_digits_and_delimiter": - "%s" - ', - self$`pattern_with_digits_and_delimiter` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/mammal.R b/samples/client/petstore/R/R/mammal.R index bbd57ed00acbe..3d93ab765e399 100644 --- a/samples/client/petstore/R/R/mammal.R +++ b/samples/client/petstore/R/R/mammal.R @@ -109,25 +109,35 @@ Mammal <- R6::R6Class( #' @description #' Serialize Mammal to JSON string. - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return JSON string representation of the Mammal. - toJSONString = function() { + toJSONString = function(...) { + simple <- self$toSimpleType() if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify(self$actual_instance$toJSONString())) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) } else { - NULL + return(NULL) } }, #' @description - #' Serialize Mammal to JSON. - #' - #' @return JSON representation of the Mammal. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert Mammal to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() + return(self$actual_instance$toSimpleType()) } else { - NULL + return(NULL) } }, diff --git a/samples/client/petstore/R/R/model_api_response.R b/samples/client/petstore/R/R/model_api_response.R index 9116e438fedc0..a3a46dfb79072 100644 --- a/samples/client/petstore/R/R/model_api_response.R +++ b/samples/client/petstore/R/R/model_api_response.R @@ -59,10 +59,35 @@ ModelApiResponse <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return ModelApiResponse in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return ModelApiResponse as a base R list. + #' @examples + #' # convert array of ModelApiResponse (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert ModelApiResponse to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { ModelApiResponseObject <- list() if (!is.null(self$`code`)) { ModelApiResponseObject[["code"]] <- @@ -80,7 +105,7 @@ ModelApiResponse <- R6::R6Class( ModelApiResponseObject[[key]] <- self$additional_properties[[key]] } - ModelApiResponseObject + return(ModelApiResponseObject) }, #' @description @@ -111,42 +136,16 @@ ModelApiResponse <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return ModelApiResponse in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`code`)) { - sprintf( - '"code": - %d - ', - self$`code` - ) - }, - if (!is.null(self$`type`)) { - sprintf( - '"type": - "%s" - ', - self$`type` - ) - }, - if (!is.null(self$`message`)) { - sprintf( - '"message": - "%s" - ', - self$`message` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/nested_one_of.R b/samples/client/petstore/R/R/nested_one_of.R index e04a31a69acd9..31dcc2f10d01f 100644 --- a/samples/client/petstore/R/R/nested_one_of.R +++ b/samples/client/petstore/R/R/nested_one_of.R @@ -48,10 +48,35 @@ NestedOneOf <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return NestedOneOf in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return NestedOneOf as a base R list. + #' @examples + #' # convert array of NestedOneOf (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert NestedOneOf to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { NestedOneOfObject <- list() if (!is.null(self$`size`)) { NestedOneOfObject[["size"]] <- @@ -59,13 +84,13 @@ NestedOneOf <- R6::R6Class( } if (!is.null(self$`nested_pig`)) { NestedOneOfObject[["nested_pig"]] <- - self$`nested_pig`$toJSON() + self$`nested_pig`$toSimpleType() } for (key in names(self$additional_properties)) { NestedOneOfObject[[key]] <- self$additional_properties[[key]] } - NestedOneOfObject + return(NestedOneOfObject) }, #' @description @@ -95,34 +120,16 @@ NestedOneOf <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return NestedOneOf in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`size`)) { - sprintf( - '"size": - %d - ', - self$`size` - ) - }, - if (!is.null(self$`nested_pig`)) { - sprintf( - '"nested_pig": - %s - ', - jsonlite::toJSON(self$`nested_pig`$toJSON(), auto_unbox = TRUE, digits = NA) - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/one_of_primitive_type_test.R b/samples/client/petstore/R/R/one_of_primitive_type_test.R index 8a9280a9b213f..e5b5669856201 100644 --- a/samples/client/petstore/R/R/one_of_primitive_type_test.R +++ b/samples/client/petstore/R/R/one_of_primitive_type_test.R @@ -111,25 +111,35 @@ OneOfPrimitiveTypeTest <- R6::R6Class( #' @description #' Serialize OneOfPrimitiveTypeTest to JSON string. - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return JSON string representation of the OneOfPrimitiveTypeTest. - toJSONString = function() { + toJSONString = function(...) { + simple <- self$toSimpleType() if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify(self$actual_instance$toJSONString())) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) } else { - NULL + return(NULL) } }, #' @description - #' Serialize OneOfPrimitiveTypeTest to JSON. - #' - #' @return JSON representation of the OneOfPrimitiveTypeTest. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert OneOfPrimitiveTypeTest to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() + return(self$actual_instance$toSimpleType()) } else { - NULL + return(NULL) } }, diff --git a/samples/client/petstore/R/R/order.R b/samples/client/petstore/R/R/order.R index cd84eed74eef0..07378f03666c3 100644 --- a/samples/client/petstore/R/R/order.R +++ b/samples/client/petstore/R/R/order.R @@ -89,10 +89,35 @@ Order <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Order in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Order as a base R list. + #' @examples + #' # convert array of Order (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Order to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { OrderObject <- list() if (!is.null(self$`id`)) { OrderObject[["id"]] <- @@ -122,7 +147,7 @@ Order <- R6::R6Class( OrderObject[[key]] <- self$additional_properties[[key]] } - OrderObject + return(OrderObject) }, #' @description @@ -165,66 +190,16 @@ Order <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Order in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`petId`)) { - sprintf( - '"petId": - %d - ', - self$`petId` - ) - }, - if (!is.null(self$`quantity`)) { - sprintf( - '"quantity": - %d - ', - self$`quantity` - ) - }, - if (!is.null(self$`shipDate`)) { - sprintf( - '"shipDate": - "%s" - ', - self$`shipDate` - ) - }, - if (!is.null(self$`status`)) { - sprintf( - '"status": - "%s" - ', - self$`status` - ) - }, - if (!is.null(self$`complete`)) { - sprintf( - '"complete": - %s - ', - tolower(self$`complete`) - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/pet.R b/samples/client/petstore/R/R/pet.R index 28e1693c419f0..27db68d8fdbdb 100644 --- a/samples/client/petstore/R/R/pet.R +++ b/samples/client/petstore/R/R/pet.R @@ -85,10 +85,35 @@ Pet <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Pet in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Pet as a base R list. + #' @examples + #' # convert array of Pet (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Pet to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { PetObject <- list() if (!is.null(self$`id`)) { PetObject[["id"]] <- @@ -96,7 +121,7 @@ Pet <- R6::R6Class( } if (!is.null(self$`category`)) { PetObject[["category"]] <- - self$`category`$toJSON() + self$`category`$toSimpleType() } if (!is.null(self$`name`)) { PetObject[["name"]] <- @@ -108,7 +133,7 @@ Pet <- R6::R6Class( } if (!is.null(self$`tags`)) { PetObject[["tags"]] <- - lapply(self$`tags`, function(x) x$toJSON()) + lapply(self$`tags`, function(x) x$toSimpleType()) } if (!is.null(self$`status`)) { PetObject[["status"]] <- @@ -118,7 +143,7 @@ Pet <- R6::R6Class( PetObject[[key]] <- self$additional_properties[[key]] } - PetObject + return(PetObject) }, #' @description @@ -163,66 +188,16 @@ Pet <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Pet in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`category`)) { - sprintf( - '"category": - %s - ', - jsonlite::toJSON(self$`category`$toJSON(), auto_unbox = TRUE, digits = NA) - ) - }, - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - }, - if (!is.null(self$`photoUrls`)) { - sprintf( - '"photoUrls": - [%s] - ', - paste(unlist(lapply(self$`photoUrls`, function(x) paste0('"', x, '"'))), collapse = ",") - ) - }, - if (!is.null(self$`tags`)) { - sprintf( - '"tags": - [%s] -', - paste(sapply(self$`tags`, function(x) jsonlite::toJSON(x$toJSON(), auto_unbox = TRUE, digits = NA)), collapse = ",") - ) - }, - if (!is.null(self$`status`)) { - sprintf( - '"status": - "%s" - ', - self$`status` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/pet_api.R b/samples/client/petstore/R/R/pet_api.R index a19e014862905..6c74624fad214 100644 --- a/samples/client/petstore/R/R/pet_api.R +++ b/samples/client/petstore/R/R/pet_api.R @@ -435,7 +435,7 @@ PetApi <- R6::R6Class( if (!is.null(`pet`)) { local_var_body <- `pet`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/pet" @@ -1288,7 +1288,7 @@ PetApi <- R6::R6Class( if (!is.null(`pet`)) { local_var_body <- `pet`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/pet" diff --git a/samples/client/petstore/R/R/pet_map.R b/samples/client/petstore/R/R/pet_map.R index 1fc910ac1da2b..aa59c50a09c06 100644 --- a/samples/client/petstore/R/R/pet_map.R +++ b/samples/client/petstore/R/R/pet_map.R @@ -40,10 +40,35 @@ PetMap <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return PetMap in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return PetMap as a base R list. + #' @examples + #' # convert array of PetMap (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert PetMap to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { PetMapObject <- list() if (!is.null(self$`pet`)) { PetMapObject[["pet"]] <- @@ -53,7 +78,7 @@ PetMap <- R6::R6Class( PetMapObject[[key]] <- self$additional_properties[[key]] } - PetMapObject + return(PetMapObject) }, #' @description @@ -78,26 +103,16 @@ PetMap <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return PetMap in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`pet`)) { - sprintf( - '"pet": - %s - ', - jsonlite::toJSON(lapply(self$`pet`, function(x){ x }), auto_unbox = TRUE, digits = NA) - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/pig.R b/samples/client/petstore/R/R/pig.R index 596a9307d4dce..94067ec4d7201 100644 --- a/samples/client/petstore/R/R/pig.R +++ b/samples/client/petstore/R/R/pig.R @@ -109,25 +109,35 @@ Pig <- R6::R6Class( #' @description #' Serialize Pig to JSON string. - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return JSON string representation of the Pig. - toJSONString = function() { + toJSONString = function(...) { + simple <- self$toSimpleType() if (!is.null(self$actual_instance)) { - as.character(jsonlite::minify(self$actual_instance$toJSONString())) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, ...) + return(as.character(jsonlite::minify(json))) } else { - NULL + return(NULL) } }, #' @description - #' Serialize Pig to JSON. - #' - #' @return JSON representation of the Pig. + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert Pig to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { if (!is.null(self$actual_instance)) { - self$actual_instance$toJSON() + return(self$actual_instance$toSimpleType()) } else { - NULL + return(NULL) } }, diff --git a/samples/client/petstore/R/R/special.R b/samples/client/petstore/R/R/special.R index 5841fc79dd39c..4c27190313fb2 100644 --- a/samples/client/petstore/R/R/special.R +++ b/samples/client/petstore/R/R/special.R @@ -97,10 +97,35 @@ Special <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Special in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Special as a base R list. + #' @examples + #' # convert array of Special (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Special to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { SpecialObject <- list() if (!is.null(self$`set_test`)) { SpecialObject[["set_test"]] <- @@ -134,7 +159,7 @@ Special <- R6::R6Class( SpecialObject[[key]] <- self$additional_properties[[key]] } - SpecialObject + return(SpecialObject) }, #' @description @@ -180,74 +205,16 @@ Special <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Special in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`set_test`)) { - sprintf( - '"set_test": - [%s] - ', - paste(unlist(lapply(self$`set_test`, function(x) paste0('"', x, '"'))), collapse = ",") - ) - }, - if (!is.null(self$`item_self`)) { - sprintf( - '"self": - %d - ', - self$`item_self` - ) - }, - if (!is.null(self$`item_private`)) { - sprintf( - '"private": - "%s" - ', - self$`item_private` - ) - }, - if (!is.null(self$`item_super`)) { - sprintf( - '"super": - "%s" - ', - self$`item_super` - ) - }, - if (!is.null(self$`123_number`)) { - sprintf( - '"123_number": - "%s" - ', - self$`123_number` - ) - }, - if (!is.null(self$`array[test]`)) { - sprintf( - '"array[test]": - "%s" - ', - self$`array[test]` - ) - }, - if (!is.null(self$`empty_string`)) { - sprintf( - '"empty_string": - "%s" - ', - self$`empty_string` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/store_api.R b/samples/client/petstore/R/R/store_api.R index 6889cdf7aa703..81acb942675c5 100644 --- a/samples/client/petstore/R/R/store_api.R +++ b/samples/client/petstore/R/R/store_api.R @@ -546,7 +546,7 @@ StoreApi <- R6::R6Class( if (!is.null(`order`)) { local_var_body <- `order`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/store/order" diff --git a/samples/client/petstore/R/R/tag.R b/samples/client/petstore/R/R/tag.R index c9ec58ae6b82e..b4c893dfe77e5 100644 --- a/samples/client/petstore/R/R/tag.R +++ b/samples/client/petstore/R/R/tag.R @@ -50,10 +50,35 @@ Tag <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Tag in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Tag as a base R list. + #' @examples + #' # convert array of Tag (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Tag to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { TagObject <- list() if (!is.null(self$`id`)) { TagObject[["id"]] <- @@ -67,7 +92,7 @@ Tag <- R6::R6Class( TagObject[[key]] <- self$additional_properties[[key]] } - TagObject + return(TagObject) }, #' @description @@ -95,34 +120,16 @@ Tag <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Tag in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`name`)) { - sprintf( - '"name": - "%s" - ', - self$`name` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/update_pet_request.R b/samples/client/petstore/R/R/update_pet_request.R index 47369030cfac2..3559d3c4d8380 100644 --- a/samples/client/petstore/R/R/update_pet_request.R +++ b/samples/client/petstore/R/R/update_pet_request.R @@ -45,14 +45,39 @@ UpdatePetRequest <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return UpdatePetRequest in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return UpdatePetRequest as a base R list. + #' @examples + #' # convert array of UpdatePetRequest (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert UpdatePetRequest to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { UpdatePetRequestObject <- list() if (!is.null(self$`jsonData`)) { UpdatePetRequestObject[["jsonData"]] <- - self$`jsonData`$toJSON() + self$`jsonData`$toSimpleType() } if (!is.null(self$`binaryDataN2Information`)) { UpdatePetRequestObject[["binaryDataN2Information"]] <- @@ -62,7 +87,7 @@ UpdatePetRequest <- R6::R6Class( UpdatePetRequestObject[[key]] <- self$additional_properties[[key]] } - UpdatePetRequestObject + return(UpdatePetRequestObject) }, #' @description @@ -92,34 +117,16 @@ UpdatePetRequest <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return UpdatePetRequest in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`jsonData`)) { - sprintf( - '"jsonData": - %s - ', - jsonlite::toJSON(self$`jsonData`$toJSON(), auto_unbox = TRUE, digits = NA) - ) - }, - if (!is.null(self$`binaryDataN2Information`)) { - sprintf( - '"binaryDataN2Information": - "%s" - ', - self$`binaryDataN2Information` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/user.R b/samples/client/petstore/R/R/user.R index df4396abb2ca7..361d0d454f210 100644 --- a/samples/client/petstore/R/R/user.R +++ b/samples/client/petstore/R/R/user.R @@ -104,10 +104,35 @@ User <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return User in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return User as a base R list. + #' @examples + #' # convert array of User (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert User to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { UserObject <- list() if (!is.null(self$`id`)) { UserObject[["id"]] <- @@ -145,7 +170,7 @@ User <- R6::R6Class( UserObject[[key]] <- self$additional_properties[[key]] } - UserObject + return(UserObject) }, #' @description @@ -191,82 +216,16 @@ User <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return User in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`id`)) { - sprintf( - '"id": - %d - ', - self$`id` - ) - }, - if (!is.null(self$`username`)) { - sprintf( - '"username": - "%s" - ', - self$`username` - ) - }, - if (!is.null(self$`firstName`)) { - sprintf( - '"firstName": - "%s" - ', - self$`firstName` - ) - }, - if (!is.null(self$`lastName`)) { - sprintf( - '"lastName": - "%s" - ', - self$`lastName` - ) - }, - if (!is.null(self$`email`)) { - sprintf( - '"email": - "%s" - ', - self$`email` - ) - }, - if (!is.null(self$`password`)) { - sprintf( - '"password": - "%s" - ', - self$`password` - ) - }, - if (!is.null(self$`phone`)) { - sprintf( - '"phone": - "%s" - ', - self$`phone` - ) - }, - if (!is.null(self$`userStatus`)) { - sprintf( - '"userStatus": - %d - ', - self$`userStatus` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/user_api.R b/samples/client/petstore/R/R/user_api.R index 389cc69b57e4d..39b793e40f758 100644 --- a/samples/client/petstore/R/R/user_api.R +++ b/samples/client/petstore/R/R/user_api.R @@ -318,7 +318,7 @@ UserApi <- R6::R6Class( if (!is.null(`user`)) { local_var_body <- `user`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/user" @@ -428,7 +428,7 @@ UserApi <- R6::R6Class( })), collapse = ",") local_var_body <- paste0("[", body.items, "]") } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/user/createWithArray" @@ -538,7 +538,7 @@ UserApi <- R6::R6Class( })), collapse = ",") local_var_body <- paste0("[", body.items, "]") } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/user/createWithList" @@ -1099,7 +1099,7 @@ UserApi <- R6::R6Class( if (!is.null(`user`)) { local_var_body <- `user`$toJSONString() } else { - body <- NULL + local_var_body <- NULL } local_var_url_path <- "/user/{username}" diff --git a/samples/client/petstore/R/R/whale.R b/samples/client/petstore/R/R/whale.R index e39211045a76f..ea54d3bdf71c4 100644 --- a/samples/client/petstore/R/R/whale.R +++ b/samples/client/petstore/R/R/whale.R @@ -59,10 +59,35 @@ Whale <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Whale in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Whale as a base R list. + #' @examples + #' # convert array of Whale (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Whale to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { WhaleObject <- list() if (!is.null(self$`hasBaleen`)) { WhaleObject[["hasBaleen"]] <- @@ -80,7 +105,7 @@ Whale <- R6::R6Class( WhaleObject[[key]] <- self$additional_properties[[key]] } - WhaleObject + return(WhaleObject) }, #' @description @@ -111,42 +136,16 @@ Whale <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Whale in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`hasBaleen`)) { - sprintf( - '"hasBaleen": - %s - ', - tolower(self$`hasBaleen`) - ) - }, - if (!is.null(self$`hasTeeth`)) { - sprintf( - '"hasTeeth": - %s - ', - tolower(self$`hasTeeth`) - ) - }, - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/R/zebra.R b/samples/client/petstore/R/R/zebra.R index fb6d90d4d983d..6b85dbff40930 100644 --- a/samples/client/petstore/R/R/zebra.R +++ b/samples/client/petstore/R/R/zebra.R @@ -53,10 +53,35 @@ Zebra <- R6::R6Class( }, #' @description - #' To JSON String - #' - #' @return Zebra in JSON format + #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead. toJSON = function() { + .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string") + return(self$toSimpleType()) + }, + + #' @description + #' Convert to a List + #' + #' Convert the R6 object to a list to work more easily with other tooling. + #' + #' @return Zebra as a base R list. + #' @examples + #' # convert array of Zebra (x) to a data frame + #' \dontrun{ + #' library(purrr) + #' library(tibble) + #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind() + #' df + #' } + toList = function() { + return(self$toSimpleType()) + }, + + #' @description + #' Convert Zebra to a base R type + #' + #' @return A base R type, e.g. a list or numeric/character array. + toSimpleType = function() { ZebraObject <- list() if (!is.null(self$`type`)) { ZebraObject[["type"]] <- @@ -70,7 +95,7 @@ Zebra <- R6::R6Class( ZebraObject[[key]] <- self$additional_properties[[key]] } - ZebraObject + return(ZebraObject) }, #' @description @@ -101,34 +126,16 @@ Zebra <- R6::R6Class( #' @description #' To JSON String - #' + #' + #' @param ... Parameters passed to `jsonlite::toJSON` #' @return Zebra in JSON format - toJSONString = function() { - jsoncontent <- c( - if (!is.null(self$`type`)) { - sprintf( - '"type": - "%s" - ', - self$`type` - ) - }, - if (!is.null(self$`className`)) { - sprintf( - '"className": - "%s" - ', - self$`className` - ) - } - ) - jsoncontent <- paste(jsoncontent, collapse = ",") - json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = ""))) - json_obj <- jsonlite::fromJSON(json_string) + toJSONString = function(...) { + simple <- self$toSimpleType() for (key in names(self$additional_properties)) { - json_obj[[key]] <- self$additional_properties[[key]] + simple[[key]] <- self$additional_properties[[key]] } - json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA))) + json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...) + return(as.character(jsonlite::minify(json))) }, #' @description diff --git a/samples/client/petstore/R/tests/testthat/test_petstore.R b/samples/client/petstore/R/tests/testthat/test_petstore.R index f7a70df4f9d58..641e2cbb27512 100644 --- a/samples/client/petstore/R/tests/testthat/test_petstore.R +++ b/samples/client/petstore/R/tests/testthat/test_petstore.R @@ -42,7 +42,7 @@ test_that("Test FindPetByStatus", { test_that("Test toJSON toJSONString fromJSON fromJSONString", { pet0 <- Pet$new() - jsonpet <- pet0$toJSON() + jsonpet <- pet0$toSimpleType() pet2 <- pet0$fromJSON( jsonlite::toJSON(jsonpet, auto_unbox = TRUE) ) @@ -68,7 +68,7 @@ test_that("Test toJSON toJSONString fromJSON fromJSONString", { ), status = "available" ) - jsonpet <- pet1$toJSON() + jsonpet <- pet1$toSimpleType() pet2 <- pet1$fromJSON( jsonlite::toJSON(jsonpet, auto_unbox = TRUE) ) @@ -90,7 +90,7 @@ test_that("Test toJSON toJSONString fromJSON fromJSONString", { test_that("Test Category", { c1 <- Category$new(id = 450, name = "test_cat") c2 <- Category$new() - c2$fromJSON(jsonlite::toJSON(c1$toJSON(), auto_unbox = TRUE)) + c2$fromJSON(jsonlite::toJSON(c1$toSimpleType(), auto_unbox = TRUE)) expect_equal(c1, c2) c2$fromJSONString(c1$toJSONString()) expect_equal(c1, c2) From 25cfac0523fc661d2915930a29acfb712cbf3024 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 28 Nov 2024 17:20:37 +0800 Subject: [PATCH 09/12] Update r petstore client test script (#20196) * update R build and test script in petstore samples * update --- samples/client/echo_api/r/build_and_test.bash | 2 +- samples/client/petstore/R-httr2-wrapper/build_and_test.bash | 2 +- samples/client/petstore/R-httr2/build_and_test.bash | 2 +- samples/client/petstore/R/build_and_test.bash | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/client/echo_api/r/build_and_test.bash b/samples/client/echo_api/r/build_and_test.bash index 730dd53024a64..40888c9286e51 100644 --- a/samples/client/echo_api/r/build_and_test.bash +++ b/samples/client/echo_api/r/build_and_test.bash @@ -23,4 +23,4 @@ mkdir $R_LIBS_USER || true # R CMD build . R CMD check *tar.gz --no-manual -R CMD install --preclean *tar.gz +R CMD INSTALL --preclean *tar.gz diff --git a/samples/client/petstore/R-httr2-wrapper/build_and_test.bash b/samples/client/petstore/R-httr2-wrapper/build_and_test.bash index 2079f75da032f..90e8fc71c9c87 100644 --- a/samples/client/petstore/R-httr2-wrapper/build_and_test.bash +++ b/samples/client/petstore/R-httr2-wrapper/build_and_test.bash @@ -23,4 +23,4 @@ rm petstore_1.0.0.tar.gz || true R CMD build . R CMD check *tar.gz --no-manual -R CMD install --preclean *tar.gz +R CMD INSTALL --preclean *tar.gz diff --git a/samples/client/petstore/R-httr2/build_and_test.bash b/samples/client/petstore/R-httr2/build_and_test.bash index 2079f75da032f..90e8fc71c9c87 100644 --- a/samples/client/petstore/R-httr2/build_and_test.bash +++ b/samples/client/petstore/R-httr2/build_and_test.bash @@ -23,4 +23,4 @@ rm petstore_1.0.0.tar.gz || true R CMD build . R CMD check *tar.gz --no-manual -R CMD install --preclean *tar.gz +R CMD INSTALL --preclean *tar.gz diff --git a/samples/client/petstore/R/build_and_test.bash b/samples/client/petstore/R/build_and_test.bash index 21baf21970d64..52cd6d1b83861 100644 --- a/samples/client/petstore/R/build_and_test.bash +++ b/samples/client/petstore/R/build_and_test.bash @@ -25,4 +25,4 @@ rm petstore_1.0.0.tar.gz || true R CMD build . R CMD check *tar.gz --no-manual -R CMD install --preclean *tar.gz +R CMD INSTALL --preclean *tar.gz From 326f100f0e4e50f569f43fbceaa5448b407fa8f9 Mon Sep 17 00:00:00 2001 From: Timon Borter Date: Thu, 28 Nov 2024 11:01:37 +0100 Subject: [PATCH 10/12] fix(#20201): static access to normalizeMediaType in typescript object serializer (#20202) accessing `normalizeMediaType` should be done static in `ObjectSerializer`, as described in https://github.com/OpenAPITools/openapi-generator/issues/20201. fix applies only to the `typescript` generator. --- .../main/resources/typescript/model/ObjectSerializer.mustache | 2 +- .../typescript/builds/array-of-lists/models/ObjectSerializer.ts | 2 +- .../builds/enum-single-value/models/ObjectSerializer.ts | 2 +- .../builds/null-types-simple/models/ObjectSerializer.ts | 2 +- .../builds/with-unique-items/models/ObjectSerializer.ts | 2 +- .../typescript/encode-decode/build/models/ObjectSerializer.ts | 2 +- .../typescript/builds/browser/models/ObjectSerializer.ts | 2 +- .../builds/composed-schemas/models/ObjectSerializer.ts | 2 +- .../typescript/builds/default/models/ObjectSerializer.ts | 2 +- .../petstore/typescript/builds/deno/models/ObjectSerializer.ts | 2 +- .../builds/deno_object_params/models/ObjectSerializer.ts | 2 +- .../typescript/builds/explode-query/models/ObjectSerializer.ts | 2 +- .../typescript/builds/inversify/models/ObjectSerializer.ts | 2 +- .../typescript/builds/jquery/models/ObjectSerializer.ts | 2 +- .../typescript/builds/nullable-enum/models/ObjectSerializer.ts | 2 +- .../typescript/builds/object_params/models/ObjectSerializer.ts | 2 +- 16 files changed, 16 insertions(+), 16 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/typescript/model/ObjectSerializer.mustache b/modules/openapi-generator/src/main/resources/typescript/model/ObjectSerializer.mustache index 53bf799186d16..9cfa5b3475f02 100644 --- a/modules/openapi-generator/src/main/resources/typescript/model/ObjectSerializer.mustache +++ b/modules/openapi-generator/src/main/resources/typescript/model/ObjectSerializer.mustache @@ -287,7 +287,7 @@ export class ObjectSerializer { return "application/json"; } - const normalMediaTypes = mediaTypes.map(this.normalizeMediaType); + const normalMediaTypes = mediaTypes.map(ObjectSerializer.normalizeMediaType); for (const predicate of supportedMimeTypePredicatesWithPriority) { for (const mediaType of normalMediaTypes) { diff --git a/samples/client/others/typescript/builds/array-of-lists/models/ObjectSerializer.ts b/samples/client/others/typescript/builds/array-of-lists/models/ObjectSerializer.ts index 6e6185206e0ed..3d607eb960ef6 100644 --- a/samples/client/others/typescript/builds/array-of-lists/models/ObjectSerializer.ts +++ b/samples/client/others/typescript/builds/array-of-lists/models/ObjectSerializer.ts @@ -262,7 +262,7 @@ export class ObjectSerializer { return "application/json"; } - const normalMediaTypes = mediaTypes.map(this.normalizeMediaType); + const normalMediaTypes = mediaTypes.map(ObjectSerializer.normalizeMediaType); for (const predicate of supportedMimeTypePredicatesWithPriority) { for (const mediaType of normalMediaTypes) { diff --git a/samples/client/others/typescript/builds/enum-single-value/models/ObjectSerializer.ts b/samples/client/others/typescript/builds/enum-single-value/models/ObjectSerializer.ts index 52f66a587fdfd..15b6c13639d3b 100644 --- a/samples/client/others/typescript/builds/enum-single-value/models/ObjectSerializer.ts +++ b/samples/client/others/typescript/builds/enum-single-value/models/ObjectSerializer.ts @@ -264,7 +264,7 @@ export class ObjectSerializer { return "application/json"; } - const normalMediaTypes = mediaTypes.map(this.normalizeMediaType); + const normalMediaTypes = mediaTypes.map(ObjectSerializer.normalizeMediaType); for (const predicate of supportedMimeTypePredicatesWithPriority) { for (const mediaType of normalMediaTypes) { diff --git a/samples/client/others/typescript/builds/null-types-simple/models/ObjectSerializer.ts b/samples/client/others/typescript/builds/null-types-simple/models/ObjectSerializer.ts index 5419a192b738e..d44f397943e33 100644 --- a/samples/client/others/typescript/builds/null-types-simple/models/ObjectSerializer.ts +++ b/samples/client/others/typescript/builds/null-types-simple/models/ObjectSerializer.ts @@ -262,7 +262,7 @@ export class ObjectSerializer { return "application/json"; } - const normalMediaTypes = mediaTypes.map(this.normalizeMediaType); + const normalMediaTypes = mediaTypes.map(ObjectSerializer.normalizeMediaType); for (const predicate of supportedMimeTypePredicatesWithPriority) { for (const mediaType of normalMediaTypes) { diff --git a/samples/client/others/typescript/builds/with-unique-items/models/ObjectSerializer.ts b/samples/client/others/typescript/builds/with-unique-items/models/ObjectSerializer.ts index 5720a08e7f625..6040ede547f6f 100644 --- a/samples/client/others/typescript/builds/with-unique-items/models/ObjectSerializer.ts +++ b/samples/client/others/typescript/builds/with-unique-items/models/ObjectSerializer.ts @@ -259,7 +259,7 @@ export class ObjectSerializer { return "application/json"; } - const normalMediaTypes = mediaTypes.map(this.normalizeMediaType); + const normalMediaTypes = mediaTypes.map(ObjectSerializer.normalizeMediaType); for (const predicate of supportedMimeTypePredicatesWithPriority) { for (const mediaType of normalMediaTypes) { diff --git a/samples/client/others/typescript/encode-decode/build/models/ObjectSerializer.ts b/samples/client/others/typescript/encode-decode/build/models/ObjectSerializer.ts index 44d6f6ab66809..59eea6798cc59 100644 --- a/samples/client/others/typescript/encode-decode/build/models/ObjectSerializer.ts +++ b/samples/client/others/typescript/encode-decode/build/models/ObjectSerializer.ts @@ -262,7 +262,7 @@ export class ObjectSerializer { return "application/json"; } - const normalMediaTypes = mediaTypes.map(this.normalizeMediaType); + const normalMediaTypes = mediaTypes.map(ObjectSerializer.normalizeMediaType); for (const predicate of supportedMimeTypePredicatesWithPriority) { for (const mediaType of normalMediaTypes) { diff --git a/samples/openapi3/client/petstore/typescript/builds/browser/models/ObjectSerializer.ts b/samples/openapi3/client/petstore/typescript/builds/browser/models/ObjectSerializer.ts index d91174d51316b..2f297efed7573 100644 --- a/samples/openapi3/client/petstore/typescript/builds/browser/models/ObjectSerializer.ts +++ b/samples/openapi3/client/petstore/typescript/builds/browser/models/ObjectSerializer.ts @@ -276,7 +276,7 @@ export class ObjectSerializer { return "application/json"; } - const normalMediaTypes = mediaTypes.map(this.normalizeMediaType); + const normalMediaTypes = mediaTypes.map(ObjectSerializer.normalizeMediaType); for (const predicate of supportedMimeTypePredicatesWithPriority) { for (const mediaType of normalMediaTypes) { diff --git a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/ObjectSerializer.ts b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/ObjectSerializer.ts index 241ae2d78de72..1f3c61a072cad 100644 --- a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/ObjectSerializer.ts +++ b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/ObjectSerializer.ts @@ -281,7 +281,7 @@ export class ObjectSerializer { return "application/json"; } - const normalMediaTypes = mediaTypes.map(this.normalizeMediaType); + const normalMediaTypes = mediaTypes.map(ObjectSerializer.normalizeMediaType); for (const predicate of supportedMimeTypePredicatesWithPriority) { for (const mediaType of normalMediaTypes) { diff --git a/samples/openapi3/client/petstore/typescript/builds/default/models/ObjectSerializer.ts b/samples/openapi3/client/petstore/typescript/builds/default/models/ObjectSerializer.ts index d91174d51316b..2f297efed7573 100644 --- a/samples/openapi3/client/petstore/typescript/builds/default/models/ObjectSerializer.ts +++ b/samples/openapi3/client/petstore/typescript/builds/default/models/ObjectSerializer.ts @@ -276,7 +276,7 @@ export class ObjectSerializer { return "application/json"; } - const normalMediaTypes = mediaTypes.map(this.normalizeMediaType); + const normalMediaTypes = mediaTypes.map(ObjectSerializer.normalizeMediaType); for (const predicate of supportedMimeTypePredicatesWithPriority) { for (const mediaType of normalMediaTypes) { diff --git a/samples/openapi3/client/petstore/typescript/builds/deno/models/ObjectSerializer.ts b/samples/openapi3/client/petstore/typescript/builds/deno/models/ObjectSerializer.ts index b73337a352022..60e339c8ae084 100644 --- a/samples/openapi3/client/petstore/typescript/builds/deno/models/ObjectSerializer.ts +++ b/samples/openapi3/client/petstore/typescript/builds/deno/models/ObjectSerializer.ts @@ -276,7 +276,7 @@ export class ObjectSerializer { return "application/json"; } - const normalMediaTypes = mediaTypes.map(this.normalizeMediaType); + const normalMediaTypes = mediaTypes.map(ObjectSerializer.normalizeMediaType); for (const predicate of supportedMimeTypePredicatesWithPriority) { for (const mediaType of normalMediaTypes) { diff --git a/samples/openapi3/client/petstore/typescript/builds/deno_object_params/models/ObjectSerializer.ts b/samples/openapi3/client/petstore/typescript/builds/deno_object_params/models/ObjectSerializer.ts index b73337a352022..60e339c8ae084 100644 --- a/samples/openapi3/client/petstore/typescript/builds/deno_object_params/models/ObjectSerializer.ts +++ b/samples/openapi3/client/petstore/typescript/builds/deno_object_params/models/ObjectSerializer.ts @@ -276,7 +276,7 @@ export class ObjectSerializer { return "application/json"; } - const normalMediaTypes = mediaTypes.map(this.normalizeMediaType); + const normalMediaTypes = mediaTypes.map(ObjectSerializer.normalizeMediaType); for (const predicate of supportedMimeTypePredicatesWithPriority) { for (const mediaType of normalMediaTypes) { diff --git a/samples/openapi3/client/petstore/typescript/builds/explode-query/models/ObjectSerializer.ts b/samples/openapi3/client/petstore/typescript/builds/explode-query/models/ObjectSerializer.ts index 4b95a65872ba3..97cbc6966a85d 100644 --- a/samples/openapi3/client/petstore/typescript/builds/explode-query/models/ObjectSerializer.ts +++ b/samples/openapi3/client/petstore/typescript/builds/explode-query/models/ObjectSerializer.ts @@ -406,7 +406,7 @@ export class ObjectSerializer { return "application/json"; } - const normalMediaTypes = mediaTypes.map(this.normalizeMediaType); + const normalMediaTypes = mediaTypes.map(ObjectSerializer.normalizeMediaType); for (const predicate of supportedMimeTypePredicatesWithPriority) { for (const mediaType of normalMediaTypes) { diff --git a/samples/openapi3/client/petstore/typescript/builds/inversify/models/ObjectSerializer.ts b/samples/openapi3/client/petstore/typescript/builds/inversify/models/ObjectSerializer.ts index d91174d51316b..2f297efed7573 100644 --- a/samples/openapi3/client/petstore/typescript/builds/inversify/models/ObjectSerializer.ts +++ b/samples/openapi3/client/petstore/typescript/builds/inversify/models/ObjectSerializer.ts @@ -276,7 +276,7 @@ export class ObjectSerializer { return "application/json"; } - const normalMediaTypes = mediaTypes.map(this.normalizeMediaType); + const normalMediaTypes = mediaTypes.map(ObjectSerializer.normalizeMediaType); for (const predicate of supportedMimeTypePredicatesWithPriority) { for (const mediaType of normalMediaTypes) { diff --git a/samples/openapi3/client/petstore/typescript/builds/jquery/models/ObjectSerializer.ts b/samples/openapi3/client/petstore/typescript/builds/jquery/models/ObjectSerializer.ts index d91174d51316b..2f297efed7573 100644 --- a/samples/openapi3/client/petstore/typescript/builds/jquery/models/ObjectSerializer.ts +++ b/samples/openapi3/client/petstore/typescript/builds/jquery/models/ObjectSerializer.ts @@ -276,7 +276,7 @@ export class ObjectSerializer { return "application/json"; } - const normalMediaTypes = mediaTypes.map(this.normalizeMediaType); + const normalMediaTypes = mediaTypes.map(ObjectSerializer.normalizeMediaType); for (const predicate of supportedMimeTypePredicatesWithPriority) { for (const mediaType of normalMediaTypes) { diff --git a/samples/openapi3/client/petstore/typescript/builds/nullable-enum/models/ObjectSerializer.ts b/samples/openapi3/client/petstore/typescript/builds/nullable-enum/models/ObjectSerializer.ts index 134a7cf943942..b7087b6774a84 100644 --- a/samples/openapi3/client/petstore/typescript/builds/nullable-enum/models/ObjectSerializer.ts +++ b/samples/openapi3/client/petstore/typescript/builds/nullable-enum/models/ObjectSerializer.ts @@ -260,7 +260,7 @@ export class ObjectSerializer { return "application/json"; } - const normalMediaTypes = mediaTypes.map(this.normalizeMediaType); + const normalMediaTypes = mediaTypes.map(ObjectSerializer.normalizeMediaType); for (const predicate of supportedMimeTypePredicatesWithPriority) { for (const mediaType of normalMediaTypes) { diff --git a/samples/openapi3/client/petstore/typescript/builds/object_params/models/ObjectSerializer.ts b/samples/openapi3/client/petstore/typescript/builds/object_params/models/ObjectSerializer.ts index d91174d51316b..2f297efed7573 100644 --- a/samples/openapi3/client/petstore/typescript/builds/object_params/models/ObjectSerializer.ts +++ b/samples/openapi3/client/petstore/typescript/builds/object_params/models/ObjectSerializer.ts @@ -276,7 +276,7 @@ export class ObjectSerializer { return "application/json"; } - const normalMediaTypes = mediaTypes.map(this.normalizeMediaType); + const normalMediaTypes = mediaTypes.map(ObjectSerializer.normalizeMediaType); for (const predicate of supportedMimeTypePredicatesWithPriority) { for (const mediaType of normalMediaTypes) { From 34bd02109e9df553546020d25e8f134fed0f3196 Mon Sep 17 00:00:00 2001 From: Thomas Ville Date: Fri, 29 Nov 2024 10:07:30 +0100 Subject: [PATCH 11/12] [rust][reqwest] support binary type for download (#20031) * [rust][reqwest] support binary type for upload and download * [rust][reqwest] support binary download in supportMultipleResponses contexts * [rust][reqwest] support binary responses that don't have any return type --- .../main/resources/rust/reqwest/api.mustache | 23 +++++++++++++++--- .../src/apis/default_api.rs | 3 ++- .../src/apis/default_api.rs | 2 +- .../composed-oneof/src/apis/default_api.rs | 5 ++-- .../emptyObject/src/apis/default_api.rs | 3 ++- .../oneOf-array-map/src/apis/default_api.rs | 5 ++-- .../oneOf-reuseRef/src/apis/default_api.rs | 3 ++- .../rust/reqwest/oneOf/src/apis/bar_api.rs | 3 ++- .../rust/reqwest/oneOf/src/apis/foo_api.rs | 6 +++-- .../reqwest/name-mapping/src/apis/fake_api.rs | 2 +- .../src/apis/fake_api.rs | 3 ++- .../src/apis/pet_api.rs | 24 ++++++++++++------- .../src/apis/store_api.rs | 12 ++++++---- .../src/apis/testing_api.rs | 11 ++++----- .../src/apis/user_api.rs | 24 ++++++++++++------- .../src/apis/fake_api.rs | 3 ++- .../src/apis/pet_api.rs | 24 ++++++++++++------- .../src/apis/store_api.rs | 12 ++++++---- .../src/apis/testing_api.rs | 11 ++++----- .../src/apis/user_api.rs | 24 ++++++++++++------- .../petstore-async/src/apis/fake_api.rs | 3 ++- .../petstore-async/src/apis/pet_api.rs | 24 ++++++++++++------- .../petstore-async/src/apis/store_api.rs | 12 ++++++---- .../petstore-async/src/apis/testing_api.rs | 11 ++++----- .../petstore-async/src/apis/user_api.rs | 24 ++++++++++++------- .../petstore-avoid-box/src/apis/fake_api.rs | 3 ++- .../petstore-avoid-box/src/apis/pet_api.rs | 24 ++++++++++++------- .../petstore-avoid-box/src/apis/store_api.rs | 12 ++++++---- .../src/apis/testing_api.rs | 11 ++++----- .../petstore-avoid-box/src/apis/user_api.rs | 24 ++++++++++++------- .../src/apis/fake_api.rs | 2 +- .../src/apis/pet_api.rs | 22 ++++++++++------- .../src/apis/store_api.rs | 11 +++++---- .../src/apis/testing_api.rs | 9 +++---- .../src/apis/user_api.rs | 18 +++++++------- .../src/apis/fake_api.rs | 2 +- .../src/apis/pet_api.rs | 22 ++++++++++------- .../src/apis/store_api.rs | 11 +++++---- .../src/apis/testing_api.rs | 9 +++---- .../src/apis/user_api.rs | 18 +++++++------- .../reqwest/petstore/src/apis/fake_api.rs | 2 +- .../rust/reqwest/petstore/src/apis/pet_api.rs | 22 ++++++++++------- .../reqwest/petstore/src/apis/store_api.rs | 11 +++++---- .../reqwest/petstore/src/apis/testing_api.rs | 9 +++---- .../reqwest/petstore/src/apis/user_api.rs | 18 +++++++------- 45 files changed, 339 insertions(+), 198 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache b/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache index dc0cf75205c0b..b96063531e616 100644 --- a/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache +++ b/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache @@ -80,7 +80,7 @@ pub enum {{{operationIdCamelCase}}}Error { /// {{{.}}} {{/notes}} {{#vendorExtensions.x-group-parameters}} -pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: &configuration::Configuration{{#allParams}}{{#-first}}, params: {{{operationIdCamelCase}}}Params{{/-first}}{{/allParams}}) -> Result<{{#supportMultipleResponses}}ResponseContent<{{{operationIdCamelCase}}}Success>{{/supportMultipleResponses}}{{^supportMultipleResponses}}{{^returnType}}(){{/returnType}}{{{returnType}}}{{/supportMultipleResponses}}, Error<{{{operationIdCamelCase}}}Error>> { +pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: &configuration::Configuration{{#allParams}}{{#-first}}, params: {{{operationIdCamelCase}}}Params{{/-first}}{{/allParams}}) -> Result<{{#isResponseFile}}{{#supportAsync}}reqwest::Response{{/supportAsync}}{{^supportAsync}}reqwest::blocking::Response{{/supportAsync}}{{/isResponseFile}}{{^isResponseFile}}{{#supportMultipleResponses}}ResponseContent<{{{operationIdCamelCase}}}Success>{{/supportMultipleResponses}}{{^supportMultipleResponses}}{{^returnType}}(){{/returnType}}{{{returnType}}}{{/supportMultipleResponses}}{{/isResponseFile}}, Error<{{{operationIdCamelCase}}}Error>> { let local_var_configuration = configuration; // unbox the parameters @@ -90,7 +90,7 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: {{/vendorExtensions.x-group-parameters}} {{^vendorExtensions.x-group-parameters}} -pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: &configuration::Configuration, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}{{#isArray}}Vec<{{/isArray}}{{^isUuid}}&str{{/isUuid}}{{#isArray}}>{{/isArray}}{{/isString}}{{#isUuid}}{{#isArray}}Vec<{{/isArray}}&str{{#isArray}}>{{/isArray}}{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) -> Result<{{#supportMultipleResponses}}ResponseContent<{{{operationIdCamelCase}}}Success>{{/supportMultipleResponses}}{{^supportMultipleResponses}}{{^returnType}}(){{/returnType}}{{{returnType}}}{{/supportMultipleResponses}}, Error<{{{operationIdCamelCase}}}Error>> { +pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: &configuration::Configuration, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}{{#isArray}}Vec<{{/isArray}}{{^isUuid}}&str{{/isUuid}}{{#isArray}}>{{/isArray}}{{/isString}}{{#isUuid}}{{#isArray}}Vec<{{/isArray}}&str{{#isArray}}>{{/isArray}}{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) -> Result<{{#isResponseFile}}{{#supportAsync}}reqwest::Response{{/supportAsync}}{{^supportAsync}}reqwest::blocking::Response{{/supportAsync}}{{/isResponseFile}}{{^isResponseFile}}{{#supportMultipleResponses}}ResponseContent<{{{operationIdCamelCase}}}Success>{{/supportMultipleResponses}}{{^supportMultipleResponses}}{{^returnType}}(){{/returnType}}{{{returnType}}}{{/supportMultipleResponses}}{{/isResponseFile}}, Error<{{{operationIdCamelCase}}}Error>> { let local_var_configuration = configuration; {{/vendorExtensions.x-group-parameters}} @@ -346,7 +346,12 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: {{/isMultipart}} {{#hasBodyParam}} {{#bodyParams}} + {{#isFile}} + local_var_req_builder = local_var_req_builder.body({{{paramName}}}); + {{/isFile}} + {{^isFile}} local_var_req_builder = local_var_req_builder.json(&{{{paramName}}}); + {{/isFile}} {{/bodyParams}} {{/hasBodyParam}} @@ -354,23 +359,35 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: let local_var_resp = local_var_client.execute(local_var_req){{#supportAsync}}.await{{/supportAsync}}?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text(){{#supportAsync}}.await{{/supportAsync}}?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { {{^supportMultipleResponses}} + {{#isResponseFile}} + Ok(local_var_resp) + {{/isResponseFile}} + {{^isResponseFile}} {{^returnType}} Ok(()) {{/returnType}} {{#returnType}} + let local_var_content = local_var_resp.text(){{#supportAsync}}.await{{/supportAsync}}?; serde_json::from_str(&local_var_content).map_err(Error::from) {{/returnType}} + {{/isResponseFile}} {{/supportMultipleResponses}} {{#supportMultipleResponses}} + {{#isResponseFile}} + Ok(local_var_resp) + {{/isResponseFile}} + {{^isResponseFile}} + let local_var_content = local_var_resp.text(){{#supportAsync}}.await{{/supportAsync}}?; let local_var_entity: Option<{{{operationIdCamelCase}}}Success> = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) + {{/isResponseFile}} {{/supportMultipleResponses}} } else { + let local_var_content = local_var_resp.text(){{#supportAsync}}.await{{/supportAsync}}?; let local_var_entity: Option<{{{operationIdCamelCase}}}Error> = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/others/rust/reqwest-regression-16119/src/apis/default_api.rs b/samples/client/others/rust/reqwest-regression-16119/src/apis/default_api.rs index 3886a83c95439..bea5f638a6e79 100644 --- a/samples/client/others/rust/reqwest-regression-16119/src/apis/default_api.rs +++ b/samples/client/others/rust/reqwest-regression-16119/src/apis/default_api.rs @@ -39,11 +39,12 @@ pub fn repro(configuration: &configuration::Configuration, ) -> Result = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/others/rust/reqwest/api-with-ref-param/src/apis/default_api.rs b/samples/client/others/rust/reqwest/api-with-ref-param/src/apis/default_api.rs index 27a37acccf490..179f9ea5c141f 100644 --- a/samples/client/others/rust/reqwest/api-with-ref-param/src/apis/default_api.rs +++ b/samples/client/others/rust/reqwest/api-with-ref-param/src/apis/default_api.rs @@ -39,11 +39,11 @@ pub async fn demo_color_get(configuration: &configuration::Configuration, color: let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/others/rust/reqwest/composed-oneof/src/apis/default_api.rs b/samples/client/others/rust/reqwest/composed-oneof/src/apis/default_api.rs index 59d4035053a91..c0def694ddee6 100644 --- a/samples/client/others/rust/reqwest/composed-oneof/src/apis/default_api.rs +++ b/samples/client/others/rust/reqwest/composed-oneof/src/apis/default_api.rs @@ -47,11 +47,11 @@ pub fn create_state(configuration: &configuration::Configuration, create_state_r let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -74,11 +74,12 @@ pub fn get_state(configuration: &configuration::Configuration, ) -> Result = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/others/rust/reqwest/emptyObject/src/apis/default_api.rs b/samples/client/others/rust/reqwest/emptyObject/src/apis/default_api.rs index 5f5b46edc2c80..54b21d9c0766f 100644 --- a/samples/client/others/rust/reqwest/emptyObject/src/apis/default_api.rs +++ b/samples/client/others/rust/reqwest/emptyObject/src/apis/default_api.rs @@ -39,11 +39,12 @@ pub fn endpoint_get(configuration: &configuration::Configuration, ) -> Result = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/others/rust/reqwest/oneOf-array-map/src/apis/default_api.rs b/samples/client/others/rust/reqwest/oneOf-array-map/src/apis/default_api.rs index c487220374ea5..9fc93a60045b4 100644 --- a/samples/client/others/rust/reqwest/oneOf-array-map/src/apis/default_api.rs +++ b/samples/client/others/rust/reqwest/oneOf-array-map/src/apis/default_api.rs @@ -46,11 +46,12 @@ pub fn root_get(configuration: &configuration::Configuration, ) -> Result = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -74,11 +75,11 @@ pub fn test(configuration: &configuration::Configuration, body: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/others/rust/reqwest/oneOf-reuseRef/src/apis/default_api.rs b/samples/client/others/rust/reqwest/oneOf-reuseRef/src/apis/default_api.rs index 035872574bf6c..3287c9177b3e8 100644 --- a/samples/client/others/rust/reqwest/oneOf-reuseRef/src/apis/default_api.rs +++ b/samples/client/others/rust/reqwest/oneOf-reuseRef/src/apis/default_api.rs @@ -39,11 +39,12 @@ pub fn get_fruit(configuration: &configuration::Configuration, ) -> Result = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/others/rust/reqwest/oneOf/src/apis/bar_api.rs b/samples/client/others/rust/reqwest/oneOf/src/apis/bar_api.rs index f8ce13d5cac64..fc6b75d5ebcd1 100644 --- a/samples/client/others/rust/reqwest/oneOf/src/apis/bar_api.rs +++ b/samples/client/others/rust/reqwest/oneOf/src/apis/bar_api.rs @@ -40,11 +40,12 @@ pub fn create_bar(configuration: &configuration::Configuration, bar_create: mode let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/others/rust/reqwest/oneOf/src/apis/foo_api.rs b/samples/client/others/rust/reqwest/oneOf/src/apis/foo_api.rs index 202e6bb667939..cdcd1feaf2a50 100644 --- a/samples/client/others/rust/reqwest/oneOf/src/apis/foo_api.rs +++ b/samples/client/others/rust/reqwest/oneOf/src/apis/foo_api.rs @@ -47,11 +47,12 @@ pub fn create_foo(configuration: &configuration::Configuration, foo: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -74,11 +75,12 @@ pub fn get_all_foos(configuration: &configuration::Configuration, ) -> Result = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/name-mapping/src/apis/fake_api.rs b/samples/client/petstore/rust/reqwest/name-mapping/src/apis/fake_api.rs index e7f8c27a8f05c..1dd40a13d980b 100644 --- a/samples/client/petstore/rust/reqwest/name-mapping/src/apis/fake_api.rs +++ b/samples/client/petstore/rust/reqwest/name-mapping/src/apis/fake_api.rs @@ -44,11 +44,11 @@ pub fn get_parameter_name_mapping(configuration: &configuration::Configuration, let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/fake_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/fake_api.rs index 3f10b5b6c2af9..f93b447840dae 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/fake_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/fake_api.rs @@ -74,13 +74,14 @@ pub async fn test_nullable_required_param(configuration: &configuration::Configu let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/pet_api.rs index 0a44b19a32ddf..471556f03bd7e 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/pet_api.rs @@ -234,13 +234,14 @@ pub async fn add_pet(configuration: &configuration::Configuration, params: AddPe let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -275,13 +276,14 @@ pub async fn delete_pet(configuration: &configuration::Configuration, params: De let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -316,13 +318,14 @@ pub async fn find_pets_by_status(configuration: &configuration::Configuration, p let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -357,13 +360,14 @@ pub async fn find_pets_by_tags(configuration: &configuration::Configuration, par let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -399,13 +403,14 @@ pub async fn get_pet_by_id(configuration: &configuration::Configuration, params: let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -437,13 +442,14 @@ pub async fn update_pet(configuration: &configuration::Configuration, params: Up let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -484,13 +490,14 @@ pub async fn update_pet_with_form(configuration: &configuration::Configuration, let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -529,13 +536,14 @@ pub async fn upload_file(configuration: &configuration::Configuration, params: U let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/store_api.rs index 67fd03a80f545..340e6f2dc97cc 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/store_api.rs @@ -122,13 +122,14 @@ pub async fn delete_order(configuration: &configuration::Configuration, params: let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -163,13 +164,14 @@ pub async fn get_inventory(configuration: &configuration::Configuration) -> Resu let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -197,13 +199,14 @@ pub async fn get_order_by_id(configuration: &configuration::Configuration, param let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -232,13 +235,14 @@ pub async fn place_order(configuration: &configuration::Configuration, params: P let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/testing_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/testing_api.rs index 83d1a00fb4cec..0dafccec4b728 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/testing_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/testing_api.rs @@ -46,7 +46,7 @@ pub enum TestsTypeTestingGetError { } -pub async fn tests_file_response_get(configuration: &configuration::Configuration) -> Result, Error> { +pub async fn tests_file_response_get(configuration: &configuration::Configuration) -> Result> { let local_var_configuration = configuration; // unbox the parameters @@ -65,13 +65,11 @@ pub async fn tests_file_response_get(configuration: &configuration::Configuratio let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { - let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); - let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; - Ok(local_var_result) + Ok(local_var_resp) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -97,13 +95,14 @@ pub async fn tests_type_testing_get(configuration: &configuration::Configuration let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/user_api.rs index 4f28c21c1cf3a..985f3b65e3173 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/user_api.rs @@ -224,13 +224,14 @@ pub async fn create_user(configuration: &configuration::Configuration, params: C let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -267,13 +268,14 @@ pub async fn create_users_with_array_input(configuration: &configuration::Config let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -310,13 +312,14 @@ pub async fn create_users_with_list_input(configuration: &configuration::Configu let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -352,13 +355,14 @@ pub async fn delete_user(configuration: &configuration::Configuration, params: D let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -386,13 +390,14 @@ pub async fn get_user_by_name(configuration: &configuration::Configuration, para let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -423,13 +428,14 @@ pub async fn login_user(configuration: &configuration::Configuration, params: Lo let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -464,13 +470,14 @@ pub async fn logout_user(configuration: &configuration::Configuration) -> Result let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -508,13 +515,14 @@ pub async fn update_user(configuration: &configuration::Configuration, params: U let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/fake_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/fake_api.rs index 3f10b5b6c2af9..f93b447840dae 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/fake_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/fake_api.rs @@ -74,13 +74,14 @@ pub async fn test_nullable_required_param(configuration: &configuration::Configu let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/pet_api.rs index 7901fb0c40d9a..55fffa82b61af 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/pet_api.rs @@ -236,13 +236,14 @@ pub async fn add_pet(configuration: &configuration::Configuration, params: AddPe let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -279,13 +280,14 @@ pub async fn delete_pet(configuration: &configuration::Configuration, params: De let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -322,13 +324,14 @@ pub async fn find_pets_by_status(configuration: &configuration::Configuration, p let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -365,13 +368,14 @@ pub async fn find_pets_by_tags(configuration: &configuration::Configuration, par let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -404,13 +408,14 @@ pub async fn get_pet_by_id(configuration: &configuration::Configuration, params: let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -444,13 +449,14 @@ pub async fn update_pet(configuration: &configuration::Configuration, params: Up let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -493,13 +499,14 @@ pub async fn update_pet_with_form(configuration: &configuration::Configuration, let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -540,13 +547,14 @@ pub async fn upload_file(configuration: &configuration::Configuration, params: U let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/store_api.rs index 2531e63067573..ef3f71dbb9cf9 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/store_api.rs @@ -122,13 +122,14 @@ pub async fn delete_order(configuration: &configuration::Configuration, params: let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -160,13 +161,14 @@ pub async fn get_inventory(configuration: &configuration::Configuration) -> Resu let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -194,13 +196,14 @@ pub async fn get_order_by_id(configuration: &configuration::Configuration, param let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -229,13 +232,14 @@ pub async fn place_order(configuration: &configuration::Configuration, params: P let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/testing_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/testing_api.rs index 83d1a00fb4cec..0dafccec4b728 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/testing_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/testing_api.rs @@ -46,7 +46,7 @@ pub enum TestsTypeTestingGetError { } -pub async fn tests_file_response_get(configuration: &configuration::Configuration) -> Result, Error> { +pub async fn tests_file_response_get(configuration: &configuration::Configuration) -> Result> { let local_var_configuration = configuration; // unbox the parameters @@ -65,13 +65,11 @@ pub async fn tests_file_response_get(configuration: &configuration::Configuratio let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { - let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); - let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; - Ok(local_var_result) + Ok(local_var_resp) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -97,13 +95,14 @@ pub async fn tests_type_testing_get(configuration: &configuration::Configuration let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/user_api.rs index 0c62352279db5..b5b830ac64a1b 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/user_api.rs @@ -221,13 +221,14 @@ pub async fn create_user(configuration: &configuration::Configuration, params: C let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -261,13 +262,14 @@ pub async fn create_users_with_array_input(configuration: &configuration::Config let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -301,13 +303,14 @@ pub async fn create_users_with_list_input(configuration: &configuration::Configu let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -340,13 +343,14 @@ pub async fn delete_user(configuration: &configuration::Configuration, params: D let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -374,13 +378,14 @@ pub async fn get_user_by_name(configuration: &configuration::Configuration, para let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -411,13 +416,14 @@ pub async fn login_user(configuration: &configuration::Configuration, params: Lo let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -449,13 +455,14 @@ pub async fn logout_user(configuration: &configuration::Configuration) -> Result let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -490,13 +497,14 @@ pub async fn update_user(configuration: &configuration::Configuration, params: U let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/fake_api.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/fake_api.rs index 3f10b5b6c2af9..f93b447840dae 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/fake_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/fake_api.rs @@ -74,13 +74,14 @@ pub async fn test_nullable_required_param(configuration: &configuration::Configu let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/pet_api.rs index 0a44b19a32ddf..471556f03bd7e 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/pet_api.rs @@ -234,13 +234,14 @@ pub async fn add_pet(configuration: &configuration::Configuration, params: AddPe let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -275,13 +276,14 @@ pub async fn delete_pet(configuration: &configuration::Configuration, params: De let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -316,13 +318,14 @@ pub async fn find_pets_by_status(configuration: &configuration::Configuration, p let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -357,13 +360,14 @@ pub async fn find_pets_by_tags(configuration: &configuration::Configuration, par let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -399,13 +403,14 @@ pub async fn get_pet_by_id(configuration: &configuration::Configuration, params: let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -437,13 +442,14 @@ pub async fn update_pet(configuration: &configuration::Configuration, params: Up let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -484,13 +490,14 @@ pub async fn update_pet_with_form(configuration: &configuration::Configuration, let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -529,13 +536,14 @@ pub async fn upload_file(configuration: &configuration::Configuration, params: U let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/store_api.rs index 67fd03a80f545..340e6f2dc97cc 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/store_api.rs @@ -122,13 +122,14 @@ pub async fn delete_order(configuration: &configuration::Configuration, params: let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -163,13 +164,14 @@ pub async fn get_inventory(configuration: &configuration::Configuration) -> Resu let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -197,13 +199,14 @@ pub async fn get_order_by_id(configuration: &configuration::Configuration, param let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -232,13 +235,14 @@ pub async fn place_order(configuration: &configuration::Configuration, params: P let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/testing_api.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/testing_api.rs index 83d1a00fb4cec..0dafccec4b728 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/testing_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/testing_api.rs @@ -46,7 +46,7 @@ pub enum TestsTypeTestingGetError { } -pub async fn tests_file_response_get(configuration: &configuration::Configuration) -> Result, Error> { +pub async fn tests_file_response_get(configuration: &configuration::Configuration) -> Result> { let local_var_configuration = configuration; // unbox the parameters @@ -65,13 +65,11 @@ pub async fn tests_file_response_get(configuration: &configuration::Configuratio let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { - let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); - let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; - Ok(local_var_result) + Ok(local_var_resp) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -97,13 +95,14 @@ pub async fn tests_type_testing_get(configuration: &configuration::Configuration let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/user_api.rs index 4f28c21c1cf3a..985f3b65e3173 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/user_api.rs @@ -224,13 +224,14 @@ pub async fn create_user(configuration: &configuration::Configuration, params: C let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -267,13 +268,14 @@ pub async fn create_users_with_array_input(configuration: &configuration::Config let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -310,13 +312,14 @@ pub async fn create_users_with_list_input(configuration: &configuration::Configu let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -352,13 +355,14 @@ pub async fn delete_user(configuration: &configuration::Configuration, params: D let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -386,13 +390,14 @@ pub async fn get_user_by_name(configuration: &configuration::Configuration, para let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -423,13 +428,14 @@ pub async fn login_user(configuration: &configuration::Configuration, params: Lo let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -464,13 +470,14 @@ pub async fn logout_user(configuration: &configuration::Configuration) -> Result let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -508,13 +515,14 @@ pub async fn update_user(configuration: &configuration::Configuration, params: U let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/fake_api.rs b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/fake_api.rs index 3f10b5b6c2af9..f93b447840dae 100644 --- a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/fake_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/fake_api.rs @@ -74,13 +74,14 @@ pub async fn test_nullable_required_param(configuration: &configuration::Configu let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/pet_api.rs index 0a44b19a32ddf..471556f03bd7e 100644 --- a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/pet_api.rs @@ -234,13 +234,14 @@ pub async fn add_pet(configuration: &configuration::Configuration, params: AddPe let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -275,13 +276,14 @@ pub async fn delete_pet(configuration: &configuration::Configuration, params: De let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -316,13 +318,14 @@ pub async fn find_pets_by_status(configuration: &configuration::Configuration, p let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -357,13 +360,14 @@ pub async fn find_pets_by_tags(configuration: &configuration::Configuration, par let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -399,13 +403,14 @@ pub async fn get_pet_by_id(configuration: &configuration::Configuration, params: let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -437,13 +442,14 @@ pub async fn update_pet(configuration: &configuration::Configuration, params: Up let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -484,13 +490,14 @@ pub async fn update_pet_with_form(configuration: &configuration::Configuration, let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -529,13 +536,14 @@ pub async fn upload_file(configuration: &configuration::Configuration, params: U let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/store_api.rs index 67fd03a80f545..340e6f2dc97cc 100644 --- a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/store_api.rs @@ -122,13 +122,14 @@ pub async fn delete_order(configuration: &configuration::Configuration, params: let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -163,13 +164,14 @@ pub async fn get_inventory(configuration: &configuration::Configuration) -> Resu let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -197,13 +199,14 @@ pub async fn get_order_by_id(configuration: &configuration::Configuration, param let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -232,13 +235,14 @@ pub async fn place_order(configuration: &configuration::Configuration, params: P let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/testing_api.rs b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/testing_api.rs index 83d1a00fb4cec..0dafccec4b728 100644 --- a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/testing_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/testing_api.rs @@ -46,7 +46,7 @@ pub enum TestsTypeTestingGetError { } -pub async fn tests_file_response_get(configuration: &configuration::Configuration) -> Result, Error> { +pub async fn tests_file_response_get(configuration: &configuration::Configuration) -> Result> { let local_var_configuration = configuration; // unbox the parameters @@ -65,13 +65,11 @@ pub async fn tests_file_response_get(configuration: &configuration::Configuratio let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { - let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); - let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; - Ok(local_var_result) + Ok(local_var_resp) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -97,13 +95,14 @@ pub async fn tests_type_testing_get(configuration: &configuration::Configuration let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/user_api.rs index 4f28c21c1cf3a..985f3b65e3173 100644 --- a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/user_api.rs @@ -224,13 +224,14 @@ pub async fn create_user(configuration: &configuration::Configuration, params: C let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -267,13 +268,14 @@ pub async fn create_users_with_array_input(configuration: &configuration::Config let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -310,13 +312,14 @@ pub async fn create_users_with_list_input(configuration: &configuration::Configu let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -352,13 +355,14 @@ pub async fn delete_user(configuration: &configuration::Configuration, params: D let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -386,13 +390,14 @@ pub async fn get_user_by_name(configuration: &configuration::Configuration, para let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -423,13 +428,14 @@ pub async fn login_user(configuration: &configuration::Configuration, params: Lo let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -464,13 +470,14 @@ pub async fn logout_user(configuration: &configuration::Configuration) -> Result let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -508,13 +515,14 @@ pub async fn update_user(configuration: &configuration::Configuration, params: U let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Ok(local_var_result) } else { + let local_var_content = local_var_resp.text().await?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/fake_api.rs b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/fake_api.rs index d14a0f233be3e..24339cb769aaa 100644 --- a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/fake_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/fake_api.rs @@ -49,11 +49,11 @@ pub fn test_nullable_required_param(configuration: &configuration::Configuration let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/pet_api.rs index c48cfb3b2f908..3bd8113f7bde0 100644 --- a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/pet_api.rs @@ -116,11 +116,12 @@ pub fn add_pet(configuration: &configuration::Configuration, pet: models::Pet) - let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -163,11 +164,11 @@ pub fn delete_pet(configuration: &configuration::Configuration, pet_id: i64, api let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -211,11 +212,12 @@ pub fn find_pets_by_status(configuration: &configuration::Configuration, status: let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -259,11 +261,12 @@ pub fn find_pets_by_tags(configuration: &configuration::Configuration, tags: Vec let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -308,11 +311,12 @@ pub fn get_pet_by_id(configuration: &configuration::Configuration, pet_id: i64) let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -353,11 +357,12 @@ pub fn update_pet(configuration: &configuration::Configuration, pet: models::Pet let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -405,11 +410,11 @@ pub fn update_pet_with_form(configuration: &configuration::Configuration, pet_id let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -457,11 +462,12 @@ pub fn upload_file(configuration: &configuration::Configuration, pet_id: i64, ad let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/store_api.rs index fd42617f4c7d8..d1ad7c4a4fc6b 100644 --- a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/store_api.rs @@ -66,11 +66,11 @@ pub fn delete_order(configuration: &configuration::Configuration, order_id: &str let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -115,11 +115,12 @@ pub fn get_inventory(configuration: &configuration::Configuration, ) -> Result = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -143,11 +144,12 @@ pub fn get_order_by_id(configuration: &configuration::Configuration, order_id: i let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -172,11 +174,12 @@ pub fn place_order(configuration: &configuration::Configuration, order: models:: let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/testing_api.rs b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/testing_api.rs index c53219078f0ee..634576260d6ac 100644 --- a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/testing_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/testing_api.rs @@ -30,7 +30,7 @@ pub enum TestsTypeTestingGetError { } -pub fn tests_file_response_get(configuration: &configuration::Configuration, ) -> Result> { +pub fn tests_file_response_get(configuration: &configuration::Configuration, ) -> Result> { let local_var_configuration = configuration; let local_var_client = &local_var_configuration.client; @@ -46,11 +46,11 @@ pub fn tests_file_response_get(configuration: &configuration::Configuration, ) - let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { - serde_json::from_str(&local_var_content).map_err(Error::from) + Ok(local_var_resp) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -73,11 +73,12 @@ pub fn tests_type_testing_get(configuration: &configuration::Configuration, ) -> let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/user_api.rs index 0eedaddc2e487..3c186de94f980 100644 --- a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/user_api.rs @@ -122,11 +122,11 @@ pub fn create_user(configuration: &configuration::Configuration, user: models::U let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -172,11 +172,11 @@ pub fn create_users_with_array_input(configuration: &configuration::Configuratio let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -222,11 +222,11 @@ pub fn create_users_with_list_input(configuration: &configuration::Configuration let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -271,11 +271,11 @@ pub fn delete_user(configuration: &configuration::Configuration, username: &str) let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -299,11 +299,12 @@ pub fn get_user_by_name(configuration: &configuration::Configuration, username: let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -329,11 +330,12 @@ pub fn login_user(configuration: &configuration::Configuration, username: &str, let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -378,11 +380,11 @@ pub fn logout_user(configuration: &configuration::Configuration, ) -> Result<(), let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -428,11 +430,11 @@ pub fn update_user(configuration: &configuration::Configuration, username: &str, let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/fake_api.rs b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/fake_api.rs index d14a0f233be3e..24339cb769aaa 100644 --- a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/fake_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/fake_api.rs @@ -49,11 +49,11 @@ pub fn test_nullable_required_param(configuration: &configuration::Configuration let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/pet_api.rs index d7274d9986b6b..b16d781edcf81 100644 --- a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/pet_api.rs @@ -103,11 +103,12 @@ pub fn add_pet(configuration: &configuration::Configuration, foo_pet: models::Fo let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -137,11 +138,11 @@ pub fn delete_pet(configuration: &configuration::Configuration, pet_id: i64, api let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -172,11 +173,12 @@ pub fn find_pets_by_status(configuration: &configuration::Configuration, status: let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -207,11 +209,12 @@ pub fn find_pets_by_tags(configuration: &configuration::Configuration, tags: Vec let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -243,11 +246,12 @@ pub fn get_pet_by_id(configuration: &configuration::Configuration, pet_id: i64) let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -275,11 +279,12 @@ pub fn update_pet(configuration: &configuration::Configuration, foo_pet: models: let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -314,11 +319,11 @@ pub fn update_pet_with_form(configuration: &configuration::Configuration, pet_id let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -353,11 +358,12 @@ pub fn upload_file(configuration: &configuration::Configuration, pet_id: i64, ad let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/store_api.rs index 2dc92a8a41b61..6bce786967c45 100644 --- a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/store_api.rs @@ -66,11 +66,11 @@ pub fn delete_order(configuration: &configuration::Configuration, order_id: &str let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -102,11 +102,12 @@ pub fn get_inventory(configuration: &configuration::Configuration, ) -> Result = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -130,11 +131,12 @@ pub fn get_order_by_id(configuration: &configuration::Configuration, order_id: i let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -159,11 +161,12 @@ pub fn place_order(configuration: &configuration::Configuration, foo_order: mode let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/testing_api.rs b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/testing_api.rs index 8f42fae4014e7..1b22593cdab6f 100644 --- a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/testing_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/testing_api.rs @@ -30,7 +30,7 @@ pub enum TestsTypeTestingGetError { } -pub fn tests_file_response_get(configuration: &configuration::Configuration, ) -> Result> { +pub fn tests_file_response_get(configuration: &configuration::Configuration, ) -> Result> { let local_var_configuration = configuration; let local_var_client = &local_var_configuration.client; @@ -46,11 +46,11 @@ pub fn tests_file_response_get(configuration: &configuration::Configuration, ) - let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { - serde_json::from_str(&local_var_content).map_err(Error::from) + Ok(local_var_resp) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -73,11 +73,12 @@ pub fn tests_type_testing_get(configuration: &configuration::Configuration, ) -> let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/user_api.rs index 45f728426b7b9..dbb0bf2ff5ffa 100644 --- a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/user_api.rs @@ -109,11 +109,11 @@ pub fn create_user(configuration: &configuration::Configuration, foo_user: model let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -146,11 +146,11 @@ pub fn create_users_with_array_input(configuration: &configuration::Configuratio let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -183,11 +183,11 @@ pub fn create_users_with_list_input(configuration: &configuration::Configuration let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -219,11 +219,11 @@ pub fn delete_user(configuration: &configuration::Configuration, username: &str) let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -247,11 +247,12 @@ pub fn get_user_by_name(configuration: &configuration::Configuration, username: let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -277,11 +278,12 @@ pub fn login_user(configuration: &configuration::Configuration, username: &str, let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -313,11 +315,11 @@ pub fn logout_user(configuration: &configuration::Configuration, ) -> Result<(), let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -350,11 +352,11 @@ pub fn update_user(configuration: &configuration::Configuration, username: &str, let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore/src/apis/fake_api.rs b/samples/client/petstore/rust/reqwest/petstore/src/apis/fake_api.rs index d14a0f233be3e..24339cb769aaa 100644 --- a/samples/client/petstore/rust/reqwest/petstore/src/apis/fake_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore/src/apis/fake_api.rs @@ -49,11 +49,11 @@ pub fn test_nullable_required_param(configuration: &configuration::Configuration let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest/petstore/src/apis/pet_api.rs index ebff8f8dde98b..a08c09aaa3cc9 100644 --- a/samples/client/petstore/rust/reqwest/petstore/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore/src/apis/pet_api.rs @@ -103,11 +103,12 @@ pub fn add_pet(configuration: &configuration::Configuration, pet: models::Pet) - let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -137,11 +138,11 @@ pub fn delete_pet(configuration: &configuration::Configuration, pet_id: i64, api let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -172,11 +173,12 @@ pub fn find_pets_by_status(configuration: &configuration::Configuration, status: let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -207,11 +209,12 @@ pub fn find_pets_by_tags(configuration: &configuration::Configuration, tags: Vec let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -243,11 +246,12 @@ pub fn get_pet_by_id(configuration: &configuration::Configuration, pet_id: i64) let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -275,11 +279,12 @@ pub fn update_pet(configuration: &configuration::Configuration, pet: models::Pet let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -314,11 +319,11 @@ pub fn update_pet_with_form(configuration: &configuration::Configuration, pet_id let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -353,11 +358,12 @@ pub fn upload_file(configuration: &configuration::Configuration, pet_id: i64, ad let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest/petstore/src/apis/store_api.rs index 98c889e0e55f2..e62feebbf8d90 100644 --- a/samples/client/petstore/rust/reqwest/petstore/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore/src/apis/store_api.rs @@ -66,11 +66,11 @@ pub fn delete_order(configuration: &configuration::Configuration, order_id: &str let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -102,11 +102,12 @@ pub fn get_inventory(configuration: &configuration::Configuration, ) -> Result = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -130,11 +131,12 @@ pub fn get_order_by_id(configuration: &configuration::Configuration, order_id: i let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -159,11 +161,12 @@ pub fn place_order(configuration: &configuration::Configuration, order: models:: let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore/src/apis/testing_api.rs b/samples/client/petstore/rust/reqwest/petstore/src/apis/testing_api.rs index c53219078f0ee..634576260d6ac 100644 --- a/samples/client/petstore/rust/reqwest/petstore/src/apis/testing_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore/src/apis/testing_api.rs @@ -30,7 +30,7 @@ pub enum TestsTypeTestingGetError { } -pub fn tests_file_response_get(configuration: &configuration::Configuration, ) -> Result> { +pub fn tests_file_response_get(configuration: &configuration::Configuration, ) -> Result> { let local_var_configuration = configuration; let local_var_client = &local_var_configuration.client; @@ -46,11 +46,11 @@ pub fn tests_file_response_get(configuration: &configuration::Configuration, ) - let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { - serde_json::from_str(&local_var_content).map_err(Error::from) + Ok(local_var_resp) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -73,11 +73,12 @@ pub fn tests_type_testing_get(configuration: &configuration::Configuration, ) -> let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) diff --git a/samples/client/petstore/rust/reqwest/petstore/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest/petstore/src/apis/user_api.rs index 2f328ace6051a..40505efb17f21 100644 --- a/samples/client/petstore/rust/reqwest/petstore/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore/src/apis/user_api.rs @@ -109,11 +109,11 @@ pub fn create_user(configuration: &configuration::Configuration, user: models::U let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -146,11 +146,11 @@ pub fn create_users_with_array_input(configuration: &configuration::Configuratio let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -183,11 +183,11 @@ pub fn create_users_with_list_input(configuration: &configuration::Configuration let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -219,11 +219,11 @@ pub fn delete_user(configuration: &configuration::Configuration, username: &str) let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -247,11 +247,12 @@ pub fn get_user_by_name(configuration: &configuration::Configuration, username: let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -277,11 +278,12 @@ pub fn login_user(configuration: &configuration::Configuration, username: &str, let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + let local_var_content = local_var_resp.text()?; serde_json::from_str(&local_var_content).map_err(Error::from) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -313,11 +315,11 @@ pub fn logout_user(configuration: &configuration::Configuration, ) -> Result<(), let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) @@ -350,11 +352,11 @@ pub fn update_user(configuration: &configuration::Configuration, username: &str, let local_var_resp = local_var_client.execute(local_var_req)?; let local_var_status = local_var_resp.status(); - let local_var_content = local_var_resp.text()?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { + let local_var_content = local_var_resp.text()?; let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; Err(Error::ResponseError(local_var_error)) From 711e53a90cd500a6068867e8294e91c394887143 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Fri, 29 Nov 2024 17:12:12 +0800 Subject: [PATCH 12/12] [Java] Add option to fallback to legacy enum naming (#20172) * add option to fallback legacy enum naming (java) * fix tests --- bin/configs/java-okhttp-gson-3.1.yaml | 1 + bin/configs/java-okhttp-gson-streaming.yaml | 1 + docs/generators/groovy.md | 1 + docs/generators/java-camel.md | 1 + docs/generators/java-helidon-client.md | 1 + docs/generators/java-helidon-server.md | 1 + docs/generators/java-inflector.md | 1 + docs/generators/java-micronaut-client.md | 1 + docs/generators/java-micronaut-server.md | 1 + docs/generators/java-microprofile.md | 1 + docs/generators/java-msf4j.md | 1 + docs/generators/java-pkmst.md | 1 + docs/generators/java-play-framework.md | 1 + docs/generators/java-undertow-server.md | 1 + docs/generators/java-vertx-web.md | 1 + docs/generators/java-vertx.md | 1 + docs/generators/java-wiremock.md | 1 + docs/generators/java.md | 1 + docs/generators/jaxrs-cxf-cdi.md | 1 + docs/generators/jaxrs-cxf-client.md | 1 + docs/generators/jaxrs-cxf-extended.md | 1 + docs/generators/jaxrs-cxf.md | 1 + docs/generators/jaxrs-jersey.md | 1 + docs/generators/jaxrs-resteasy-eap.md | 1 + docs/generators/jaxrs-resteasy.md | 1 + docs/generators/jaxrs-spec.md | 1 + docs/generators/spring.md | 1 + .../languages/AbstractJavaCodegen.java | 46 +++++++++++++++++-- .../java/spring/SpringCodegenTest.java | 4 -- .../okhttp-gson-streaming/docs/SomeObj.md | 2 +- .../openapitools/client/model/SomeObj.java | 4 +- 31 files changed, 71 insertions(+), 12 deletions(-) diff --git a/bin/configs/java-okhttp-gson-3.1.yaml b/bin/configs/java-okhttp-gson-3.1.yaml index b7d67ab0a5da1..845d7510c6775 100644 --- a/bin/configs/java-okhttp-gson-3.1.yaml +++ b/bin/configs/java-okhttp-gson-3.1.yaml @@ -15,5 +15,6 @@ additionalProperties: hideGenerationTimestamp: "true" useOneOfDiscriminatorLookup: "true" disallowAdditionalPropertiesIfNotPresent: false + enumPropertyNaming: legacy openapiNormalizer: FIX_DUPLICATED_OPERATIONID: true diff --git a/bin/configs/java-okhttp-gson-streaming.yaml b/bin/configs/java-okhttp-gson-streaming.yaml index 9e75c93bac4cf..a5ab03be70dd1 100644 --- a/bin/configs/java-okhttp-gson-streaming.yaml +++ b/bin/configs/java-okhttp-gson-streaming.yaml @@ -8,3 +8,4 @@ additionalProperties: hideGenerationTimestamp: "true" supportStreaming: true serializableModel: true + enumPropertyNaming: legacy diff --git a/docs/generators/groovy.md b/docs/generators/groovy.md index 5407b0b894efb..d1eab74f3fa39 100644 --- a/docs/generators/groovy.md +++ b/docs/generators/groovy.md @@ -38,6 +38,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|
**false**
The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.
**true**
Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.
|true| |discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| +|enumPropertyNaming|Naming convention for enum properties: 'MACRO_CASE' and 'legacy'| |MACRO_CASE| |enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| |generateBuilders|Whether to generate builders for models| |false| |generateConstructorWithAllArgs|whether to generate a constructor for all arguments| |false| diff --git a/docs/generators/java-camel.md b/docs/generators/java-camel.md index e77c38151eb37..2ffb19c88591c 100644 --- a/docs/generators/java-camel.md +++ b/docs/generators/java-camel.md @@ -54,6 +54,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |documentationProvider|Select the OpenAPI documentation provider.|
**none**
Do not publish an OpenAPI specification.
**source**
Publish the original input OpenAPI specification.
**springfox**
Generate an OpenAPI 2 (fka Swagger RESTful API Documentation Specification) specification using SpringFox 2.x. Deprecated (for removal); use springdoc instead.
**springdoc**
Generate an OpenAPI 3 specification using SpringDoc.
|springdoc| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| +|enumPropertyNaming|Naming convention for enum properties: 'MACRO_CASE' and 'legacy'| |MACRO_CASE| |enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| |generateBuilders|Whether to generate builders for models| |false| |generateConstructorWithAllArgs|whether to generate a constructor for all arguments| |false| diff --git a/docs/generators/java-helidon-client.md b/docs/generators/java-helidon-client.md index c9c1e40644694..b5e7384f4ec64 100644 --- a/docs/generators/java-helidon-client.md +++ b/docs/generators/java-helidon-client.md @@ -36,6 +36,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|
**false**
The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.
**true**
Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.
|true| |discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| +|enumPropertyNaming|Naming convention for enum properties: 'MACRO_CASE' and 'legacy'| |MACRO_CASE| |enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| |fullProject|If set to true, it will generate all files; if set to false, it will only generate API files. If unspecified, the behavior depends on whether a project exists or not: if it does not, same as true; if it does, same as false. Note that test files are never overwritten.| || |generateBuilders|Whether to generate builders for models| |false| diff --git a/docs/generators/java-helidon-server.md b/docs/generators/java-helidon-server.md index 5ca963a6686e9..13af83f521370 100644 --- a/docs/generators/java-helidon-server.md +++ b/docs/generators/java-helidon-server.md @@ -35,6 +35,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|
**false**
The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.
**true**
Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.
|true| |discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| +|enumPropertyNaming|Naming convention for enum properties: 'MACRO_CASE' and 'legacy'| |MACRO_CASE| |enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| |fullProject|If set to true, it will generate all files; if set to false, it will only generate API files. If unspecified, the behavior depends on whether a project exists or not: if it does not, same as true; if it does, same as false. Note that test files are never overwritten.| || |generateBuilders|Whether to generate builders for models| |false| diff --git a/docs/generators/java-inflector.md b/docs/generators/java-inflector.md index 8b8b35ea29dce..6c8c79dfcc3b8 100644 --- a/docs/generators/java-inflector.md +++ b/docs/generators/java-inflector.md @@ -40,6 +40,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|
**false**
The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.
**true**
Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.
|true| |discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| +|enumPropertyNaming|Naming convention for enum properties: 'MACRO_CASE' and 'legacy'| |MACRO_CASE| |enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| |generateBuilders|Whether to generate builders for models| |false| |generateConstructorWithAllArgs|whether to generate a constructor for all arguments| |false| diff --git a/docs/generators/java-micronaut-client.md b/docs/generators/java-micronaut-client.md index 6ca685331a199..72d32e61225ba 100644 --- a/docs/generators/java-micronaut-client.md +++ b/docs/generators/java-micronaut-client.md @@ -49,6 +49,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|
**false**
The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.
**true**
Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.
|true| |discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| +|enumPropertyNaming|Naming convention for enum properties: 'MACRO_CASE' and 'legacy'| |MACRO_CASE| |enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| |generateBuilders|Whether to generate builders for models| |false| |generateConstructorWithAllArgs|whether to generate a constructor for all arguments| |false| diff --git a/docs/generators/java-micronaut-server.md b/docs/generators/java-micronaut-server.md index 2a181970fe116..71261b9aa6444 100644 --- a/docs/generators/java-micronaut-server.md +++ b/docs/generators/java-micronaut-server.md @@ -44,6 +44,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|
**false**
The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.
**true**
Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.
|true| |discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| +|enumPropertyNaming|Naming convention for enum properties: 'MACRO_CASE' and 'legacy'| |MACRO_CASE| |enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| |generateBuilders|Whether to generate builders for models| |false| |generateConstructorWithAllArgs|whether to generate a constructor for all arguments| |false| diff --git a/docs/generators/java-microprofile.md b/docs/generators/java-microprofile.md index b9778bbfe802f..335e71f9678a3 100644 --- a/docs/generators/java-microprofile.md +++ b/docs/generators/java-microprofile.md @@ -47,6 +47,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |documentationProvider|Select the OpenAPI documentation provider.|
**none**
Do not publish an OpenAPI specification.
**source**
Publish the original input OpenAPI specification.
|source| |dynamicOperations|Generate operations dynamically at runtime from an OAS| |false| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| +|enumPropertyNaming|Naming convention for enum properties: 'MACRO_CASE' and 'legacy'| |MACRO_CASE| |enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| |errorObjectType|Error Object type. (This option is for okhttp-gson only)| |null| |failOnUnknownProperties|Fail Jackson de-serialization on unknown properties| |false| diff --git a/docs/generators/java-msf4j.md b/docs/generators/java-msf4j.md index d321b030be83a..e87372b5fa5af 100644 --- a/docs/generators/java-msf4j.md +++ b/docs/generators/java-msf4j.md @@ -40,6 +40,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|
**false**
The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.
**true**
Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.
|true| |discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| +|enumPropertyNaming|Naming convention for enum properties: 'MACRO_CASE' and 'legacy'| |MACRO_CASE| |enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| |generateBuilders|Whether to generate builders for models| |false| |generateConstructorWithAllArgs|whether to generate a constructor for all arguments| |false| diff --git a/docs/generators/java-pkmst.md b/docs/generators/java-pkmst.md index 4a96c9d89d9be..6fa61fa2c9d2a 100644 --- a/docs/generators/java-pkmst.md +++ b/docs/generators/java-pkmst.md @@ -41,6 +41,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|
**false**
The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.
**true**
Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.
|true| |discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| +|enumPropertyNaming|Naming convention for enum properties: 'MACRO_CASE' and 'legacy'| |MACRO_CASE| |enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| |eurekaUri|Eureka URI| |null| |generateBuilders|Whether to generate builders for models| |false| diff --git a/docs/generators/java-play-framework.md b/docs/generators/java-play-framework.md index 1e4efaaeae5be..20d617d45ee32 100644 --- a/docs/generators/java-play-framework.md +++ b/docs/generators/java-play-framework.md @@ -43,6 +43,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|
**false**
The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.
**true**
Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.
|true| |discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| +|enumPropertyNaming|Naming convention for enum properties: 'MACRO_CASE' and 'legacy'| |MACRO_CASE| |enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| |generateBuilders|Whether to generate builders for models| |false| |generateConstructorWithAllArgs|whether to generate a constructor for all arguments| |false| diff --git a/docs/generators/java-undertow-server.md b/docs/generators/java-undertow-server.md index ca484ad146ed4..2e02829c2ed5b 100644 --- a/docs/generators/java-undertow-server.md +++ b/docs/generators/java-undertow-server.md @@ -40,6 +40,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|
**false**
The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.
**true**
Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.
|true| |discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| +|enumPropertyNaming|Naming convention for enum properties: 'MACRO_CASE' and 'legacy'| |MACRO_CASE| |enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| |generateBuilders|Whether to generate builders for models| |false| |generateConstructorWithAllArgs|whether to generate a constructor for all arguments| |false| diff --git a/docs/generators/java-vertx-web.md b/docs/generators/java-vertx-web.md index 8c98816db81c0..b39dfcaf03f88 100644 --- a/docs/generators/java-vertx-web.md +++ b/docs/generators/java-vertx-web.md @@ -40,6 +40,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|
**false**
The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.
**true**
Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.
|true| |discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| +|enumPropertyNaming|Naming convention for enum properties: 'MACRO_CASE' and 'legacy'| |MACRO_CASE| |enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| |generateBuilders|Whether to generate builders for models| |false| |generateConstructorWithAllArgs|whether to generate a constructor for all arguments| |false| diff --git a/docs/generators/java-vertx.md b/docs/generators/java-vertx.md index 9720c15d8bdbd..9f9024732f284 100644 --- a/docs/generators/java-vertx.md +++ b/docs/generators/java-vertx.md @@ -40,6 +40,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|
**false**
The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.
**true**
Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.
|true| |discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| +|enumPropertyNaming|Naming convention for enum properties: 'MACRO_CASE' and 'legacy'| |MACRO_CASE| |enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| |generateBuilders|Whether to generate builders for models| |false| |generateConstructorWithAllArgs|whether to generate a constructor for all arguments| |false| diff --git a/docs/generators/java-wiremock.md b/docs/generators/java-wiremock.md index 09fb082309e2a..b8a0af01f0143 100644 --- a/docs/generators/java-wiremock.md +++ b/docs/generators/java-wiremock.md @@ -40,6 +40,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|
**false**
The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.
**true**
Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.
|true| |discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| +|enumPropertyNaming|Naming convention for enum properties: 'MACRO_CASE' and 'legacy'| |MACRO_CASE| |enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| |generateBuilders|Whether to generate builders for models| |false| |generateConstructorWithAllArgs|whether to generate a constructor for all arguments| |false| diff --git a/docs/generators/java.md b/docs/generators/java.md index bb371ceeca749..96cb5b888bfe7 100644 --- a/docs/generators/java.md +++ b/docs/generators/java.md @@ -47,6 +47,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |documentationProvider|Select the OpenAPI documentation provider.|
**none**
Do not publish an OpenAPI specification.
**source**
Publish the original input OpenAPI specification.
|source| |dynamicOperations|Generate operations dynamically at runtime from an OAS| |false| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| +|enumPropertyNaming|Naming convention for enum properties: 'MACRO_CASE' and 'legacy'| |MACRO_CASE| |enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| |errorObjectType|Error Object type. (This option is for okhttp-gson only)| |null| |failOnUnknownProperties|Fail Jackson de-serialization on unknown properties| |false| diff --git a/docs/generators/jaxrs-cxf-cdi.md b/docs/generators/jaxrs-cxf-cdi.md index d911fd30b0f3f..8029aa638bb00 100644 --- a/docs/generators/jaxrs-cxf-cdi.md +++ b/docs/generators/jaxrs-cxf-cdi.md @@ -40,6 +40,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|
**false**
The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.
**true**
Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.
|true| |discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| +|enumPropertyNaming|Naming convention for enum properties: 'MACRO_CASE' and 'legacy'| |MACRO_CASE| |enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| |generateBuilders|Whether to generate builders for models| |false| |generateConstructorWithAllArgs|whether to generate a constructor for all arguments| |false| diff --git a/docs/generators/jaxrs-cxf-client.md b/docs/generators/jaxrs-cxf-client.md index 04ae1cfee4e16..395719497aab3 100644 --- a/docs/generators/jaxrs-cxf-client.md +++ b/docs/generators/jaxrs-cxf-client.md @@ -40,6 +40,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|
**false**
The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.
**true**
Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.
|true| |discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| +|enumPropertyNaming|Naming convention for enum properties: 'MACRO_CASE' and 'legacy'| |MACRO_CASE| |enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| |generateBuilders|Whether to generate builders for models| |false| |generateConstructorWithAllArgs|whether to generate a constructor for all arguments| |false| diff --git a/docs/generators/jaxrs-cxf-extended.md b/docs/generators/jaxrs-cxf-extended.md index 8c34c65d1460d..4228d9a6bae06 100644 --- a/docs/generators/jaxrs-cxf-extended.md +++ b/docs/generators/jaxrs-cxf-extended.md @@ -41,6 +41,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|
**false**
The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.
**true**
Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.
|true| |discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| +|enumPropertyNaming|Naming convention for enum properties: 'MACRO_CASE' and 'legacy'| |MACRO_CASE| |enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| |generateBuilders|Whether to generate builders for models| |false| |generateConstructorWithAllArgs|whether to generate a constructor for all arguments| |false| diff --git a/docs/generators/jaxrs-cxf.md b/docs/generators/jaxrs-cxf.md index 12deda54824da..633cd75780582 100644 --- a/docs/generators/jaxrs-cxf.md +++ b/docs/generators/jaxrs-cxf.md @@ -41,6 +41,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|
**false**
The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.
**true**
Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.
|true| |discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| +|enumPropertyNaming|Naming convention for enum properties: 'MACRO_CASE' and 'legacy'| |MACRO_CASE| |enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| |generateBuilders|Whether to generate builders for models| |false| |generateConstructorWithAllArgs|whether to generate a constructor for all arguments| |false| diff --git a/docs/generators/jaxrs-jersey.md b/docs/generators/jaxrs-jersey.md index 0965570fdde47..34d402be27d7c 100644 --- a/docs/generators/jaxrs-jersey.md +++ b/docs/generators/jaxrs-jersey.md @@ -40,6 +40,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|
**false**
The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.
**true**
Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.
|true| |discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| +|enumPropertyNaming|Naming convention for enum properties: 'MACRO_CASE' and 'legacy'| |MACRO_CASE| |enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| |generateBuilders|Whether to generate builders for models| |false| |generateConstructorWithAllArgs|whether to generate a constructor for all arguments| |false| diff --git a/docs/generators/jaxrs-resteasy-eap.md b/docs/generators/jaxrs-resteasy-eap.md index 6973aecf1dba2..7e75d1b939a9f 100644 --- a/docs/generators/jaxrs-resteasy-eap.md +++ b/docs/generators/jaxrs-resteasy-eap.md @@ -40,6 +40,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|
**false**
The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.
**true**
Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.
|true| |discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| +|enumPropertyNaming|Naming convention for enum properties: 'MACRO_CASE' and 'legacy'| |MACRO_CASE| |enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| |generateBuilders|Whether to generate builders for models| |false| |generateConstructorWithAllArgs|whether to generate a constructor for all arguments| |false| diff --git a/docs/generators/jaxrs-resteasy.md b/docs/generators/jaxrs-resteasy.md index f48428ba1c92d..4dfd3e6295a82 100644 --- a/docs/generators/jaxrs-resteasy.md +++ b/docs/generators/jaxrs-resteasy.md @@ -40,6 +40,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|
**false**
The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.
**true**
Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.
|true| |discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| +|enumPropertyNaming|Naming convention for enum properties: 'MACRO_CASE' and 'legacy'| |MACRO_CASE| |enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| |generateBuilders|Whether to generate builders for models| |false| |generateConstructorWithAllArgs|whether to generate a constructor for all arguments| |false| diff --git a/docs/generators/jaxrs-spec.md b/docs/generators/jaxrs-spec.md index 6f9fb5a406202..ccd66e36bb0a9 100644 --- a/docs/generators/jaxrs-spec.md +++ b/docs/generators/jaxrs-spec.md @@ -40,6 +40,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|
**false**
The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.
**true**
Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.
|true| |discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| +|enumPropertyNaming|Naming convention for enum properties: 'MACRO_CASE' and 'legacy'| |MACRO_CASE| |enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| |generateBuilders|Whether to generate builders for models| |false| |generateConstructorWithAllArgs|whether to generate a constructor for all arguments| |false| diff --git a/docs/generators/spring.md b/docs/generators/spring.md index b71cefb3c1260..745517a34ae8c 100644 --- a/docs/generators/spring.md +++ b/docs/generators/spring.md @@ -47,6 +47,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |documentationProvider|Select the OpenAPI documentation provider.|
**none**
Do not publish an OpenAPI specification.
**source**
Publish the original input OpenAPI specification.
**springfox**
Generate an OpenAPI 2 (fka Swagger RESTful API Documentation Specification) specification using SpringFox 2.x. Deprecated (for removal); use springdoc instead.
**springdoc**
Generate an OpenAPI 3 specification using SpringDoc.
|springdoc| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| +|enumPropertyNaming|Naming convention for enum properties: 'MACRO_CASE' and 'legacy'| |MACRO_CASE| |enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| |generateBuilders|Whether to generate builders for models| |false| |generateConstructorWithAllArgs|whether to generate a constructor for all arguments| |false| diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java index e34cbee7799e8..7f10686ae7e1b 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java @@ -140,6 +140,11 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code protected String sourceFolder = projectFolder + "/java"; @Getter @Setter protected String testFolder = projectTestFolder + "/java"; + + protected static enum ENUM_PROPERTY_NAMING_TYPE {MACRO_CASE, legacy}; + protected static final String ENUM_PROPERTY_NAMING_DESC = "Naming convention for enum properties: 'MACRO_CASE' and 'legacy'"; + @Getter protected ENUM_PROPERTY_NAMING_TYPE enumPropertyNaming = ENUM_PROPERTY_NAMING_TYPE.MACRO_CASE; + /** * -- SETTER -- * Set whether discriminator value lookup is case-sensitive or not. @@ -356,6 +361,9 @@ public AbstractJavaCodegen() { annotationLibraryCliOption.addEnum(al.toCliOptValue(), al.getDescription())); cliOptions.add(annotationLibraryCliOption); } + + CliOption enumPropertyNamingOpt = new CliOption(CodegenConstants.ENUM_PROPERTY_NAMING, ENUM_PROPERTY_NAMING_DESC); + cliOptions.add(enumPropertyNamingOpt.defaultValue(enumPropertyNaming.name())); } @Override @@ -540,11 +548,11 @@ public void processOpts() { convertPropertyToStringAndWriteBack(CodegenConstants.LIBRARY, this::setLibrary); convertPropertyToBooleanAndWriteBack(CodegenConstants.SERIALIZE_BIG_DECIMAL_AS_STRING, this::setSerializeBigDecimalAsString ); // need to put back serializableModel (boolean) into additionalProperties as value in additionalProperties is string -// additionalProperties.put(CodegenConstants.SERIALIZABLE_MODEL, serializableModel); + // additionalProperties.put(CodegenConstants.SERIALIZABLE_MODEL, serializableModel); - // By default, the discriminator lookup should be case sensitive. There is nothing in the OpenAPI specification - // that indicates the lookup should be case insensitive. However, some implementations perform - // a case-insensitive lookup. + // By default, the discriminator lookup should be case sensitive. There is nothing in the OpenAPI specification + // that indicates the lookup should be case insensitive. However, some implementations perform + // a case-insensitive lookup. convertPropertyToBooleanAndWriteBack(DISCRIMINATOR_CASE_SENSITIVE, this::setDiscriminatorCaseSensitive); convertPropertyToBooleanAndWriteBack(WITH_XML, this::setWithXml); convertPropertyToBooleanAndWriteBack(OPENAPI_NULLABLE, this::setOpenApiNullable); @@ -555,6 +563,7 @@ public void processOpts() { convertPropertyToStringAndWriteBack(IMPLICIT_HEADERS_REGEX, this::setImplicitHeadersRegex); convertPropertyToBooleanAndWriteBack(CAMEL_CASE_DOLLAR_SIGN, this::setCamelCaseDollarSign); convertPropertyToBooleanAndWriteBack(USE_ONE_OF_INTERFACES, this::setUseOneOfInterfaces); + convertPropertyToStringAndWriteBack(CodegenConstants.ENUM_PROPERTY_NAMING, this::setEnumPropertyNaming); if (!StringUtils.isEmpty(parentGroupId) && !StringUtils.isEmpty(parentArtifactId) && !StringUtils.isEmpty(parentVersion)) { additionalProperties.put("parentOverridden", true); @@ -2009,7 +2018,17 @@ public String toEnumVarName(String value, String datatype) { } // string - String var = underscore(value.replaceAll("\\W+", "_")).toUpperCase(Locale.ROOT); + String var; + switch (getEnumPropertyNaming()) { + case legacy: + // legacy ,e.g. WITHNUMBER1 + var = value.replaceAll("\\W+", "_").toUpperCase(Locale.ROOT); + break; + default: + // default to MACRO_CASE, e.g. WITH_NUMBER1 + var = underscore(value.replaceAll("\\W+", "_")).toUpperCase(Locale.ROOT); + break; + } if (var.matches("\\d.*")) { var = "_" + var; } @@ -2367,4 +2386,21 @@ public static void addImports(List> imports, CodegenModel cm public boolean isTypeErasedGenerics() { return true; } + + /** + * Sets the naming convention for Java enum properties + * + * @param enumPropertyNamingType The string representation of the naming convention, as defined by {@link ENUM_PROPERTY_NAMING_TYPE} + */ + public void setEnumPropertyNaming(final String enumPropertyNamingType) { + try { + this.enumPropertyNaming = ENUM_PROPERTY_NAMING_TYPE.valueOf(enumPropertyNamingType); + } catch (IllegalArgumentException ex) { + StringBuilder sb = new StringBuilder(enumPropertyNamingType + " is an invalid enum property naming option. Please choose from:"); + for (ENUM_PROPERTY_NAMING_TYPE t : ENUM_PROPERTY_NAMING_TYPE.values()) { + sb.append("\n ").append(t.name()); + } + throw new RuntimeException(sb.toString()); + } + } } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java index 37863f2659f58..f2d7bd6274589 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java @@ -2398,7 +2398,6 @@ public void requiredFieldShouldIncludeNotNullAnnotation_issue13365() throws IOEx codegen.additionalProperties().put(CodegenConstants.SORT_MODEL_PROPERTIES_BY_REQUIRED_FLAG, "false"); codegen.additionalProperties().put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, "false"); codegen.additionalProperties().put(CodegenConstants.SERIALIZATION_LIBRARY, "jackson"); - codegen.additionalProperties().put(CodegenConstants.ENUM_PROPERTY_NAMING, "PascalCase"); codegen.additionalProperties().put(SpringCodegen.USE_TAGS, "true"); Map files = generateFiles(codegen, "src/test/resources/bugs/issue_13365.yml"); @@ -2428,7 +2427,6 @@ public void requiredFieldShouldIncludeNotNullAnnotationJakarta_issue13365_issue1 codegen.additionalProperties().put(CodegenConstants.SORT_MODEL_PROPERTIES_BY_REQUIRED_FLAG, "false"); codegen.additionalProperties().put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, "false"); codegen.additionalProperties().put(CodegenConstants.SERIALIZATION_LIBRARY, "jackson"); - codegen.additionalProperties().put(CodegenConstants.ENUM_PROPERTY_NAMING, "PascalCase"); codegen.additionalProperties().put(SpringCodegen.USE_TAGS, "true"); Map files = generateFiles(codegen, "src/test/resources/bugs/issue_13365.yml"); @@ -2457,7 +2455,6 @@ public void nonRequiredFieldShouldNotIncludeNotNullAnnotation_issue13365() throw codegen.additionalProperties().put(CodegenConstants.SORT_MODEL_PROPERTIES_BY_REQUIRED_FLAG, "false"); codegen.additionalProperties().put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, "false"); codegen.additionalProperties().put(CodegenConstants.SERIALIZATION_LIBRARY, "jackson"); - codegen.additionalProperties().put(CodegenConstants.ENUM_PROPERTY_NAMING, "PascalCase"); codegen.additionalProperties().put(SpringCodegen.USE_TAGS, "true"); Map files = generateFiles(codegen, "src/test/resources/bugs/issue_13365.yml"); @@ -2499,7 +2496,6 @@ public void requiredFieldShouldIncludeNotNullAnnotationWithBeanValidationTrue_is codegen.additionalProperties().put(CodegenConstants.SORT_MODEL_PROPERTIES_BY_REQUIRED_FLAG, "false"); codegen.additionalProperties().put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, "false"); codegen.additionalProperties().put(CodegenConstants.SERIALIZATION_LIBRARY, "jackson"); - codegen.additionalProperties().put(CodegenConstants.ENUM_PROPERTY_NAMING, "PascalCase"); codegen.additionalProperties().put(SpringCodegen.USE_TAGS, "true"); Map files = generateFiles(codegen, "src/test/resources/bugs/issue_13365.yml"); diff --git a/samples/client/others/java/okhttp-gson-streaming/docs/SomeObj.md b/samples/client/others/java/okhttp-gson-streaming/docs/SomeObj.md index d27439c839f1d..70bf3335f7bed 100644 --- a/samples/client/others/java/okhttp-gson-streaming/docs/SomeObj.md +++ b/samples/client/others/java/okhttp-gson-streaming/docs/SomeObj.md @@ -19,7 +19,7 @@ | Name | Value | |---- | -----| -| SOME_OBJ_IDENTIFIER | "SomeObjIdentifier" | +| SOMEOBJIDENTIFIER | "SomeObjIdentifier" | ## Implemented Interfaces diff --git a/samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/model/SomeObj.java b/samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/model/SomeObj.java index 2fce672f6c465..b6f61f7872eb6 100644 --- a/samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/model/SomeObj.java +++ b/samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/model/SomeObj.java @@ -58,7 +58,7 @@ public class SomeObj implements Serializable { */ @JsonAdapter(TypeEnum.Adapter.class) public enum TypeEnum { - SOME_OBJ_IDENTIFIER("SomeObjIdentifier"); + SOMEOBJIDENTIFIER("SomeObjIdentifier"); private String value; @@ -106,7 +106,7 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti public static final String SERIALIZED_NAME_$_TYPE = "$_type"; @SerializedName(SERIALIZED_NAME_$_TYPE) @javax.annotation.Nullable - private TypeEnum $type = TypeEnum.SOME_OBJ_IDENTIFIER; + private TypeEnum $type = TypeEnum.SOMEOBJIDENTIFIER; public static final String SERIALIZED_NAME_ID = "id"; @SerializedName(SERIALIZED_NAME_ID)