diff --git a/bin/configs/rust-reqwest-discriminated-union.yaml b/bin/configs/rust-reqwest-discriminated-union.yaml new file mode 100644 index 000000000000..98ab3aca1947 --- /dev/null +++ b/bin/configs/rust-reqwest-discriminated-union.yaml @@ -0,0 +1,8 @@ +generatorName: rust +outputDir: samples/client/others/rust/reqwest/discriminated-union +library: reqwest +inputSpec: modules/openapi-generator/src/test/resources/3_0/rust/discriminated-union.yaml +templateDir: modules/openapi-generator/src/main/resources/rust +additionalProperties: + supportAsync: false + packageName: discriminated-union diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java index d2d4dcc51fd9..a7978c857460 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java @@ -333,6 +333,42 @@ public CodegenModel fromModel(String name, Schema model) { return mdl; } + @Override + public Map postProcessAllModels(Map objs) { + objs = super.postProcessAllModels(objs); + + for (ModelsMap modelsMap : objs.values()) { + for (ModelMap modelMap : modelsMap.getModels()) { + CodegenModel cm = modelMap.getModel(); + CodegenDiscriminator discriminator = cm.discriminator; + if (discriminator == null || discriminator.getMappedModels() == null) { + continue; + } + // a mapping that names the base itself leaves no struct to wrap, and an enum-typed tag would be + // written twice (the child's copy keeps its default): keep the inline variants + if (discriminator.getMappedModels().stream().anyMatch(m -> cm.name.equals(m.getSchemaName())) + || cm.allVars.stream().anyMatch(v -> discriminator.getPropertyBaseName().equals(v.baseName) && v.getIsEnumOrRef())) { + discriminator.getVendorExtensions().put("x-rust-inline-variants", true); + continue; + } + // a mapped child's discriminator doubles as the union's serde tag, which is consumed before the + // child deserializes: mark it so the template defaults it and skips it while unset + for (CodegenDiscriminator.MappedModel mapped : discriminator.getMappedModels()) { + if (mapped.getModel() == null) { + continue; + } + for (CodegenProperty var : mapped.getModel().vars) { + if (discriminator.getPropertyBaseName().equals(var.baseName)) { + var.isDiscriminator = true; + } + } + } + } + } + + return objs; + } + @Override public ModelsMap postProcessModels(ModelsMap objs) { for (ModelMap model : objs.getModels()) { diff --git a/modules/openapi-generator/src/main/resources/rust/model.mustache b/modules/openapi-generator/src/main/resources/rust/model.mustache index a2c60b117a45..3a89ab2299c0 100644 --- a/modules/openapi-generator/src/main/resources/rust/model.mustache +++ b/modules/openapi-generator/src/main/resources/rust/model.mustache @@ -84,6 +84,11 @@ pub enum {{{classname}}} { {{^oneOf}} {{#mappedModels}} #[serde(rename="{{mappingName}}")] + {{^vendorExtensions.x-rust-inline-variants}} + {{!-- newtype variant: the child's own fields survive; named by modelName (unique per mapping), wraps the real classname --}} + {{{modelName}}}({{^avoidBoxedModels}}Box<{{/avoidBoxedModels}}models::{{#model}}{{{classname}}}{{/model}}{{^model}}{{{modelName}}}{{/model}}{{^avoidBoxedModels}}>{{/avoidBoxedModels}}), + {{/vendorExtensions.x-rust-inline-variants}} + {{#vendorExtensions.x-rust-inline-variants}} {{{modelName}}} { {{#vars}} {{#description}} @@ -93,6 +98,7 @@ pub enum {{{classname}}} { {{{name}}}: {{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{^required}}Option<{{/required}}{{#isEnum}}{{{enumName}}}{{/isEnum}}{{^isEnum}}{{#isModel}}{{^avoidBoxedModels}}Box<{{/avoidBoxedModels}}{{{dataType}}}{{^avoidBoxedModels}}>{{/avoidBoxedModels}}{{/isModel}}{{^isModel}}{{{dataType}}}{{/isModel}}{{/isEnum}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{^required}}>{{/required}}, {{/vars}} }, + {{/vendorExtensions.x-rust-inline-variants}} {{/mappedModels}} {{/oneOf}} {{^oneOf.isEmpty}} @@ -110,11 +116,11 @@ pub enum {{{classname}}} { impl Default for {{classname}} { fn default() -> Self { - {{^oneOf}}{{#mappedModels}}{{#-first}}Self::{{modelName}} { + {{^oneOf}}{{#mappedModels}}{{#-first}}{{^vendorExtensions.x-rust-inline-variants}}Self::{{modelName}}(Default::default()){{/vendorExtensions.x-rust-inline-variants}}{{#vendorExtensions.x-rust-inline-variants}}Self::{{modelName}} { {{#vars}} {{{name}}}: Default::default(), {{/vars}} - }{{/-first}}{{/mappedModels}} + }{{/vendorExtensions.x-rust-inline-variants}}{{/-first}}{{/mappedModels}} {{/oneOf}}{{^oneOf.isEmpty}}{{#composedSchemas.oneOf}}{{#-first}}Self::{{{name}}}(Default::default()){{/-first}}{{/composedSchemas.oneOf}}{{/oneOf.isEmpty}} } } @@ -133,7 +139,8 @@ pub struct {{{classname}}} { {{#isByteArray}} {{#vendorExtensions.isMandatory}}#[serde_as(as = "serde_with::base64::Base64")]{{/vendorExtensions.isMandatory}}{{^vendorExtensions.isMandatory}}#[serde_as(as = "{{^serdeAsDoubleOption}}Option{{/serdeAsDoubleOption}}{{#serdeAsDoubleOption}}super::DoubleOption{{/serdeAsDoubleOption}}")]{{/vendorExtensions.isMandatory}} {{/isByteArray}} - #[serde(rename = "{{{baseName}}}"{{^required}}{{#isNullable}}, default{{^isByteArray}}, with = "::serde_with::rust::double_option"{{/isByteArray}}{{/isNullable}}{{/required}}{{^required}}, skip_serializing_if = "Option::is_none"{{/required}}{{#required}}{{#isNullable}}, deserialize_with = "Option::deserialize"{{/isNullable}}{{/required}})] + {{!-- a mapped child's discriminator is the union's consumed serde tag: default it, skip it while unset --}} + #[serde(rename = "{{{baseName}}}"{{#isDiscriminator}}{{#required}}, default{{#isNullable}}, skip_serializing_if = "Option::is_none"{{/isNullable}}{{^isNullable}}{{#isString}}{{^isEnum}}, skip_serializing_if = "String::is_empty"{{/isEnum}}{{/isString}}{{/isNullable}}{{/required}}{{/isDiscriminator}}{{^required}}{{#isNullable}}, default{{^isByteArray}}, with = "::serde_with::rust::double_option"{{/isByteArray}}{{/isNullable}}{{/required}}{{^required}}, skip_serializing_if = "Option::is_none"{{/required}}{{#required}}{{#isNullable}}{{^isDiscriminator}}, deserialize_with = "Option::deserialize"{{/isDiscriminator}}{{/isNullable}}{{/required}})] pub {{{name}}}: {{! ### Option Start }}{{#isNullable}}Option<{{/isNullable}}{{^required}}Option<{{/required}}{{! diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/rust/RustClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/rust/RustClientCodegenTest.java index 6f8a164ea40d..97d31d8a15d7 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/rust/RustClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/rust/RustClientCodegenTest.java @@ -298,6 +298,49 @@ public void testMultipleArrayTypesEnum() throws IOException { TestUtils.assertFileContains(outputPath, enumSpec); } + @Test + public void testDiscriminatedUnionKeepsChildFields() throws IOException { + Path target = Files.createTempDirectory("test"); + target.toFile().deleteOnExit(); + final CodegenConfigurator configurator = new CodegenConfigurator() + .setGeneratorName("rust") + .setInputSpec("src/test/resources/3_0/rust/discriminated-union.yaml") + .setSkipOverwrite(false) + .setOutputDir(target.toAbsolutePath().toString().replace("\\", "/")); + new DefaultGenerator().opts(configurator.toClientOptInput()).generate(); + + // newtype variants, so the child's own fields survive + Path unionPath = Path.of(target.toString(), "/src/models/api_error.rs"); + TestUtils.assertFileContains(unionPath, "#[serde(tag = \"type\")]"); + TestUtils.assertFileContains(unionPath, "ObjectExists(Box),"); + TestUtils.assertFileContains(unionPath, "ValidationError(Box),"); + TestUtils.assertFileContains(unionPath, "Self::ObjectExists(Default::default())"); + TestUtils.assertFileNotContains(unionPath, "ObjectExists {"); + + // the consumed tag key defaults and is skipped while unset; standalone field and new() unchanged + Path childPath = Path.of(target.toString(), "/src/models/object_exists.rs"); + TestUtils.assertFileContains(childPath, + "#[serde(rename = \"type\", default, skip_serializing_if = \"String::is_empty\")]", + "pub identifier: String,", + "pub fn new(r#type: String, message: String, identifier: String) -> ObjectExists {"); + TestUtils.assertFileContains(Path.of(target.toString(), "/src/models/alpha.rs"), + "#[serde(rename = \"kind\", default, skip_serializing_if = \"Option::is_none\")]"); + // an enum-typed tag would be written twice, the child's copy keeping its default: inline variants, children untouched + TestUtils.assertFileContains(Path.of(target.toString(), "/src/models/pet.rs"), + "#[serde(rename=\"Cat\")]\n Cat {", "#[serde(rename=\"Dog\")]\n Dog {"); + TestUtils.assertFileNotContains(Path.of(target.toString(), "/src/models/pet.rs"), "Box"); + TestUtils.assertFileContains(Path.of(target.toString(), "/src/models/cat.rs"), "#[serde(rename = \"petType\")]\n pub pet_type: PetType,"); + TestUtils.assertFileContains(Path.of(target.toString(), "/src/models/shape.rs"), "#[serde(rename=\"circle\")]\n Circle {"); + TestUtils.assertFileContains(Path.of(target.toString(), "/src/models/circle.rs"), "#[serde(rename = \"kind\")]\n pub kind: models::ShapeKind,"); + + // a mapping that names the base itself leaves no struct to wrap (E0275): inline variants, children untouched + TestUtils.assertFileContains(Path.of(target.toString(), "/src/models/creature.rs"), + "#[serde(rename=\"Creature\")]\n Creature {", "#[serde(rename=\"Bird\")]\n Bird {"); + TestUtils.assertFileNotContains(Path.of(target.toString(), "/src/models/creature.rs"), "Box"); + TestUtils.assertFileContains(Path.of(target.toString(), "/src/models/creature.rs"), "#[serde(tag = \"kind\")]"); + TestUtils.assertFileContains(Path.of(target.toString(), "/src/models/bird.rs"), "#[serde(rename = \"kind\")]\n pub kind: String,"); + } + @Test public void testIntegerPropertyEnum() throws IOException { Path target = Files.createTempDirectory("test"); diff --git a/modules/openapi-generator/src/test/resources/3_0/rust/discriminated-union.yaml b/modules/openapi-generator/src/test/resources/3_0/rust/discriminated-union.yaml new file mode 100644 index 000000000000..c7c9b6010033 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/rust/discriminated-union.yaml @@ -0,0 +1,143 @@ +openapi: 3.0.3 +info: + title: discriminated union + version: 1.0.0 +paths: + /errors: + get: + operationId: getError + responses: + '200': + description: ok + content: + application/json: + schema: + $ref: '#/components/schemas/ApiError' +components: + schemas: + ApiError: + type: object + required: + - type + - message + properties: + type: + type: string + message: + type: string + discriminator: + propertyName: type + mapping: + ObjectExists: '#/components/schemas/ObjectExists' + ValidationError: '#/components/schemas/ValidationError' + ObjectExists: + allOf: + - $ref: '#/components/schemas/ApiError' + - type: object + required: + - identifier + properties: + identifier: + type: string + objectType: + type: string + ValidationError: + allOf: + - $ref: '#/components/schemas/ApiError' + - type: object + properties: + field: + type: string + # nullable discriminator: String::is_empty would not compile against it + NullableTagged: + type: object + required: + - kind + properties: + kind: + type: string + nullable: true + label: + type: string + discriminator: + propertyName: kind + mapping: + Alpha: '#/components/schemas/Alpha' + Alpha: + allOf: + - $ref: '#/components/schemas/NullableTagged' + - type: object + properties: + alphaOnly: + type: string + # enum-typed discriminators, inline and $ref: the union keeps the inline variants + Pet: + type: object + required: + - petType + properties: + petType: + type: string + enum: [Cat, Dog] + discriminator: + propertyName: petType + mapping: + Cat: '#/components/schemas/Cat' + Dog: '#/components/schemas/Dog' + Cat: + allOf: + - $ref: '#/components/schemas/Pet' + - type: object + properties: + lives: + type: integer + Dog: + allOf: + - $ref: '#/components/schemas/Pet' + - type: object + properties: + bark: + type: boolean + ShapeKind: + type: string + enum: [circle] + Shape: + type: object + required: + - kind + properties: + kind: + $ref: '#/components/schemas/ShapeKind' + discriminator: + propertyName: kind + mapping: + circle: '#/components/schemas/Circle' + Circle: + allOf: + - $ref: '#/components/schemas/Shape' + - type: object + properties: + radius: + type: number + # the mapping names the base itself: no struct to wrap, so the union keeps the inline variants + Creature: + type: object + required: + - kind + properties: + kind: + type: string + name: + type: string + discriminator: + propertyName: kind + mapping: + Creature: '#/components/schemas/Creature' + Bird: '#/components/schemas/Bird' + Bird: + allOf: + - $ref: '#/components/schemas/Creature' + - type: object + properties: + wingspan: + type: number diff --git a/samples/client/others/rust/hyper/oneOf/src/models/bar.rs b/samples/client/others/rust/hyper/oneOf/src/models/bar.rs index ed85518807f2..0e5acbf27e4d 100644 --- a/samples/client/others/rust/hyper/oneOf/src/models/bar.rs +++ b/samples/client/others/rust/hyper/oneOf/src/models/bar.rs @@ -25,7 +25,7 @@ pub struct Bar { #[serde(rename = "@baseType", skip_serializing_if = "Option::is_none")] pub at_base_type: Option, /// When sub-classing, this defines the sub-class Extensible name - #[serde(rename = "@type")] + #[serde(rename = "@type", default, skip_serializing_if = "String::is_empty")] pub at_type: String, #[serde(rename = "barPropA", skip_serializing_if = "Option::is_none")] pub bar_prop_a: Option, diff --git a/samples/client/others/rust/hyper/oneOf/src/models/bar_create.rs b/samples/client/others/rust/hyper/oneOf/src/models/bar_create.rs index 98481c64e2f9..3a0da7cd7500 100644 --- a/samples/client/others/rust/hyper/oneOf/src/models/bar_create.rs +++ b/samples/client/others/rust/hyper/oneOf/src/models/bar_create.rs @@ -26,7 +26,7 @@ pub struct BarCreate { #[serde(rename = "@baseType", skip_serializing_if = "Option::is_none")] pub at_base_type: Option, /// When sub-classing, this defines the sub-class Extensible name - #[serde(rename = "@type")] + #[serde(rename = "@type", default, skip_serializing_if = "String::is_empty")] pub at_type: String, #[serde(rename = "barPropA", skip_serializing_if = "Option::is_none")] pub bar_prop_a: Option, diff --git a/samples/client/others/rust/hyper/oneOf/src/models/bar_ref.rs b/samples/client/others/rust/hyper/oneOf/src/models/bar_ref.rs index ce4ee09caf9d..07ca991d8627 100644 --- a/samples/client/others/rust/hyper/oneOf/src/models/bar_ref.rs +++ b/samples/client/others/rust/hyper/oneOf/src/models/bar_ref.rs @@ -26,7 +26,7 @@ pub struct BarRef { #[serde(rename = "@baseType", skip_serializing_if = "Option::is_none")] pub at_base_type: Option, /// When sub-classing, this defines the sub-class Extensible name - #[serde(rename = "@type")] + #[serde(rename = "@type", default, skip_serializing_if = "String::is_empty")] pub at_type: String, /// Name of the related entity. #[serde(rename = "name", skip_serializing_if = "Option::is_none")] diff --git a/samples/client/others/rust/hyper/oneOf/src/models/entity.rs b/samples/client/others/rust/hyper/oneOf/src/models/entity.rs index bfb1aac3382c..6f6c47efe667 100644 --- a/samples/client/others/rust/hyper/oneOf/src/models/entity.rs +++ b/samples/client/others/rust/hyper/oneOf/src/models/entity.rs @@ -15,105 +15,22 @@ use serde::{Deserialize, Serialize}; #[serde(tag = "@type")] pub enum Entity { #[serde(rename="Bar")] - Bar { - /// Hyperlink reference - #[serde(rename = "href", skip_serializing_if = "Option::is_none")] - href: Option, - /// unique identifier - #[serde(rename = "id", skip_serializing_if = "Option::is_none")] - id: Option, - /// A URI to a JSON-Schema file that defines additional attributes and relationships - #[serde(rename = "@schemaLocation", skip_serializing_if = "Option::is_none")] - at_schema_location: Option, - /// When sub-classing, this defines the super-class - #[serde(rename = "@baseType", skip_serializing_if = "Option::is_none")] - at_base_type: Option, - }, + Bar(Box), #[serde(rename="Bar_Create")] - BarCreate { - /// Hyperlink reference - #[serde(rename = "href", skip_serializing_if = "Option::is_none")] - href: Option, - /// unique identifier - #[serde(rename = "id", skip_serializing_if = "Option::is_none")] - id: Option, - /// A URI to a JSON-Schema file that defines additional attributes and relationships - #[serde(rename = "@schemaLocation", skip_serializing_if = "Option::is_none")] - at_schema_location: Option, - /// When sub-classing, this defines the super-class - #[serde(rename = "@baseType", skip_serializing_if = "Option::is_none")] - at_base_type: Option, - }, + BarCreate(Box), #[serde(rename="Foo")] - Foo { - /// Hyperlink reference - #[serde(rename = "href", skip_serializing_if = "Option::is_none")] - href: Option, - /// unique identifier - #[serde(rename = "id", skip_serializing_if = "Option::is_none")] - id: Option, - /// A URI to a JSON-Schema file that defines additional attributes and relationships - #[serde(rename = "@schemaLocation", skip_serializing_if = "Option::is_none")] - at_schema_location: Option, - /// When sub-classing, this defines the super-class - #[serde(rename = "@baseType", skip_serializing_if = "Option::is_none")] - at_base_type: Option, - }, + Foo(Box), #[serde(rename="Pasta")] - Pasta { - /// Hyperlink reference - #[serde(rename = "href", skip_serializing_if = "Option::is_none")] - href: Option, - /// unique identifier - #[serde(rename = "id", skip_serializing_if = "Option::is_none")] - id: Option, - /// A URI to a JSON-Schema file that defines additional attributes and relationships - #[serde(rename = "@schemaLocation", skip_serializing_if = "Option::is_none")] - at_schema_location: Option, - /// When sub-classing, this defines the super-class - #[serde(rename = "@baseType", skip_serializing_if = "Option::is_none")] - at_base_type: Option, - }, + Pasta(Box), #[serde(rename="Pizza")] - Pizza { - /// Hyperlink reference - #[serde(rename = "href", skip_serializing_if = "Option::is_none")] - href: Option, - /// unique identifier - #[serde(rename = "id", skip_serializing_if = "Option::is_none")] - id: Option, - /// A URI to a JSON-Schema file that defines additional attributes and relationships - #[serde(rename = "@schemaLocation", skip_serializing_if = "Option::is_none")] - at_schema_location: Option, - /// When sub-classing, this defines the super-class - #[serde(rename = "@baseType", skip_serializing_if = "Option::is_none")] - at_base_type: Option, - }, + Pizza(Box), #[serde(rename="PizzaSpeziale")] - PizzaSpeziale { - /// Hyperlink reference - #[serde(rename = "href", skip_serializing_if = "Option::is_none")] - href: Option, - /// unique identifier - #[serde(rename = "id", skip_serializing_if = "Option::is_none")] - id: Option, - /// A URI to a JSON-Schema file that defines additional attributes and relationships - #[serde(rename = "@schemaLocation", skip_serializing_if = "Option::is_none")] - at_schema_location: Option, - /// When sub-classing, this defines the super-class - #[serde(rename = "@baseType", skip_serializing_if = "Option::is_none")] - at_base_type: Option, - }, + PizzaSpeziale(Box), } impl Default for Entity { fn default() -> Self { - Self::Bar { - href: Default::default(), - id: Default::default(), - at_schema_location: Default::default(), - at_base_type: Default::default(), - } + Self::Bar(Default::default()) } } diff --git a/samples/client/others/rust/hyper/oneOf/src/models/entity_ref.rs b/samples/client/others/rust/hyper/oneOf/src/models/entity_ref.rs index d1a9853dc89b..ea762128d931 100644 --- a/samples/client/others/rust/hyper/oneOf/src/models/entity_ref.rs +++ b/samples/client/others/rust/hyper/oneOf/src/models/entity_ref.rs @@ -15,59 +15,14 @@ use serde::{Deserialize, Serialize}; #[serde(tag = "@type")] pub enum EntityRef { #[serde(rename="BarRef")] - BarRef { - /// Hyperlink reference - #[serde(rename = "href", skip_serializing_if = "Option::is_none")] - href: Option, - /// unique identifier - #[serde(rename = "id", skip_serializing_if = "Option::is_none")] - id: Option, - /// A URI to a JSON-Schema file that defines additional attributes and relationships - #[serde(rename = "@schemaLocation", skip_serializing_if = "Option::is_none")] - at_schema_location: Option, - /// When sub-classing, this defines the super-class - #[serde(rename = "@baseType", skip_serializing_if = "Option::is_none")] - at_base_type: Option, - /// Name of the related entity. - #[serde(rename = "name", skip_serializing_if = "Option::is_none")] - name: Option, - /// The actual type of the target instance when needed for disambiguation. - #[serde(rename = "@referredType", skip_serializing_if = "Option::is_none")] - at_referred_type: Option, - }, + BarRef(Box), #[serde(rename="FooRef")] - FooRef { - /// Hyperlink reference - #[serde(rename = "href", skip_serializing_if = "Option::is_none")] - href: Option, - /// unique identifier - #[serde(rename = "id", skip_serializing_if = "Option::is_none")] - id: Option, - /// A URI to a JSON-Schema file that defines additional attributes and relationships - #[serde(rename = "@schemaLocation", skip_serializing_if = "Option::is_none")] - at_schema_location: Option, - /// When sub-classing, this defines the super-class - #[serde(rename = "@baseType", skip_serializing_if = "Option::is_none")] - at_base_type: Option, - /// Name of the related entity. - #[serde(rename = "name", skip_serializing_if = "Option::is_none")] - name: Option, - /// The actual type of the target instance when needed for disambiguation. - #[serde(rename = "@referredType", skip_serializing_if = "Option::is_none")] - at_referred_type: Option, - }, + FooRef(Box), } impl Default for EntityRef { fn default() -> Self { - Self::BarRef { - href: Default::default(), - id: Default::default(), - at_schema_location: Default::default(), - at_base_type: Default::default(), - name: Default::default(), - at_referred_type: Default::default(), - } + Self::BarRef(Default::default()) } } diff --git a/samples/client/others/rust/hyper/oneOf/src/models/foo.rs b/samples/client/others/rust/hyper/oneOf/src/models/foo.rs index becc6957dd5d..6365749a7432 100644 --- a/samples/client/others/rust/hyper/oneOf/src/models/foo.rs +++ b/samples/client/others/rust/hyper/oneOf/src/models/foo.rs @@ -26,7 +26,7 @@ pub struct Foo { #[serde(rename = "@baseType", skip_serializing_if = "Option::is_none")] pub at_base_type: Option, /// When sub-classing, this defines the sub-class Extensible name - #[serde(rename = "@type")] + #[serde(rename = "@type", default, skip_serializing_if = "String::is_empty")] pub at_type: String, #[serde(rename = "fooPropA", skip_serializing_if = "Option::is_none")] pub foo_prop_a: Option, diff --git a/samples/client/others/rust/hyper/oneOf/src/models/foo_ref.rs b/samples/client/others/rust/hyper/oneOf/src/models/foo_ref.rs index f4b3a2837fb7..09d760d3bae1 100644 --- a/samples/client/others/rust/hyper/oneOf/src/models/foo_ref.rs +++ b/samples/client/others/rust/hyper/oneOf/src/models/foo_ref.rs @@ -26,7 +26,7 @@ pub struct FooRef { #[serde(rename = "@baseType", skip_serializing_if = "Option::is_none")] pub at_base_type: Option, /// When sub-classing, this defines the sub-class Extensible name - #[serde(rename = "@type")] + #[serde(rename = "@type", default, skip_serializing_if = "String::is_empty")] pub at_type: String, /// Name of the related entity. #[serde(rename = "name", skip_serializing_if = "Option::is_none")] diff --git a/samples/client/others/rust/hyper/oneOf/src/models/pasta.rs b/samples/client/others/rust/hyper/oneOf/src/models/pasta.rs index 5352c0da9d41..a6dec55be07b 100644 --- a/samples/client/others/rust/hyper/oneOf/src/models/pasta.rs +++ b/samples/client/others/rust/hyper/oneOf/src/models/pasta.rs @@ -26,7 +26,7 @@ pub struct Pasta { #[serde(rename = "@baseType", skip_serializing_if = "Option::is_none")] pub at_base_type: Option, /// When sub-classing, this defines the sub-class Extensible name - #[serde(rename = "@type")] + #[serde(rename = "@type", default, skip_serializing_if = "String::is_empty")] pub at_type: String, #[serde(rename = "vendor", skip_serializing_if = "Option::is_none")] pub vendor: Option, diff --git a/samples/client/others/rust/hyper/oneOf/src/models/pizza.rs b/samples/client/others/rust/hyper/oneOf/src/models/pizza.rs index b99e41a1a354..a0c7390b126f 100644 --- a/samples/client/others/rust/hyper/oneOf/src/models/pizza.rs +++ b/samples/client/others/rust/hyper/oneOf/src/models/pizza.rs @@ -26,7 +26,7 @@ pub struct Pizza { #[serde(rename = "@baseType", skip_serializing_if = "Option::is_none")] pub at_base_type: Option, /// When sub-classing, this defines the sub-class Extensible name - #[serde(rename = "@type")] + #[serde(rename = "@type", default, skip_serializing_if = "String::is_empty")] pub at_type: String, #[serde(rename = "pizzaSize", skip_serializing_if = "Option::is_none")] pub pizza_size: Option, diff --git a/samples/client/others/rust/hyper/oneOf/src/models/pizza_speziale.rs b/samples/client/others/rust/hyper/oneOf/src/models/pizza_speziale.rs index f3cfea721eff..40133bbf0304 100644 --- a/samples/client/others/rust/hyper/oneOf/src/models/pizza_speziale.rs +++ b/samples/client/others/rust/hyper/oneOf/src/models/pizza_speziale.rs @@ -26,7 +26,7 @@ pub struct PizzaSpeziale { #[serde(rename = "@baseType", skip_serializing_if = "Option::is_none")] pub at_base_type: Option, /// When sub-classing, this defines the sub-class Extensible name - #[serde(rename = "@type")] + #[serde(rename = "@type", default, skip_serializing_if = "String::is_empty")] pub at_type: String, #[serde(rename = "pizzaSize", skip_serializing_if = "Option::is_none")] pub pizza_size: Option, diff --git a/samples/client/others/rust/reqwest/discriminated-union/.gitignore b/samples/client/others/rust/reqwest/discriminated-union/.gitignore new file mode 100644 index 000000000000..6aa106405a4b --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/.gitignore @@ -0,0 +1,3 @@ +/target/ +**/*.rs.bk +Cargo.lock diff --git a/samples/client/others/rust/reqwest/discriminated-union/.openapi-generator-ignore b/samples/client/others/rust/reqwest/discriminated-union/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/client/others/rust/reqwest/discriminated-union/.openapi-generator/FILES b/samples/client/others/rust/reqwest/discriminated-union/.openapi-generator/FILES new file mode 100644 index 000000000000..827c53e18a78 --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/.openapi-generator/FILES @@ -0,0 +1,37 @@ +.gitignore +.travis.yml +Cargo.toml +README.md +docs/Alpha.md +docs/ApiError.md +docs/Bird.md +docs/Cat.md +docs/Circle.md +docs/Creature.md +docs/DefaultApi.md +docs/Dog.md +docs/NullableTagged.md +docs/ObjectExists.md +docs/Pet.md +docs/Shape.md +docs/ShapeKind.md +docs/ValidationError.md +git_push.sh +src/apis/configuration.rs +src/apis/default_api.rs +src/apis/mod.rs +src/lib.rs +src/models/alpha.rs +src/models/api_error.rs +src/models/bird.rs +src/models/cat.rs +src/models/circle.rs +src/models/creature.rs +src/models/dog.rs +src/models/mod.rs +src/models/nullable_tagged.rs +src/models/object_exists.rs +src/models/pet.rs +src/models/shape.rs +src/models/shape_kind.rs +src/models/validation_error.rs diff --git a/samples/client/others/rust/reqwest/discriminated-union/.openapi-generator/VERSION b/samples/client/others/rust/reqwest/discriminated-union/.openapi-generator/VERSION new file mode 100644 index 000000000000..32a8cfaceeb9 --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.26.0-SNAPSHOT diff --git a/samples/client/others/rust/reqwest/discriminated-union/.travis.yml b/samples/client/others/rust/reqwest/discriminated-union/.travis.yml new file mode 100644 index 000000000000..22761ba7ee19 --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/.travis.yml @@ -0,0 +1 @@ +language: rust diff --git a/samples/client/others/rust/reqwest/discriminated-union/Cargo.toml b/samples/client/others/rust/reqwest/discriminated-union/Cargo.toml new file mode 100644 index 000000000000..e8716a24a5c9 --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "discriminated-union" +version = "1.0.0" +authors = ["OpenAPI Generator team and contributors"] +description = "No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)" +# Override this license by providing a License Object in the OpenAPI. +license = "Unlicense" +edition = "2021" + +[dependencies] +serde = { version = "^1.0", features = ["derive"] } +serde_json = "^1.0" +serde_repr = "^0.1" +url = "^2.5" +reqwest = { version = "^0.13", default-features = false, features = ["json", "blocking", "multipart", "query", "form"] } + +[features] +default = ["native-tls"] +native-tls = ["reqwest/native-tls"] +rustls = ["reqwest/rustls"] diff --git a/samples/client/others/rust/reqwest/discriminated-union/README.md b/samples/client/others/rust/reqwest/discriminated-union/README.md new file mode 100644 index 000000000000..54b6b555dd10 --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/README.md @@ -0,0 +1,58 @@ +# Rust API client for discriminated-union + +No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + +## Overview + +This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [openapi-spec](https://openapis.org) from a remote server, you can easily generate an API client. + +- API version: 1.0.0 +- Package version: 1.0.0 +- Generator version: 7.26.0-SNAPSHOT +- Build package: `org.openapitools.codegen.languages.RustClientCodegen` + +## Installation + +Put the package under your project folder in a directory named `discriminated-union` and add the following to `Cargo.toml` under `[dependencies]`: + +``` +discriminated-union = { path = "./discriminated-union" } +``` + +## Documentation for API Endpoints + +All URIs are relative to *http://localhost* + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +*DefaultApi* | [**get_error**](docs/DefaultApi.md#get_error) | **GET** /errors | + + +## Documentation For Models + + - [Alpha](docs/Alpha.md) + - [ApiError](docs/ApiError.md) + - [Bird](docs/Bird.md) + - [Cat](docs/Cat.md) + - [Circle](docs/Circle.md) + - [Creature](docs/Creature.md) + - [Dog](docs/Dog.md) + - [NullableTagged](docs/NullableTagged.md) + - [ObjectExists](docs/ObjectExists.md) + - [Pet](docs/Pet.md) + - [Shape](docs/Shape.md) + - [ShapeKind](docs/ShapeKind.md) + - [ValidationError](docs/ValidationError.md) + + +To get access to the crate's generated documentation, use: + +``` +cargo doc --open +``` + +## Author + + + diff --git a/samples/client/others/rust/reqwest/discriminated-union/docs/Alpha.md b/samples/client/others/rust/reqwest/discriminated-union/docs/Alpha.md new file mode 100644 index 000000000000..0282fb09eefc --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/docs/Alpha.md @@ -0,0 +1,13 @@ +# Alpha + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**kind** | Option<**String**> | | +**label** | Option<**String**> | | [optional] +**alpha_only** | Option<**String**> | | [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/others/rust/reqwest/discriminated-union/docs/ApiError.md b/samples/client/others/rust/reqwest/discriminated-union/docs/ApiError.md new file mode 100644 index 000000000000..c39d1629e29e --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/docs/ApiError.md @@ -0,0 +1,10 @@ +# ApiError + +## Enum Variants + +| Name | 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/client/others/rust/reqwest/discriminated-union/docs/Bird.md b/samples/client/others/rust/reqwest/discriminated-union/docs/Bird.md new file mode 100644 index 000000000000..a9e82a55b80d --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/docs/Bird.md @@ -0,0 +1,13 @@ +# Bird + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**kind** | **String** | | +**name** | Option<**String**> | | [optional] +**wingspan** | Option<**f64**> | | [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/others/rust/reqwest/discriminated-union/docs/Cat.md b/samples/client/others/rust/reqwest/discriminated-union/docs/Cat.md new file mode 100644 index 000000000000..041f84ceb05d --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/docs/Cat.md @@ -0,0 +1,12 @@ +# Cat + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**pet_type** | **PetType** | (enum: Cat, Dog) | +**lives** | Option<**i32**> | | [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/others/rust/reqwest/discriminated-union/docs/Circle.md b/samples/client/others/rust/reqwest/discriminated-union/docs/Circle.md new file mode 100644 index 000000000000..c804262807a9 --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/docs/Circle.md @@ -0,0 +1,12 @@ +# Circle + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**kind** | [**models::ShapeKind**](ShapeKind.md) | | +**radius** | Option<**f64**> | | [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/others/rust/reqwest/discriminated-union/docs/Creature.md b/samples/client/others/rust/reqwest/discriminated-union/docs/Creature.md new file mode 100644 index 000000000000..8d1424d4a52e --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/docs/Creature.md @@ -0,0 +1,10 @@ +# Creature + +## Enum Variants + +| Name | 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/client/others/rust/reqwest/discriminated-union/docs/DefaultApi.md b/samples/client/others/rust/reqwest/discriminated-union/docs/DefaultApi.md new file mode 100644 index 000000000000..915ab0bae813 --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/docs/DefaultApi.md @@ -0,0 +1,34 @@ +# \DefaultApi + +All URIs are relative to *http://localhost* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**get_error**](DefaultApi.md#get_error) | **GET** /errors | + + + +## get_error + +> models::ApiError get_error() + + +### Parameters + +This endpoint does not need any parameter. + +### Return type + +[**models::ApiError**](ApiError.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: 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) + diff --git a/samples/client/others/rust/reqwest/discriminated-union/docs/Dog.md b/samples/client/others/rust/reqwest/discriminated-union/docs/Dog.md new file mode 100644 index 000000000000..d8d044545b8a --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/docs/Dog.md @@ -0,0 +1,12 @@ +# Dog + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**pet_type** | **PetType** | (enum: Cat, Dog) | +**bark** | Option<**bool**> | | [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/others/rust/reqwest/discriminated-union/docs/NullableTagged.md b/samples/client/others/rust/reqwest/discriminated-union/docs/NullableTagged.md new file mode 100644 index 000000000000..f0b59cd1dcc9 --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/docs/NullableTagged.md @@ -0,0 +1,10 @@ +# NullableTagged + +## Enum Variants + +| Name | 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/client/others/rust/reqwest/discriminated-union/docs/ObjectExists.md b/samples/client/others/rust/reqwest/discriminated-union/docs/ObjectExists.md new file mode 100644 index 000000000000..dfd3f3b3d7e2 --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/docs/ObjectExists.md @@ -0,0 +1,14 @@ +# ObjectExists + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**r#type** | **String** | | +**message** | **String** | | +**identifier** | **String** | | +**object_type** | Option<**String**> | | [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/others/rust/reqwest/discriminated-union/docs/Pet.md b/samples/client/others/rust/reqwest/discriminated-union/docs/Pet.md new file mode 100644 index 000000000000..a2ddd4939591 --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/docs/Pet.md @@ -0,0 +1,10 @@ +# Pet + +## Enum Variants + +| Name | 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/client/others/rust/reqwest/discriminated-union/docs/Shape.md b/samples/client/others/rust/reqwest/discriminated-union/docs/Shape.md new file mode 100644 index 000000000000..87fa99a64217 --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/docs/Shape.md @@ -0,0 +1,10 @@ +# Shape + +## Enum Variants + +| Name | 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/client/others/rust/reqwest/discriminated-union/docs/ShapeKind.md b/samples/client/others/rust/reqwest/discriminated-union/docs/ShapeKind.md new file mode 100644 index 000000000000..6dd55c8897fc --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/docs/ShapeKind.md @@ -0,0 +1,12 @@ +# ShapeKind + +## Enum Variants + +| Name | Value | +|---- | -----| +| Circle | circle | + + +[[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/others/rust/reqwest/discriminated-union/docs/ValidationError.md b/samples/client/others/rust/reqwest/discriminated-union/docs/ValidationError.md new file mode 100644 index 000000000000..b866049bba56 --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/docs/ValidationError.md @@ -0,0 +1,13 @@ +# ValidationError + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**r#type** | **String** | | +**message** | **String** | | +**field** | Option<**String**> | | [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/others/rust/reqwest/discriminated-union/git_push.sh b/samples/client/others/rust/reqwest/discriminated-union/git_push.sh new file mode 100644 index 000000000000..a35991cd51a1 --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/git_push.sh @@ -0,0 +1,54 @@ +#!/bin/sh +# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ +# +# Usage example: /bin/sh ./git_push.sh wing328 openapi-petstore-perl "minor update" "gitlab.com" + +git_user_id=$1 +git_repo_id=$2 +release_note=$3 +git_host=$4 + +if [ -z "${git_host}" ]; then + git_host="github.com" + echo "[INFO] No command line input provided. Set \${git_host} to ${git_host}" +fi + +if [ -z "${git_user_id}" ]; then + git_user_id="GIT_USER_ID" + echo "[INFO] No command line input provided. Set \${git_user_id} to ${git_user_id}" +fi + +if [ -z "${git_repo_id}" ]; then + git_repo_id="GIT_REPO_ID" + echo "[INFO] No command line input provided. Set \${git_repo_id} to ${git_repo_id}" +fi + +if [ -z "${release_note}" ]; then + release_note="Minor update" + echo "[INFO] No command line input provided. Set \${release_note} to ${release_note}" +fi + +# Initialize the local directory as a Git repository +git init + +# Adds the files in the local repository and stages them for commit. +git add . + +# Commits the tracked changes and prepares them to be pushed to a remote repository. +git commit -m "${release_note}" + +# Sets the new remote +if [ -z "$(git remote)" ]; then # git remote not defined + if [ -z "${GIT_TOKEN:-}" ]; then + echo "[INFO] \${GIT_TOKEN} (environment variable) is not set. Using the git credential in your environment." + git remote add origin "https://${git_host}/${git_user_id}/${git_repo_id}.git" + else + git remote add origin "https://${git_user_id}:${GIT_TOKEN}@${git_host}/${git_user_id}/${git_repo_id}.git" + fi +fi + +git pull origin master + +# Pushes (Forces) the changes in the local repository up to the remote repository +echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git" +git push origin master 2>&1 | grep -v 'To https' diff --git a/samples/client/others/rust/reqwest/discriminated-union/src/apis/configuration.rs b/samples/client/others/rust/reqwest/discriminated-union/src/apis/configuration.rs new file mode 100644 index 000000000000..9650ca864427 --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/src/apis/configuration.rs @@ -0,0 +1,77 @@ +/* + * discriminated union + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + + +pub use reqwest::blocking::Client; + +#[derive(Clone)] +pub struct Configuration { + pub base_path: String, + pub user_agent: Option, + pub client: reqwest::blocking::Client, + pub basic_auth: Option, + pub oauth_access_token: Option, + pub bearer_access_token: Option, + pub api_key: Option, +} + +pub type BasicAuth = (String, Option); + +#[derive(Clone)] +pub struct ApiKey { + pub prefix: Option, + pub key: String, +} + +impl std::fmt::Debug for ApiKey { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("ApiKey") + .field("prefix", &self.prefix) + .field("key", &"[REDACTED]") + .finish() + } +} + + +impl std::fmt::Debug for Configuration { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let mut debug = f.debug_struct("Configuration"); + debug + .field("base_path", &self.base_path) + .field("user_agent", &self.user_agent) + .field("client", &self.client); + debug + .field("basic_auth", &self.basic_auth.as_ref().map(|(username, password)| (username, password.as_ref().map(|_| "[REDACTED]")))) + .field("oauth_access_token", &self.oauth_access_token.as_ref().map(|_| "[REDACTED]")) + .field("bearer_access_token", &self.bearer_access_token.as_ref().map(|_| "[REDACTED]")) + .field("api_key", &self.api_key); + debug.finish() + } +} + +impl Configuration { + pub fn new() -> Configuration { + Configuration::default() + } +} + +impl Default for Configuration { + fn default() -> Self { + Configuration { + base_path: "http://localhost".to_owned(), + user_agent: Some("OpenAPI-Generator/1.0.0/rust".to_owned()), + client: reqwest::blocking::Client::new(), + basic_auth: None, + oauth_access_token: None, + bearer_access_token: None, + api_key: None, + } + } +} diff --git a/samples/client/others/rust/reqwest/discriminated-union/src/apis/default_api.rs b/samples/client/others/rust/reqwest/discriminated-union/src/apis/default_api.rs new file mode 100644 index 000000000000..c13e3c9e9af1 --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/src/apis/default_api.rs @@ -0,0 +1,59 @@ +/* + * discriminated union + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + + +use reqwest; +use serde::{Deserialize, Serialize, de::Error as _}; +use crate::{apis::ResponseContent, models}; +use super::{Error, configuration, ContentType}; + + +/// struct for typed errors of method [`get_error`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum GetErrorError { + UnknownValue(serde_json::Value), +} + + +pub fn get_error(configuration: &configuration::Configuration, ) -> Result> { + + let uri_str = format!("{}/errors", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); + + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); + } + + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; + + let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); + + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ApiError`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ApiError`")))), + } + } else { + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) + } +} + diff --git a/samples/client/others/rust/reqwest/discriminated-union/src/apis/mod.rs b/samples/client/others/rust/reqwest/discriminated-union/src/apis/mod.rs new file mode 100644 index 000000000000..fdcc89b36066 --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/src/apis/mod.rs @@ -0,0 +1,116 @@ +use std::error; +use std::fmt; + +#[derive(Debug, Clone)] +pub struct ResponseContent { + pub status: reqwest::StatusCode, + pub content: String, + pub entity: Option, +} + +#[derive(Debug)] +pub enum Error { + Reqwest(reqwest::Error), + Serde(serde_json::Error), + Io(std::io::Error), + ResponseError(ResponseContent), +} + +impl fmt::Display for Error { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let (module, e) = match self { + Error::Reqwest(e) => ("reqwest", e.to_string()), + Error::Serde(e) => ("serde", e.to_string()), + Error::Io(e) => ("IO", e.to_string()), + Error::ResponseError(e) => ("response", format!("status code {}", e.status)), + }; + write!(f, "error in {}: {}", module, e) + } +} + +impl error::Error for Error { + fn source(&self) -> Option<&(dyn error::Error + 'static)> { + Some(match self { + Error::Reqwest(e) => e, + Error::Serde(e) => e, + Error::Io(e) => e, + Error::ResponseError(_) => return None, + }) + } +} + +impl From for Error { + fn from(e: reqwest::Error) -> Self { + Error::Reqwest(e) + } +} + +impl From for Error { + fn from(e: serde_json::Error) -> Self { + Error::Serde(e) + } +} + +impl From for Error { + fn from(e: std::io::Error) -> Self { + Error::Io(e) + } +} + +pub fn urlencode>(s: T) -> String { + ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect() +} + +pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> { + if let serde_json::Value::Object(object) = value { + let mut params = vec![]; + + for (key, value) in object { + match value { + serde_json::Value::Object(_) => params.append(&mut parse_deep_object( + &format!("{}[{}]", prefix, key), + value, + )), + serde_json::Value::Array(array) => { + for (i, value) in array.iter().enumerate() { + params.append(&mut parse_deep_object( + &format!("{}[{}][{}]", prefix, key, i), + value, + )); + } + }, + serde_json::Value::String(s) => params.push((format!("{}[{}]", prefix, key), s.clone())), + _ => params.push((format!("{}[{}]", prefix, key), value.to_string())), + } + } + + return params; + } + + unimplemented!("Only objects are supported with style=deepObject") +} + +/// Internal use only +/// A content type supported by this client. +#[allow(dead_code)] +enum ContentType { + Json, + Text, + Unsupported(String) +} + +impl From<&str> for ContentType { + fn from(content_type: &str) -> Self { + if content_type.starts_with("application") && content_type.contains("json") { + return Self::Json; + } else if content_type.starts_with("text/plain") { + return Self::Text; + } else { + return Self::Unsupported(content_type.to_string()); + } + } +} + +pub mod default_api; + +pub mod configuration; diff --git a/samples/client/others/rust/reqwest/discriminated-union/src/lib.rs b/samples/client/others/rust/reqwest/discriminated-union/src/lib.rs new file mode 100644 index 000000000000..e1520628d762 --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/src/lib.rs @@ -0,0 +1,11 @@ +#![allow(unused_imports)] +#![allow(clippy::too_many_arguments)] + +extern crate serde_repr; +extern crate serde; +extern crate serde_json; +extern crate url; +extern crate reqwest; + +pub mod apis; +pub mod models; diff --git a/samples/client/others/rust/reqwest/discriminated-union/src/models/alpha.rs b/samples/client/others/rust/reqwest/discriminated-union/src/models/alpha.rs new file mode 100644 index 000000000000..f89537383c68 --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/src/models/alpha.rs @@ -0,0 +1,33 @@ +/* + * discriminated union + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +use crate::models; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] +pub struct Alpha { + #[serde(rename = "kind", default, skip_serializing_if = "Option::is_none")] + pub kind: Option, + #[serde(rename = "label", skip_serializing_if = "Option::is_none")] + pub label: Option, + #[serde(rename = "alphaOnly", skip_serializing_if = "Option::is_none")] + pub alpha_only: Option, +} + +impl Alpha { + pub fn new(kind: Option) -> Alpha { + Alpha { + kind, + label: None, + alpha_only: None, + } + } +} + diff --git a/samples/client/others/rust/reqwest/discriminated-union/src/models/api_error.rs b/samples/client/others/rust/reqwest/discriminated-union/src/models/api_error.rs new file mode 100644 index 000000000000..85b1068bfa8e --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/src/models/api_error.rs @@ -0,0 +1,30 @@ +/* + * discriminated union + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +use crate::models; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[serde(tag = "type")] +pub enum ApiError { + #[serde(rename="ObjectExists")] + ObjectExists(Box), + #[serde(rename="ValidationError")] + ValidationError(Box), +} + +impl Default for ApiError { + fn default() -> Self { + Self::ObjectExists(Default::default()) + + } +} + + diff --git a/samples/client/others/rust/reqwest/discriminated-union/src/models/bird.rs b/samples/client/others/rust/reqwest/discriminated-union/src/models/bird.rs new file mode 100644 index 000000000000..81f7992bc283 --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/src/models/bird.rs @@ -0,0 +1,33 @@ +/* + * discriminated union + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +use crate::models; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] +pub struct Bird { + #[serde(rename = "kind")] + pub kind: String, + #[serde(rename = "name", skip_serializing_if = "Option::is_none")] + pub name: Option, + #[serde(rename = "wingspan", skip_serializing_if = "Option::is_none")] + pub wingspan: Option, +} + +impl Bird { + pub fn new(kind: String) -> Bird { + Bird { + kind, + name: None, + wingspan: None, + } + } +} + diff --git a/samples/client/others/rust/reqwest/discriminated-union/src/models/cat.rs b/samples/client/others/rust/reqwest/discriminated-union/src/models/cat.rs new file mode 100644 index 000000000000..c7bd8911fa0a --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/src/models/cat.rs @@ -0,0 +1,44 @@ +/* + * discriminated union + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +use crate::models; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] +pub struct Cat { + #[serde(rename = "petType")] + pub pet_type: PetType, + #[serde(rename = "lives", skip_serializing_if = "Option::is_none")] + pub lives: Option, +} + +impl Cat { + pub fn new(pet_type: PetType) -> Cat { + Cat { + pet_type, + lives: None, + } + } +} +/// +#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)] +pub enum PetType { + #[serde(rename = "Cat")] + Cat, + #[serde(rename = "Dog")] + Dog, +} + +impl Default for PetType { + fn default() -> PetType { + Self::Cat + } +} + diff --git a/samples/client/others/rust/reqwest/discriminated-union/src/models/circle.rs b/samples/client/others/rust/reqwest/discriminated-union/src/models/circle.rs new file mode 100644 index 000000000000..c07c7bb99832 --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/src/models/circle.rs @@ -0,0 +1,30 @@ +/* + * discriminated union + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +use crate::models; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] +pub struct Circle { + #[serde(rename = "kind")] + pub kind: models::ShapeKind, + #[serde(rename = "radius", skip_serializing_if = "Option::is_none")] + pub radius: Option, +} + +impl Circle { + pub fn new(kind: models::ShapeKind) -> Circle { + Circle { + kind, + radius: None, + } + } +} + diff --git a/samples/client/others/rust/reqwest/discriminated-union/src/models/creature.rs b/samples/client/others/rust/reqwest/discriminated-union/src/models/creature.rs new file mode 100644 index 000000000000..173e30cc3c8e --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/src/models/creature.rs @@ -0,0 +1,38 @@ +/* + * discriminated union + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +use crate::models; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[serde(tag = "kind")] +pub enum Creature { + #[serde(rename="Bird")] + Bird { + #[serde(rename = "name", skip_serializing_if = "Option::is_none")] + name: Option, + }, + #[serde(rename="Creature")] + Creature { + #[serde(rename = "name", skip_serializing_if = "Option::is_none")] + name: Option, + }, +} + +impl Default for Creature { + fn default() -> Self { + Self::Bird { + name: Default::default(), + } + + } +} + + diff --git a/samples/client/others/rust/reqwest/discriminated-union/src/models/dog.rs b/samples/client/others/rust/reqwest/discriminated-union/src/models/dog.rs new file mode 100644 index 000000000000..bce7efba2980 --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/src/models/dog.rs @@ -0,0 +1,44 @@ +/* + * discriminated union + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +use crate::models; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] +pub struct Dog { + #[serde(rename = "petType")] + pub pet_type: PetType, + #[serde(rename = "bark", skip_serializing_if = "Option::is_none")] + pub bark: Option, +} + +impl Dog { + pub fn new(pet_type: PetType) -> Dog { + Dog { + pet_type, + bark: None, + } + } +} +/// +#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)] +pub enum PetType { + #[serde(rename = "Cat")] + Cat, + #[serde(rename = "Dog")] + Dog, +} + +impl Default for PetType { + fn default() -> PetType { + Self::Cat + } +} + diff --git a/samples/client/others/rust/reqwest/discriminated-union/src/models/mod.rs b/samples/client/others/rust/reqwest/discriminated-union/src/models/mod.rs new file mode 100644 index 000000000000..f2a9f81b0dbd --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/src/models/mod.rs @@ -0,0 +1,26 @@ +pub mod alpha; +pub use self::alpha::Alpha; +pub mod api_error; +pub use self::api_error::ApiError; +pub mod bird; +pub use self::bird::Bird; +pub mod cat; +pub use self::cat::Cat; +pub mod circle; +pub use self::circle::Circle; +pub mod creature; +pub use self::creature::Creature; +pub mod dog; +pub use self::dog::Dog; +pub mod nullable_tagged; +pub use self::nullable_tagged::NullableTagged; +pub mod object_exists; +pub use self::object_exists::ObjectExists; +pub mod pet; +pub use self::pet::Pet; +pub mod shape; +pub use self::shape::Shape; +pub mod shape_kind; +pub use self::shape_kind::ShapeKind; +pub mod validation_error; +pub use self::validation_error::ValidationError; diff --git a/samples/client/others/rust/reqwest/discriminated-union/src/models/nullable_tagged.rs b/samples/client/others/rust/reqwest/discriminated-union/src/models/nullable_tagged.rs new file mode 100644 index 000000000000..6a3033b746f2 --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/src/models/nullable_tagged.rs @@ -0,0 +1,28 @@ +/* + * discriminated union + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +use crate::models; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[serde(tag = "kind")] +pub enum NullableTagged { + #[serde(rename="Alpha")] + Alpha(Box), +} + +impl Default for NullableTagged { + fn default() -> Self { + Self::Alpha(Default::default()) + + } +} + + diff --git a/samples/client/others/rust/reqwest/discriminated-union/src/models/object_exists.rs b/samples/client/others/rust/reqwest/discriminated-union/src/models/object_exists.rs new file mode 100644 index 000000000000..9c888681f005 --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/src/models/object_exists.rs @@ -0,0 +1,36 @@ +/* + * discriminated union + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +use crate::models; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] +pub struct ObjectExists { + #[serde(rename = "type", default, skip_serializing_if = "String::is_empty")] + pub r#type: String, + #[serde(rename = "message")] + pub message: String, + #[serde(rename = "identifier")] + pub identifier: String, + #[serde(rename = "objectType", skip_serializing_if = "Option::is_none")] + pub object_type: Option, +} + +impl ObjectExists { + pub fn new(r#type: String, message: String, identifier: String) -> ObjectExists { + ObjectExists { + r#type, + message, + identifier, + object_type: None, + } + } +} + diff --git a/samples/client/others/rust/reqwest/discriminated-union/src/models/pet.rs b/samples/client/others/rust/reqwest/discriminated-union/src/models/pet.rs new file mode 100644 index 000000000000..b2f201ce75c6 --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/src/models/pet.rs @@ -0,0 +1,33 @@ +/* + * discriminated union + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +use crate::models; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[serde(tag = "petType")] +pub enum Pet { + #[serde(rename="Cat")] + Cat { + }, + #[serde(rename="Dog")] + Dog { + }, +} + +impl Default for Pet { + fn default() -> Self { + Self::Cat { + } + + } +} + + diff --git a/samples/client/others/rust/reqwest/discriminated-union/src/models/shape.rs b/samples/client/others/rust/reqwest/discriminated-union/src/models/shape.rs new file mode 100644 index 000000000000..df0bb13f7c2d --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/src/models/shape.rs @@ -0,0 +1,30 @@ +/* + * discriminated union + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +use crate::models; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[serde(tag = "kind")] +pub enum Shape { + #[serde(rename="circle")] + Circle { + }, +} + +impl Default for Shape { + fn default() -> Self { + Self::Circle { + } + + } +} + + diff --git a/samples/client/others/rust/reqwest/discriminated-union/src/models/shape_kind.rs b/samples/client/others/rust/reqwest/discriminated-union/src/models/shape_kind.rs new file mode 100644 index 000000000000..3956333c5b71 --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/src/models/shape_kind.rs @@ -0,0 +1,35 @@ +/* + * discriminated union + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +use crate::models; +use serde::{Deserialize, Serialize}; + +/// +#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)] +pub enum ShapeKind { + #[serde(rename = "circle")] + Circle, + +} + +impl std::fmt::Display for ShapeKind { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + match self { + Self::Circle => write!(f, "circle"), + } + } +} + +impl Default for ShapeKind { + fn default() -> ShapeKind { + Self::Circle + } +} + diff --git a/samples/client/others/rust/reqwest/discriminated-union/src/models/validation_error.rs b/samples/client/others/rust/reqwest/discriminated-union/src/models/validation_error.rs new file mode 100644 index 000000000000..26312897d7c9 --- /dev/null +++ b/samples/client/others/rust/reqwest/discriminated-union/src/models/validation_error.rs @@ -0,0 +1,33 @@ +/* + * discriminated union + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +use crate::models; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] +pub struct ValidationError { + #[serde(rename = "type", default, skip_serializing_if = "String::is_empty")] + pub r#type: String, + #[serde(rename = "message")] + pub message: String, + #[serde(rename = "field", skip_serializing_if = "Option::is_none")] + pub field: Option, +} + +impl ValidationError { + pub fn new(r#type: String, message: String) -> ValidationError { + ValidationError { + r#type, + message, + field: None, + } + } +} + diff --git a/samples/client/others/rust/reqwest/oneOf/src/models/bar.rs b/samples/client/others/rust/reqwest/oneOf/src/models/bar.rs index ed85518807f2..0e5acbf27e4d 100644 --- a/samples/client/others/rust/reqwest/oneOf/src/models/bar.rs +++ b/samples/client/others/rust/reqwest/oneOf/src/models/bar.rs @@ -25,7 +25,7 @@ pub struct Bar { #[serde(rename = "@baseType", skip_serializing_if = "Option::is_none")] pub at_base_type: Option, /// When sub-classing, this defines the sub-class Extensible name - #[serde(rename = "@type")] + #[serde(rename = "@type", default, skip_serializing_if = "String::is_empty")] pub at_type: String, #[serde(rename = "barPropA", skip_serializing_if = "Option::is_none")] pub bar_prop_a: Option, diff --git a/samples/client/others/rust/reqwest/oneOf/src/models/bar_create.rs b/samples/client/others/rust/reqwest/oneOf/src/models/bar_create.rs index 98481c64e2f9..3a0da7cd7500 100644 --- a/samples/client/others/rust/reqwest/oneOf/src/models/bar_create.rs +++ b/samples/client/others/rust/reqwest/oneOf/src/models/bar_create.rs @@ -26,7 +26,7 @@ pub struct BarCreate { #[serde(rename = "@baseType", skip_serializing_if = "Option::is_none")] pub at_base_type: Option, /// When sub-classing, this defines the sub-class Extensible name - #[serde(rename = "@type")] + #[serde(rename = "@type", default, skip_serializing_if = "String::is_empty")] pub at_type: String, #[serde(rename = "barPropA", skip_serializing_if = "Option::is_none")] pub bar_prop_a: Option, diff --git a/samples/client/others/rust/reqwest/oneOf/src/models/bar_ref.rs b/samples/client/others/rust/reqwest/oneOf/src/models/bar_ref.rs index ce4ee09caf9d..07ca991d8627 100644 --- a/samples/client/others/rust/reqwest/oneOf/src/models/bar_ref.rs +++ b/samples/client/others/rust/reqwest/oneOf/src/models/bar_ref.rs @@ -26,7 +26,7 @@ pub struct BarRef { #[serde(rename = "@baseType", skip_serializing_if = "Option::is_none")] pub at_base_type: Option, /// When sub-classing, this defines the sub-class Extensible name - #[serde(rename = "@type")] + #[serde(rename = "@type", default, skip_serializing_if = "String::is_empty")] pub at_type: String, /// Name of the related entity. #[serde(rename = "name", skip_serializing_if = "Option::is_none")] diff --git a/samples/client/others/rust/reqwest/oneOf/src/models/entity.rs b/samples/client/others/rust/reqwest/oneOf/src/models/entity.rs index bfb1aac3382c..6f6c47efe667 100644 --- a/samples/client/others/rust/reqwest/oneOf/src/models/entity.rs +++ b/samples/client/others/rust/reqwest/oneOf/src/models/entity.rs @@ -15,105 +15,22 @@ use serde::{Deserialize, Serialize}; #[serde(tag = "@type")] pub enum Entity { #[serde(rename="Bar")] - Bar { - /// Hyperlink reference - #[serde(rename = "href", skip_serializing_if = "Option::is_none")] - href: Option, - /// unique identifier - #[serde(rename = "id", skip_serializing_if = "Option::is_none")] - id: Option, - /// A URI to a JSON-Schema file that defines additional attributes and relationships - #[serde(rename = "@schemaLocation", skip_serializing_if = "Option::is_none")] - at_schema_location: Option, - /// When sub-classing, this defines the super-class - #[serde(rename = "@baseType", skip_serializing_if = "Option::is_none")] - at_base_type: Option, - }, + Bar(Box), #[serde(rename="Bar_Create")] - BarCreate { - /// Hyperlink reference - #[serde(rename = "href", skip_serializing_if = "Option::is_none")] - href: Option, - /// unique identifier - #[serde(rename = "id", skip_serializing_if = "Option::is_none")] - id: Option, - /// A URI to a JSON-Schema file that defines additional attributes and relationships - #[serde(rename = "@schemaLocation", skip_serializing_if = "Option::is_none")] - at_schema_location: Option, - /// When sub-classing, this defines the super-class - #[serde(rename = "@baseType", skip_serializing_if = "Option::is_none")] - at_base_type: Option, - }, + BarCreate(Box), #[serde(rename="Foo")] - Foo { - /// Hyperlink reference - #[serde(rename = "href", skip_serializing_if = "Option::is_none")] - href: Option, - /// unique identifier - #[serde(rename = "id", skip_serializing_if = "Option::is_none")] - id: Option, - /// A URI to a JSON-Schema file that defines additional attributes and relationships - #[serde(rename = "@schemaLocation", skip_serializing_if = "Option::is_none")] - at_schema_location: Option, - /// When sub-classing, this defines the super-class - #[serde(rename = "@baseType", skip_serializing_if = "Option::is_none")] - at_base_type: Option, - }, + Foo(Box), #[serde(rename="Pasta")] - Pasta { - /// Hyperlink reference - #[serde(rename = "href", skip_serializing_if = "Option::is_none")] - href: Option, - /// unique identifier - #[serde(rename = "id", skip_serializing_if = "Option::is_none")] - id: Option, - /// A URI to a JSON-Schema file that defines additional attributes and relationships - #[serde(rename = "@schemaLocation", skip_serializing_if = "Option::is_none")] - at_schema_location: Option, - /// When sub-classing, this defines the super-class - #[serde(rename = "@baseType", skip_serializing_if = "Option::is_none")] - at_base_type: Option, - }, + Pasta(Box), #[serde(rename="Pizza")] - Pizza { - /// Hyperlink reference - #[serde(rename = "href", skip_serializing_if = "Option::is_none")] - href: Option, - /// unique identifier - #[serde(rename = "id", skip_serializing_if = "Option::is_none")] - id: Option, - /// A URI to a JSON-Schema file that defines additional attributes and relationships - #[serde(rename = "@schemaLocation", skip_serializing_if = "Option::is_none")] - at_schema_location: Option, - /// When sub-classing, this defines the super-class - #[serde(rename = "@baseType", skip_serializing_if = "Option::is_none")] - at_base_type: Option, - }, + Pizza(Box), #[serde(rename="PizzaSpeziale")] - PizzaSpeziale { - /// Hyperlink reference - #[serde(rename = "href", skip_serializing_if = "Option::is_none")] - href: Option, - /// unique identifier - #[serde(rename = "id", skip_serializing_if = "Option::is_none")] - id: Option, - /// A URI to a JSON-Schema file that defines additional attributes and relationships - #[serde(rename = "@schemaLocation", skip_serializing_if = "Option::is_none")] - at_schema_location: Option, - /// When sub-classing, this defines the super-class - #[serde(rename = "@baseType", skip_serializing_if = "Option::is_none")] - at_base_type: Option, - }, + PizzaSpeziale(Box), } impl Default for Entity { fn default() -> Self { - Self::Bar { - href: Default::default(), - id: Default::default(), - at_schema_location: Default::default(), - at_base_type: Default::default(), - } + Self::Bar(Default::default()) } } diff --git a/samples/client/others/rust/reqwest/oneOf/src/models/entity_ref.rs b/samples/client/others/rust/reqwest/oneOf/src/models/entity_ref.rs index d1a9853dc89b..ea762128d931 100644 --- a/samples/client/others/rust/reqwest/oneOf/src/models/entity_ref.rs +++ b/samples/client/others/rust/reqwest/oneOf/src/models/entity_ref.rs @@ -15,59 +15,14 @@ use serde::{Deserialize, Serialize}; #[serde(tag = "@type")] pub enum EntityRef { #[serde(rename="BarRef")] - BarRef { - /// Hyperlink reference - #[serde(rename = "href", skip_serializing_if = "Option::is_none")] - href: Option, - /// unique identifier - #[serde(rename = "id", skip_serializing_if = "Option::is_none")] - id: Option, - /// A URI to a JSON-Schema file that defines additional attributes and relationships - #[serde(rename = "@schemaLocation", skip_serializing_if = "Option::is_none")] - at_schema_location: Option, - /// When sub-classing, this defines the super-class - #[serde(rename = "@baseType", skip_serializing_if = "Option::is_none")] - at_base_type: Option, - /// Name of the related entity. - #[serde(rename = "name", skip_serializing_if = "Option::is_none")] - name: Option, - /// The actual type of the target instance when needed for disambiguation. - #[serde(rename = "@referredType", skip_serializing_if = "Option::is_none")] - at_referred_type: Option, - }, + BarRef(Box), #[serde(rename="FooRef")] - FooRef { - /// Hyperlink reference - #[serde(rename = "href", skip_serializing_if = "Option::is_none")] - href: Option, - /// unique identifier - #[serde(rename = "id", skip_serializing_if = "Option::is_none")] - id: Option, - /// A URI to a JSON-Schema file that defines additional attributes and relationships - #[serde(rename = "@schemaLocation", skip_serializing_if = "Option::is_none")] - at_schema_location: Option, - /// When sub-classing, this defines the super-class - #[serde(rename = "@baseType", skip_serializing_if = "Option::is_none")] - at_base_type: Option, - /// Name of the related entity. - #[serde(rename = "name", skip_serializing_if = "Option::is_none")] - name: Option, - /// The actual type of the target instance when needed for disambiguation. - #[serde(rename = "@referredType", skip_serializing_if = "Option::is_none")] - at_referred_type: Option, - }, + FooRef(Box), } impl Default for EntityRef { fn default() -> Self { - Self::BarRef { - href: Default::default(), - id: Default::default(), - at_schema_location: Default::default(), - at_base_type: Default::default(), - name: Default::default(), - at_referred_type: Default::default(), - } + Self::BarRef(Default::default()) } } diff --git a/samples/client/others/rust/reqwest/oneOf/src/models/foo.rs b/samples/client/others/rust/reqwest/oneOf/src/models/foo.rs index becc6957dd5d..6365749a7432 100644 --- a/samples/client/others/rust/reqwest/oneOf/src/models/foo.rs +++ b/samples/client/others/rust/reqwest/oneOf/src/models/foo.rs @@ -26,7 +26,7 @@ pub struct Foo { #[serde(rename = "@baseType", skip_serializing_if = "Option::is_none")] pub at_base_type: Option, /// When sub-classing, this defines the sub-class Extensible name - #[serde(rename = "@type")] + #[serde(rename = "@type", default, skip_serializing_if = "String::is_empty")] pub at_type: String, #[serde(rename = "fooPropA", skip_serializing_if = "Option::is_none")] pub foo_prop_a: Option, diff --git a/samples/client/others/rust/reqwest/oneOf/src/models/foo_ref.rs b/samples/client/others/rust/reqwest/oneOf/src/models/foo_ref.rs index f4b3a2837fb7..09d760d3bae1 100644 --- a/samples/client/others/rust/reqwest/oneOf/src/models/foo_ref.rs +++ b/samples/client/others/rust/reqwest/oneOf/src/models/foo_ref.rs @@ -26,7 +26,7 @@ pub struct FooRef { #[serde(rename = "@baseType", skip_serializing_if = "Option::is_none")] pub at_base_type: Option, /// When sub-classing, this defines the sub-class Extensible name - #[serde(rename = "@type")] + #[serde(rename = "@type", default, skip_serializing_if = "String::is_empty")] pub at_type: String, /// Name of the related entity. #[serde(rename = "name", skip_serializing_if = "Option::is_none")] diff --git a/samples/client/others/rust/reqwest/oneOf/src/models/pasta.rs b/samples/client/others/rust/reqwest/oneOf/src/models/pasta.rs index 5352c0da9d41..a6dec55be07b 100644 --- a/samples/client/others/rust/reqwest/oneOf/src/models/pasta.rs +++ b/samples/client/others/rust/reqwest/oneOf/src/models/pasta.rs @@ -26,7 +26,7 @@ pub struct Pasta { #[serde(rename = "@baseType", skip_serializing_if = "Option::is_none")] pub at_base_type: Option, /// When sub-classing, this defines the sub-class Extensible name - #[serde(rename = "@type")] + #[serde(rename = "@type", default, skip_serializing_if = "String::is_empty")] pub at_type: String, #[serde(rename = "vendor", skip_serializing_if = "Option::is_none")] pub vendor: Option, diff --git a/samples/client/others/rust/reqwest/oneOf/src/models/pizza.rs b/samples/client/others/rust/reqwest/oneOf/src/models/pizza.rs index b99e41a1a354..a0c7390b126f 100644 --- a/samples/client/others/rust/reqwest/oneOf/src/models/pizza.rs +++ b/samples/client/others/rust/reqwest/oneOf/src/models/pizza.rs @@ -26,7 +26,7 @@ pub struct Pizza { #[serde(rename = "@baseType", skip_serializing_if = "Option::is_none")] pub at_base_type: Option, /// When sub-classing, this defines the sub-class Extensible name - #[serde(rename = "@type")] + #[serde(rename = "@type", default, skip_serializing_if = "String::is_empty")] pub at_type: String, #[serde(rename = "pizzaSize", skip_serializing_if = "Option::is_none")] pub pizza_size: Option, diff --git a/samples/client/others/rust/reqwest/oneOf/src/models/pizza_speziale.rs b/samples/client/others/rust/reqwest/oneOf/src/models/pizza_speziale.rs index f3cfea721eff..40133bbf0304 100644 --- a/samples/client/others/rust/reqwest/oneOf/src/models/pizza_speziale.rs +++ b/samples/client/others/rust/reqwest/oneOf/src/models/pizza_speziale.rs @@ -26,7 +26,7 @@ pub struct PizzaSpeziale { #[serde(rename = "@baseType", skip_serializing_if = "Option::is_none")] pub at_base_type: Option, /// When sub-classing, this defines the sub-class Extensible name - #[serde(rename = "@type")] + #[serde(rename = "@type", default, skip_serializing_if = "String::is_empty")] pub at_type: String, #[serde(rename = "pizzaSize", skip_serializing_if = "Option::is_none")] pub pizza_size: Option, diff --git a/samples/client/petstore/rust/hyper/test-duplicates/src/models/_tests_discriminator_duplicate_enums_get_200_response.rs b/samples/client/petstore/rust/hyper/test-duplicates/src/models/_tests_discriminator_duplicate_enums_get_200_response.rs index 91ae6492101b..a7886f3c293f 100644 --- a/samples/client/petstore/rust/hyper/test-duplicates/src/models/_tests_discriminator_duplicate_enums_get_200_response.rs +++ b/samples/client/petstore/rust/hyper/test-duplicates/src/models/_tests_discriminator_duplicate_enums_get_200_response.rs @@ -15,41 +15,16 @@ use serde::{Deserialize, Serialize}; #[serde(tag = "objectType")] pub enum TestsDiscriminatorDuplicateEnumsGet200Response { #[serde(rename="car")] - Vehicle { - #[serde(rename = "type")] - r#type: String, - #[serde(rename = "name")] - name: String, - #[serde(rename = "speed")] - speed: f64, - }, + Vehicle(Box), #[serde(rename="student")] - PersonStudent { - #[serde(rename = "type")] - r#type: String, - #[serde(rename = "name")] - name: String, - #[serde(rename = "speed")] - speed: f64, - }, + PersonStudent(Box), #[serde(rename="teacher")] - PersonTeacher { - #[serde(rename = "type")] - r#type: String, - #[serde(rename = "name")] - name: String, - #[serde(rename = "speed")] - speed: f64, - }, + PersonTeacher(Box), } impl Default for TestsDiscriminatorDuplicateEnumsGet200Response { fn default() -> Self { - Self::Vehicle { - r#type: Default::default(), - name: Default::default(), - speed: Default::default(), - } + Self::Vehicle(Default::default()) } } diff --git a/samples/client/petstore/rust/reqwest/test-duplicates/src/models/_tests_discriminator_duplicate_enums_get_200_response.rs b/samples/client/petstore/rust/reqwest/test-duplicates/src/models/_tests_discriminator_duplicate_enums_get_200_response.rs index 91ae6492101b..a7886f3c293f 100644 --- a/samples/client/petstore/rust/reqwest/test-duplicates/src/models/_tests_discriminator_duplicate_enums_get_200_response.rs +++ b/samples/client/petstore/rust/reqwest/test-duplicates/src/models/_tests_discriminator_duplicate_enums_get_200_response.rs @@ -15,41 +15,16 @@ use serde::{Deserialize, Serialize}; #[serde(tag = "objectType")] pub enum TestsDiscriminatorDuplicateEnumsGet200Response { #[serde(rename="car")] - Vehicle { - #[serde(rename = "type")] - r#type: String, - #[serde(rename = "name")] - name: String, - #[serde(rename = "speed")] - speed: f64, - }, + Vehicle(Box), #[serde(rename="student")] - PersonStudent { - #[serde(rename = "type")] - r#type: String, - #[serde(rename = "name")] - name: String, - #[serde(rename = "speed")] - speed: f64, - }, + PersonStudent(Box), #[serde(rename="teacher")] - PersonTeacher { - #[serde(rename = "type")] - r#type: String, - #[serde(rename = "name")] - name: String, - #[serde(rename = "speed")] - speed: f64, - }, + PersonTeacher(Box), } impl Default for TestsDiscriminatorDuplicateEnumsGet200Response { fn default() -> Self { - Self::Vehicle { - r#type: Default::default(), - name: Default::default(), - speed: Default::default(), - } + Self::Vehicle(Default::default()) } }