diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractRustCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractRustCodegen.java index 92b6347afc4..d5457abba34 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractRustCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractRustCodegen.java @@ -173,6 +173,11 @@ public abstract class AbstractRustCodegen extends DefaultCodegen implements Code @Override public String toEnumVarName(String name, String datatype) { + // Empty strings need to be mapped to "Empty" + // https://github.com/OpenAPITools/openapi-generator/issues/13453 + if (Strings.isNullOrEmpty(name)) { + return "Empty"; + } // Rust Enum variants should be camel cased return sanitizeIdentifier(name, CasingType.CAMEL_CASE, "variant", "enum variant", true); } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/rust/AbstractRustCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/rust/AbstractRustCodegenTest.java index ab15ef827fa..f341c264051 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/rust/AbstractRustCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/rust/AbstractRustCodegenTest.java @@ -117,6 +117,9 @@ public class AbstractRustCodegenTest { Assert.assertEquals(fakeRustCodegen.toEnumVarName("SCREAMING_SNAKE_CASE", null), "ScreamingSnakeCase"); // Prefix is added when starting with a number Assert.assertEquals(fakeRustCodegen.toEnumVarName("1_pending", null), "Variant1Pending"); + // Empty strings need to be mapped to "Empty" + // https://github.com/OpenAPITools/openapi-generator/issues/13453 + Assert.assertEquals(fakeRustCodegen.toEnumVarName("", null), "Empty"); } @Test diff --git a/modules/openapi-generator/src/test/resources/3_0/rust/petstore.yaml b/modules/openapi-generator/src/test/resources/3_0/rust/petstore.yaml index b7000126a0c..deaf6dd0860 100644 --- a/modules/openapi-generator/src/test/resources/3_0/rust/petstore.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/rust/petstore.yaml @@ -812,9 +812,11 @@ components: - $ref: '#/components/schemas/Baz' - nullable: false Baz: + description: Test handling of empty variants enum: - A - B + - "" type: string TypeTesting: description: Test handling of different field data types diff --git a/samples/client/petstore/rust/.openapi-generator/VERSION b/samples/client/petstore/rust/.openapi-generator/VERSION deleted file mode 100644 index 479c313e87b..00000000000 --- a/samples/client/petstore/rust/.openapi-generator/VERSION +++ /dev/null @@ -1 +0,0 @@ -4.0.3-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/rust/docs/InlineObject.md b/samples/client/petstore/rust/docs/InlineObject.md deleted file mode 100644 index bfe33a4efb3..00000000000 --- a/samples/client/petstore/rust/docs/InlineObject.md +++ /dev/null @@ -1,12 +0,0 @@ -# InlineObject - -## Properties - -Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -**name** | **String** | Updated name of the pet | [optional] -**status** | **String** | Updated status of the pet | [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/rust/docs/InlineObject1.md b/samples/client/petstore/rust/docs/InlineObject1.md deleted file mode 100644 index 930d10cdcbf..00000000000 --- a/samples/client/petstore/rust/docs/InlineObject1.md +++ /dev/null @@ -1,12 +0,0 @@ -# InlineObject1 - -## Properties - -Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -**additional_metadata** | **String** | Additional data to pass to server | [optional] -**file** | [***std::path::PathBuf**](std::path::PathBuf.md) | file to upload | [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/rust/hyper/petstore/src/models/baz.rs b/samples/client/petstore/rust/hyper/petstore/src/models/baz.rs index 8a07bf66198..94f8c5aa6aa 100644 --- a/samples/client/petstore/rust/hyper/petstore/src/models/baz.rs +++ b/samples/client/petstore/rust/hyper/petstore/src/models/baz.rs @@ -8,14 +8,17 @@ * Generated by: https://openapi-generator.tech */ +/// Baz : Test handling of empty variants -/// +/// Test handling of empty variants #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)] pub enum Baz { #[serde(rename = "A")] A, #[serde(rename = "B")] B, + #[serde(rename = "")] + Empty, } @@ -24,6 +27,7 @@ impl ToString for Baz { match self { Self::A => String::from("A"), Self::B => String::from("B"), + Self::Empty => String::from(""), } } } diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/models/baz.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/models/baz.rs index 8a07bf66198..94f8c5aa6aa 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/models/baz.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/models/baz.rs @@ -8,14 +8,17 @@ * Generated by: https://openapi-generator.tech */ +/// Baz : Test handling of empty variants -/// +/// Test handling of empty variants #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)] pub enum Baz { #[serde(rename = "A")] A, #[serde(rename = "B")] B, + #[serde(rename = "")] + Empty, } @@ -24,6 +27,7 @@ impl ToString for Baz { match self { Self::A => String::from("A"), Self::B => String::from("B"), + Self::Empty => String::from(""), } } } diff --git a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/models/baz.rs b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/models/baz.rs index 8a07bf66198..94f8c5aa6aa 100644 --- a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/models/baz.rs +++ b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/models/baz.rs @@ -8,14 +8,17 @@ * Generated by: https://openapi-generator.tech */ +/// Baz : Test handling of empty variants -/// +/// Test handling of empty variants #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)] pub enum Baz { #[serde(rename = "A")] A, #[serde(rename = "B")] B, + #[serde(rename = "")] + Empty, } @@ -24,6 +27,7 @@ impl ToString for Baz { match self { Self::A => String::from("A"), Self::B => String::from("B"), + Self::Empty => String::from(""), } } } diff --git a/samples/client/petstore/rust/reqwest/petstore/src/models/baz.rs b/samples/client/petstore/rust/reqwest/petstore/src/models/baz.rs index 8a07bf66198..94f8c5aa6aa 100644 --- a/samples/client/petstore/rust/reqwest/petstore/src/models/baz.rs +++ b/samples/client/petstore/rust/reqwest/petstore/src/models/baz.rs @@ -8,14 +8,17 @@ * Generated by: https://openapi-generator.tech */ +/// Baz : Test handling of empty variants -/// +/// Test handling of empty variants #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)] pub enum Baz { #[serde(rename = "A")] A, #[serde(rename = "B")] B, + #[serde(rename = "")] + Empty, } @@ -24,6 +27,7 @@ impl ToString for Baz { match self { Self::A => String::from("A"), Self::B => String::from("B"), + Self::Empty => String::from(""), } } } diff --git a/samples/client/petstore/rust/src/models/inline_object.rs b/samples/client/petstore/rust/src/models/inline_object.rs deleted file mode 100644 index b1444810dcf..00000000000 --- a/samples/client/petstore/rust/src/models/inline_object.rs +++ /dev/null @@ -1,32 +0,0 @@ -/* - * OpenAPI Petstore - * - * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. - * - * The version of the OpenAPI document: 1.0.0 - * - * Generated by: https://openapi-generator.tech - */ - - - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -pub struct InlineObject { - /// Updated name of the pet - #[serde(rename = "name", skip_serializing_if = "Option::is_none")] - pub name: Option, - /// Updated status of the pet - #[serde(rename = "status", skip_serializing_if = "Option::is_none")] - pub status: Option, -} - -impl InlineObject { - pub fn new() -> InlineObject { - InlineObject { - name: None, - status: None, - } - } -} - - diff --git a/samples/client/petstore/rust/src/models/inline_object_1.rs b/samples/client/petstore/rust/src/models/inline_object_1.rs deleted file mode 100644 index ee4c1b78ae5..00000000000 --- a/samples/client/petstore/rust/src/models/inline_object_1.rs +++ /dev/null @@ -1,32 +0,0 @@ -/* - * OpenAPI Petstore - * - * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. - * - * The version of the OpenAPI document: 1.0.0 - * - * Generated by: https://openapi-generator.tech - */ - - - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -pub struct InlineObject1 { - /// Additional data to pass to server - #[serde(rename = "additionalMetadata", skip_serializing_if = "Option::is_none")] - pub additional_metadata: Option, - /// file to upload - #[serde(rename = "file", skip_serializing_if = "Option::is_none")] - pub file: Option, -} - -impl InlineObject1 { - pub fn new() -> InlineObject1 { - InlineObject1 { - additional_metadata: None, - file: None, - } - } -} - - diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/200_response.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/200_response.cpp new file mode 100644 index 00000000000..c28bfae43a7 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/200_response.cpp @@ -0,0 +1,118 @@ +/** + * 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: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI-Generator 6.1.0-SNAPSHOT. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + + +#include "200_response.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "helpers.h" + +using boost::property_tree::ptree; +using boost::property_tree::read_json; +using boost::property_tree::write_json; + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +200_response::200_response(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string 200_response::toJsonString(bool prettyJson /* = false */) const +{ + std::stringstream ss; + write_json(ss, this->toPropertyTree(), prettyJson); + // workaround inspired by: https://stackoverflow.com/a/56395440 + std::regex reg("\\\"([0-9]+\\.{0,1}[0-9]*)\\\""); + std::string result = std::regex_replace(ss.str(), reg, "$1"); + return result; +} + +void 200_response::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree 200_response::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + pt.put("name", m_Name); + pt.put("class", m_r_class); + return pt; +} + +void 200_response::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; + m_Name = pt.get("name", 0); + m_r_class = pt.get("class", ""); +} + +int32_t 200_response::getName() const +{ + return m_Name; +} + +void 200_response::setName(int32_t value) +{ + m_Name = value; +} + + +std::string 200_response::getRClass() const +{ + return m_r_class; +} + +void 200_response::setRClass(std::string value) +{ + m_r_class = value; +} + + + +std::vector<200_response> create200_responseVectorFromJsonString(const std::string& json) +{ + std::stringstream sstream(json); + boost::property_tree::ptree pt; + boost::property_tree::json_parser::read_json(sstream,pt); + + auto vec = std::vector<200_response>(); + for (const auto& child: pt) { + vec.emplace_back(200_response(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/200_response.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/200_response.h new file mode 100644 index 00000000000..cb325c759f1 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/200_response.h @@ -0,0 +1,96 @@ +/** + * 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: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI-Generator 6.1.0-SNAPSHOT. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +/* + * 200_response.h + * + * Model for testing model name starting with number + */ + +#ifndef 200_response_H_ +#define 200_response_H_ + + + +#include +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// Model for testing model name starting with number +/// +class 200_response +{ +public: + 200_response() = default; + explicit 200_response(boost::property_tree::ptree const& pt); + virtual ~200_response() = default; + + 200_response(const 200_response& other) = default; // copy constructor + 200_response(200_response&& other) noexcept = default; // move constructor + + 200_response& operator=(const 200_response& other) = default; // copy assignment + 200_response& operator=(200_response&& other) noexcept = default; // move assignment + + std::string toJsonString(bool prettyJson = false) const; + void fromJsonString(std::string const& jsonString); + boost::property_tree::ptree toPropertyTree() const; + void fromPropertyTree(boost::property_tree::ptree const& pt); + + + ///////////////////////////////////////////// + /// 200_response members + + /// + /// + /// + int32_t getName() const; + void setName(int32_t value); + + /// + /// + /// + std::string getRClass() const; + void setRClass(std::string value); + +protected: + int32_t m_Name = 0; + std::string m_r_class = ""; +}; + +std::vector<200_response> create200_responseVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt<200_response>(const 200_response& val) { + return val.toPropertyTree(); +} + +template<> +inline 200_response fromPt<200_response>(const boost::property_tree::ptree& pt) { + 200_response ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* 200_response_H_ */ diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithArrayInputThrowsStdExceptionDerivedException.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithArrayInputThrowsStdExceptionDerivedException.approved.txt deleted file mode 100644 index bc8d2c1aebf..00000000000 --- a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithArrayInputThrowsStdExceptionDerivedException.approved.txt +++ /dev/null @@ -1,3 +0,0 @@ -Status code: 500 INTERNAL_SERVER_ERROR -Reason: std::logic_error raised -Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithListInputThrowsStdExceptionDerivedException.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithListInputThrowsStdExceptionDerivedException.approved.txt deleted file mode 100644 index bc8d2c1aebf..00000000000 --- a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithListInputThrowsStdExceptionDerivedException.approved.txt +++ /dev/null @@ -1,3 +0,0 @@ -Status code: 500 INTERNAL_SERVER_ERROR -Reason: std::logic_error raised -Response headers: [Connection:"close"] \ No newline at end of file