From 30e1ba7c873088ed5e02a197741ae346f732c09e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Foorack=20/=20Max=20Fax=C3=A4lv?= Date: Thu, 11 Nov 2021 07:26:21 +0100 Subject: [PATCH] fix(rust, client): fix breaking regression introduced by #10432 (#10720) * Fix breaking regression introduced by #10432 This change forgot enum structures, which causes the compiler to throw errors for "the trait `Default` is not implemented for MyEnum". This change implements the Default trait to the enum template. * fix: add Default for type enums --- .../src/main/resources/rust/model.mustache | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/rust/model.mustache b/modules/openapi-generator/src/main/resources/rust/model.mustache index c4ed5beb64d..1bd2b8db9e0 100644 --- a/modules/openapi-generator/src/main/resources/rust/model.mustache +++ b/modules/openapi-generator/src/main/resources/rust/model.mustache @@ -28,6 +28,14 @@ impl ToString for {{{classname}}} { } } } + +impl Default for {{{classname}}} { + fn default() -> {{{classname}}} { + {{#allowableValues}} + Self::{{ enumVars.0.name }} + {{/allowableValues}} + } +} {{/isEnum}} {{!-- for schemas that have a discriminator --}} @@ -95,6 +103,14 @@ pub enum {{{enumName}}} { {{/enumVars}} {{/allowableValues}} } + +impl Default for {{{enumName}}} { + fn default() -> {{{enumName}}} { + {{#allowableValues}} + Self::{{ enumVars.0.name }} + {{/allowableValues}} + } +} {{/isEnum}} {{/vars}}