diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustAxumServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustAxumServerCodegen.java index 3605dbc5fb5..0e4ce7b1182 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustAxumServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustAxumServerCodegen.java @@ -11,7 +11,6 @@ import io.swagger.v3.oas.models.parameters.Parameter; import io.swagger.v3.oas.models.parameters.RequestBody; import io.swagger.v3.oas.models.responses.ApiResponse; import io.swagger.v3.oas.models.servers.Server; -import joptsimple.internal.Strings; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.StringUtils; import org.openapitools.codegen.*; @@ -26,14 +25,13 @@ import org.openapitools.codegen.model.ModelsMap; import org.openapitools.codegen.model.OperationMap; import org.openapitools.codegen.model.OperationsMap; import org.openapitools.codegen.utils.ModelUtils; -import org.openapitools.codegen.utils.URLPathUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; import java.math.BigInteger; -import java.net.URL; +import java.nio.file.Path; import java.util.*; import java.util.stream.Collectors; @@ -42,17 +40,31 @@ import static org.openapitools.codegen.utils.StringUtils.underscore; public class RustAxumServerCodegen extends AbstractRustCodegen implements CodegenConfig { public static final String PROJECT_NAME = "openapi-server"; + private static final String apiPath = "rust-axum"; + + private String packageName; + private String packageVersion; + private Boolean disableValidator = false; + private Boolean allowBlockingValidator = false; + private Boolean allowBlockingResponseSerialize = false; + private String externCrateName; + // Types private static final String uuidType = "uuid::Uuid"; private static final String bytesType = "ByteArray"; + private static final String dateType = "chrono::naive::NaiveDate"; + private static final String dateTimeType = "chrono::DateTime::"; + private static final String stringType = "String"; + private static final String objectType = "crate::types::Object"; + private static final String mapType = "std::collections::HashMap"; + private static final String vecType = "Vec"; + + // Mime private static final String octetMimeType = "application/octet-stream"; private static final String plainTextMimeType = "text/plain"; - private static final String xmlMimeType = "application/xml"; private static final String textXmlMimeType = "text/xml"; - private static final String formUrlEncodedMimeType = "application/x-www-form-urlencoded"; - private static final String jsonMimeType = "application/json"; // RFC 7386 support private static final String mergePatchJsonMimeType = "application/merge-patch+json"; @@ -60,19 +72,11 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege private static final String problemJsonMimeType = "application/problem+json"; private static final String problemXmlMimeType = "application/problem+xml"; - private final Logger LOGGER = LoggerFactory.getLogger(RustAxumServerCodegen.class); // Grouping (Method, Operation) by Path. private final Map> pathMethodOpMap = new HashMap<>(); - protected String apiVersion = "1.0.0"; - protected String apiPath = "rust-axum"; - protected String packageName; - protected String packageVersion; - protected Boolean disableValidator = false; - protected Boolean allowBlockingValidator = false; - protected Boolean allowBlockingResponseSerialize = false; - protected String externCrateName; - protected int serverPort = 8080; + // Logger + private final Logger LOGGER = LoggerFactory.getLogger(RustAxumServerCodegen.class); public RustAxumServerCodegen() { super(); @@ -109,7 +113,7 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege hideGenerationTimestamp = Boolean.FALSE; // set the output folder here - outputFolder = "generated-code" + File.separator + "rust-axum"; + outputFolder = Path.of("generated-code", "rust-axum").toString(); embeddedTemplateDir = templateDir = "rust-axum"; importMapping = new HashMap<>(); @@ -118,13 +122,11 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege // types defaultIncludes = new HashSet<>( - Arrays.asList( - "map", - "array") + Set.of("map", "array") ); languageSpecificPrimitives = new HashSet<>( - Arrays.asList( + Set.of( "bool", "char", "i8", @@ -140,49 +142,48 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege "f32", "f64", "str", - "String") + stringType) ); + assert languageSpecificPrimitives.size() == 16; - instantiationTypes.clear(); - instantiationTypes.put("array", "Vec"); - instantiationTypes.put("map", "std::collections::HashMap"); + instantiationTypes = new HashMap<>( + Map.of( + "array", vecType, + "map", mapType + ) + ); + assert instantiationTypes.size() == 2; - typeMapping.clear(); - typeMapping.put("number", "f64"); - typeMapping.put("integer", "i32"); - typeMapping.put("long", "i64"); - typeMapping.put("float", "f32"); - typeMapping.put("double", "f64"); - typeMapping.put("string", "String"); - typeMapping.put("UUID", uuidType); - typeMapping.put("URI", "String"); - typeMapping.put("byte", "u8"); - typeMapping.put("ByteArray", bytesType); - typeMapping.put("binary", bytesType); - typeMapping.put("boolean", "bool"); - typeMapping.put("date", "chrono::naive::NaiveDate"); - typeMapping.put("DateTime", "chrono::DateTime::"); - typeMapping.put("password", "String"); - typeMapping.put("File", "ByteArray"); - typeMapping.put("file", "ByteArray"); - typeMapping.put("array", "Vec"); - typeMapping.put("map", "std::collections::HashMap"); - typeMapping.put("object", "crate::types::Object"); - typeMapping.put("AnyType", "crate::types::Object"); + typeMapping = new HashMap<>(Map.ofEntries( + new AbstractMap.SimpleEntry<>("number", "f64"), + new AbstractMap.SimpleEntry<>("integer", "i32"), + new AbstractMap.SimpleEntry<>("long", "i64"), + new AbstractMap.SimpleEntry<>("float", "f32"), + new AbstractMap.SimpleEntry<>("double", "f64"), + new AbstractMap.SimpleEntry<>("string", stringType), + new AbstractMap.SimpleEntry<>("UUID", uuidType), + new AbstractMap.SimpleEntry<>("URI", stringType), + new AbstractMap.SimpleEntry<>("byte", "u8"), + new AbstractMap.SimpleEntry<>("ByteArray", bytesType), + new AbstractMap.SimpleEntry<>("binary", bytesType), + new AbstractMap.SimpleEntry<>("boolean", "bool"), + new AbstractMap.SimpleEntry<>("date", dateType), + new AbstractMap.SimpleEntry<>("DateTime", dateTimeType), + new AbstractMap.SimpleEntry<>("password", stringType), + new AbstractMap.SimpleEntry<>("File", bytesType), + new AbstractMap.SimpleEntry<>("file", bytesType), + new AbstractMap.SimpleEntry<>("array", vecType), + new AbstractMap.SimpleEntry<>("map", mapType), + new AbstractMap.SimpleEntry<>("object", objectType), + new AbstractMap.SimpleEntry<>("AnyType", objectType) + )); + assert typeMapping.size() == 21; // cli options - cliOptions.clear(); - cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, - "Rust crate name (convention: snake_case).") - .defaultValue("openapi")); - cliOptions.add(new CliOption(CodegenConstants.PACKAGE_VERSION, - "Rust crate version.")); - CliOption optDisableValidator = new CliOption("disableValidator", "Disable validating request-data (header, path, query, body) " + "against OpenAPI Schema Specification."); optDisableValidator.setType("bool"); optDisableValidator.defaultValue(disableValidator.toString()); - cliOptions.add(optDisableValidator); CliOption optAllowBlockingValidator = new CliOption("allowBlockingValidator", String.join("", @@ -193,7 +194,6 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege "is low cost.")); optAllowBlockingValidator.setType("bool"); optAllowBlockingValidator.defaultValue(allowBlockingValidator.toString()); - cliOptions.add(optAllowBlockingValidator); CliOption optAllowBlockingResponseSerialize = new CliOption("allowBlockingResponseSerialize", String.join("", "By default, json/form-urlencoded response serialization, which might ", @@ -203,10 +203,19 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege "serialization (e.g. returns tiny data) is low cost.")); optAllowBlockingResponseSerialize.setType("bool"); optAllowBlockingResponseSerialize.defaultValue(allowBlockingResponseSerialize.toString()); - cliOptions.add(optAllowBlockingResponseSerialize); - additionalProperties.put("apiVersion", apiVersion); - additionalProperties.put("apiPath", apiPath); + cliOptions = new ArrayList<>( + List.of( + new CliOption(CodegenConstants.PACKAGE_NAME, + "Rust crate name (convention: snake_case).") + .defaultValue("openapi"), + new CliOption(CodegenConstants.PACKAGE_VERSION, + "Rust crate version."), + optDisableValidator, + optAllowBlockingValidator, + optAllowBlockingResponseSerialize + ) + ); supportingFiles.add(new SupportingFile("Cargo.mustache", "", "Cargo.toml")); supportingFiles.add(new SupportingFile("gitignore", "", ".gitignore")); @@ -276,7 +285,7 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege } if (additionalProperties.containsKey("allowBlockingResponseSerialize")) { - allowBlockingValidator = convertPropertyToBooleanAndWriteBack("allowBlockingResponseSerialize"); + allowBlockingResponseSerialize = convertPropertyToBooleanAndWriteBack("allowBlockingResponseSerialize"); } else { additionalProperties.put("allowBlockingResponseSerialize", allowBlockingResponseSerialize); } @@ -302,10 +311,6 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege public void preprocessOpenAPI(OpenAPI openAPI) { Info info = openAPI.getInfo(); - URL url = URLPathUtils.getServerURL(openAPI, serverVariableOverrides()); - additionalProperties.put("serverHost", url.getHost()); - additionalProperties.put("serverPort", URLPathUtils.getPort(url, serverPort)); - if (packageVersion == null || packageVersion.isEmpty()) { List versionComponents = new ArrayList<>(Arrays.asList(info.getVersion().split("[.]"))); if (versionComponents.isEmpty()) { @@ -323,10 +328,9 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege @Override public String toApiName(String name) { - if (name.isEmpty()) { - return "default"; - } - return sanitizeIdentifier(name, CasingType.SNAKE_CASE, "api", "API", true); + return name.isEmpty() ? + "default" : + sanitizeIdentifier(name, CasingType.SNAKE_CASE, "api", "API", true); } /** @@ -335,7 +339,7 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege */ @Override public String apiFileFolder() { - return outputFolder + File.separator + apiPackage().replace('.', File.separatorChar); + return Path.of(outputFolder, apiPackage().replace('.', File.separatorChar)).toString(); } @Override @@ -348,6 +352,10 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege return "\"" + super.toEnumValue(value, datatype) + "\""; } + private boolean isObjectType(String type) { + return "object".equals(type); + } + private boolean isMimetypeXml(String mimetype) { return mimetype.toLowerCase(Locale.ROOT).startsWith(xmlMimeType) || mimetype.toLowerCase(Locale.ROOT).startsWith(problemXmlMimeType) || @@ -483,11 +491,6 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege outputMime = jsonMimeType; } } else { - // If we know exactly what mimetype this response is - // going to produce, then use that. If we have not found - // anything, then we'll fall back to the 'producesXXX' - // definitions we worked out above for the operation as a - // whole. if (isMimetypeWwwFormUrlEncoded(firstProduces)) { producesFormUrlEncoded = true; producesPlainText = false; @@ -509,8 +512,6 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege rsp.vendorExtensions.put("x-mime-type", outputMime); - // Write out the type of data we actually expect this response - // to make. if (producesFormUrlEncoded) { rsp.vendorExtensions.put("x-produces-form-urlencoded", true); } else if (producesPlainText) { @@ -529,11 +530,8 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege } } else { rsp.vendorExtensions.put("x-produces-json", true); - // If the data type is just "object", then ensure that the - // Rust data type is "crate::types::Object". This allows us - // to define APIs that can return arbitrary JSON bodies. - if ("object".equals(rsp.dataType)) { - rsp.dataType = "crate::types::Object"; + if (isObjectType(rsp.dataType)) { + rsp.dataType = objectType; } } } @@ -557,15 +555,15 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege } @Override - public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List allModels) { - OperationMap operations = objs.getOperations(); + public OperationsMap postProcessOperationsWithModels(OperationsMap operationsMap, List allModels) { + OperationMap operations = operationsMap.getOperations(); List operationList = operations.getOperation(); for (CodegenOperation op : operationList) { postProcessOperationWithModels(op); } - return objs; + return operationsMap; } private void postProcessOperationWithModels(CodegenOperation op) { @@ -793,7 +791,8 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege String defaultValue = null; if ((ModelUtils.isNullable(p)) && (p.getDefault() != null) && ("null".equalsIgnoreCase(p.getDefault().toString()))) return "Nullable::Null"; - else if (ModelUtils.isBooleanSchema(p)) { + + if (ModelUtils.isBooleanSchema(p)) { if (p.getDefault() != null) { if ("false".equalsIgnoreCase(p.getDefault().toString())) defaultValue = "false"; @@ -813,18 +812,20 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege defaultValue = "\"" + p.getDefault() + "\".to_string()"; } } + if ((defaultValue != null) && (ModelUtils.isNullable(p))) defaultValue = "Nullable::Present(" + defaultValue + ")"; + return defaultValue; } @Override public void postProcessModelProperty(CodegenModel model, CodegenProperty property) { super.postProcessModelProperty(model, property); + if (!languageSpecificPrimitives.contains(property.dataType)) { - // If we use a more qualified model name, then only camelize the actual type, not the qualifier. - if (property.dataType.contains(":")) { - int position = property.dataType.lastIndexOf(":"); + final int position = property.dataType.lastIndexOf(":"); + if (position != -1) { property.dataType = property.dataType.substring(0, position) + camelize(property.dataType.substring(position)); } else { property.dataType = camelize(property.dataType); @@ -836,42 +837,12 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege // Integer type fitting if (Objects.equals(property.baseType, "integer")) { - BigInteger minimum = Optional.ofNullable(property.getMinimum()).map(BigInteger::new).orElse(null); BigInteger maximum = Optional.ofNullable(property.getMaximum()).map(BigInteger::new).orElse(null); - - boolean unsigned = canFitIntoUnsigned(minimum, property.getExclusiveMinimum()); - - if (Strings.isNullOrEmpty(property.dataFormat)) { - property.dataType = bestFittingIntegerType(minimum, - property.getExclusiveMinimum(), - maximum, - property.getExclusiveMaximum(), - true); - } else { - switch (property.dataFormat) { - // custom integer formats (legacy) - case "uint32": - property.dataType = "u32"; - break; - case "uint64": - property.dataType = "u64"; - break; - case "int32": - property.dataType = unsigned ? "u32" : "i32"; - break; - case "int64": - property.dataType = unsigned ? "u64" : "i64"; - break; - default: - LOGGER.warn("The integer format '{}' is not recognized and will be ignored.", property.dataFormat); - property.dataType = bestFittingIntegerType(minimum, - property.getExclusiveMinimum(), - maximum, - property.getExclusiveMaximum(), - true); - } - } + property.dataType = bestFittingIntegerType( + minimum, property.getExclusiveMinimum(), + maximum, property.getExclusiveMaximum(), + true); } property.name = underscore(property.name); @@ -880,57 +851,41 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege property.defaultValue = (property.defaultValue != null) ? "Some(" + property.defaultValue + ")" : "None"; } - // If a property has no type defined in the schema, it can take values of any type. - // This clashes with Rust being statically typed. Hence, assume it's sent as a json - // blob and return the json value to the user of the API and let the user determine - // the type from the value. If the property has no type, at this point it will have - // baseType "object" allowing us to identify such properties. Moreover, set to not - // nullable, we can use the crate::types::Object::Null enum variant. - if ("object".equals(property.baseType)) { - property.dataType = "crate::types::Object"; + if (isObjectType(property.baseType)) { + property.dataType = objectType; property.isNullable = false; } } @Override - public ModelsMap postProcessModels(ModelsMap objs) { - for (ModelMap mo : objs.getModels()) { + public ModelsMap postProcessModels(ModelsMap modelsMap) { + for (ModelMap mo : modelsMap.getModels()) { CodegenModel cm = mo.getModel(); LOGGER.trace("Post processing model: {}", cm); - if ("object".equals(cm.dataType)) { + if (isObjectType(cm.dataType)) { // Object isn't a sensible default. Instead, we set it to // 'null'. This ensures that we treat this model as a struct // with multiple parameters. cm.dataType = null; } else if ("map".equals(cm.dataType)) { if (!cm.allVars.isEmpty() || cm.additionalPropertiesType == null) { - // We don't yet support `additionalProperties` that also have - // properties. If we see variables, we ignore the - // `additionalProperties` type ('map') and warn the user. This - // will produce code that compiles, but won't feature the - // `additionalProperties` - but that's likely more useful to - // the user than the alternative. LOGGER.warn("Ignoring additionalProperties (see https://github.com/OpenAPITools/openapi-generator/issues/318) alongside defined properties"); cm.dataType = null; } else { - cm.dataType = "std::collections::HashMap"; + cm.dataType = mapType + ""; } } else if (cm.dataType != null) { // We need to hack about with single-parameter models to // get them recognised correctly. cm.isAlias = false; cm.dataType = typeMapping.get(cm.dataType); - - if (uuidType.equals(cm.dataType)) { - additionalProperties.put("apiUsesUuid", true); - } } - cm.vendorExtensions.put("x-is-string", "String".equals(cm.dataType)); + cm.vendorExtensions.put("x-is-string", stringType.equals(cm.dataType)); } - return super.postProcessModelsEnum(objs); + return super.postProcessModelsEnum(modelsMap); } @Override @@ -939,24 +894,30 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege return; } - String commandPrefix = System.getenv("RUST_POST_PROCESS_FILE"); - if (StringUtils.isEmpty(commandPrefix)) { - commandPrefix = "rustfmt"; + final String fileName = file.toString(); + + String[] command; + + String cmd = System.getenv("RUST_POST_PROCESS_FILE"); + if (StringUtils.isEmpty(cmd)) { + cmd = "rustfmt"; + command = new String[]{cmd, "--edition", "2021", fileName}; + } else { + command = new String[]{cmd, fileName}; } // only process files with .rs extension - if ("rs".equals(FilenameUtils.getExtension(file.toString()))) { + if ("rs".equals(FilenameUtils.getExtension(fileName))) { try { - Process p = Runtime.getRuntime().exec(new String[]{commandPrefix, "--edition", "2021", file.toString()}); + Process p = Runtime.getRuntime().exec(command); int exitValue = p.waitFor(); if (exitValue != 0) { - LOGGER.error("Error running the command ({} {}). Exit code: {}", commandPrefix, file, exitValue); + LOGGER.error("Error running the command ({} {}). Exit code: {}", cmd, file, exitValue); } else { - LOGGER.info("Successfully executed: {} {}", commandPrefix, file); + LOGGER.info("Successfully executed: {} {}", cmd, file); } } catch (InterruptedException | IOException e) { - LOGGER.error("Error running the command ({} {}). Exception: {}", commandPrefix, file, e.getMessage()); - // Restore interrupted state + LOGGER.error("Error running the command ({} {}). Exception: {}", cmd, file, e.getMessage()); Thread.currentThread().interrupt(); } } @@ -964,9 +925,6 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege @Override protected void updateParameterForString(CodegenParameter codegenParameter, Schema parameterSchema) { - /* - we have a custom version of this function to set isString to false for uuid - */ if (ModelUtils.isEmailSchema(parameterSchema)) { codegenParameter.isEmail = true; } else if (ModelUtils.isUUIDSchema(parameterSchema)) { @@ -1000,9 +958,6 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege @Override protected void updatePropertyForAnyType(CodegenProperty property, Schema p) { - /* - * we have a custom version of this function to not set isNullable to true - */ // The 'null' value is allowed when the OAS schema is 'any type'. // See https://github.com/OAI/OpenAPI-Specification/issues/1389 if (Boolean.FALSE.equals(p.getNullable())) { diff --git a/samples/server/petstore/rust-axum/output/multipart-v3/src/header.rs b/samples/server/petstore/rust-axum/output/multipart-v3/src/header.rs index 4d1cc4c6dcc..7c530892fbf 100644 --- a/samples/server/petstore/rust-axum/output/multipart-v3/src/header.rs +++ b/samples/server/petstore/rust-axum/output/multipart-v3/src/header.rs @@ -30,11 +30,16 @@ macro_rules! ihv_generate { match hdr_value.to_str() { Ok(hdr_value) => match hdr_value.parse::<$t>() { Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value)), - Err(e) => Err(format!("Unable to parse {} as a string: {}", - stringify!($t), e)), + Err(e) => Err(format!( + "Unable to parse {} as a string: {}", + stringify!($t), + e + )), }, - Err(e) => Err(format!("Unable to parse header {:?} as a string - {}", - hdr_value, e)), + Err(e) => Err(format!( + "Unable to parse header {:?} as a string - {}", + hdr_value, e + )), } } } @@ -69,14 +74,17 @@ impl TryFrom for IntoHeaderValue> { match hdr_value.to_str() { Ok(hdr_value) => Ok(IntoHeaderValue( hdr_value - .split(',') - .filter_map(|x| match x.trim() { - "" => None, - y => Some(y.to_string()), - }) - .collect())), - Err(e) => Err(format!("Unable to parse header: {:?} as a string - {}", - hdr_value, e)), + .split(',') + .filter_map(|x| match x.trim() { + "" => None, + y => Some(y.to_string()), + }) + .collect(), + )), + Err(e) => Err(format!( + "Unable to parse header: {:?} as a string - {}", + hdr_value, e + )), } } } @@ -85,11 +93,13 @@ impl TryFrom>> for HeaderValue { type Error = String; fn try_from(hdr_value: IntoHeaderValue>) -> Result { - match HeaderValue::from_str(&hdr_value.0.join(", ")) { - Ok(hdr_value) => Ok(hdr_value), - Err(e) => Err(format!("Unable to convert {:?} into a header - {}", - hdr_value, e)) - } + match HeaderValue::from_str(&hdr_value.0.join(", ")) { + Ok(hdr_value) => Ok(hdr_value), + Err(e) => Err(format!( + "Unable to convert {:?} into a header - {}", + hdr_value, e + )), + } } } @@ -101,8 +111,7 @@ impl TryFrom for IntoHeaderValue { fn try_from(hdr_value: HeaderValue) -> Result { match hdr_value.to_str() { Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value.to_string())), - Err(e) => Err(format!("Unable to convert header {:?} to {}", - hdr_value, e)), + Err(e) => Err(format!("Unable to convert header {:?} to {}", hdr_value, e)), } } } @@ -113,8 +122,10 @@ impl TryFrom> for HeaderValue { fn try_from(hdr_value: IntoHeaderValue) -> Result { match HeaderValue::from_str(&hdr_value.0) { Ok(hdr_value) => Ok(hdr_value), - Err(e) => Err(format!("Unable to convert {:?} from a header {}", - hdr_value, e)) + Err(e) => Err(format!( + "Unable to convert {:?} from a header {}", + hdr_value, e + )), } } } @@ -128,11 +139,12 @@ impl TryFrom for IntoHeaderValue { match hdr_value.to_str() { Ok(hdr_value) => match hdr_value.parse() { Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value)), - Err(e) => Err(format!("Unable to parse bool from {} - {}", - hdr_value, e)), + Err(e) => Err(format!("Unable to parse bool from {} - {}", hdr_value, e)), }, - Err(e) => Err(format!("Unable to convert {:?} from a header {}", - hdr_value, e)), + Err(e) => Err(format!( + "Unable to convert {:?} from a header {}", + hdr_value, e + )), } } } @@ -143,8 +155,10 @@ impl TryFrom> for HeaderValue { fn try_from(hdr_value: IntoHeaderValue) -> Result { match HeaderValue::from_str(&hdr_value.0.to_string()) { Ok(hdr_value) => Ok(hdr_value), - Err(e) => Err(format!("Unable to convert: {:?} into a header: {}", - hdr_value, e)) + Err(e) => Err(format!( + "Unable to convert: {:?} into a header: {}", + hdr_value, e + )), } } } @@ -158,11 +172,12 @@ impl TryFrom for IntoHeaderValue> { match hdr_value.to_str() { Ok(hdr_value) => match DateTime::parse_from_rfc3339(hdr_value) { Ok(date) => Ok(IntoHeaderValue(date.with_timezone(&Utc))), - Err(e) => Err(format!("Unable to parse: {} as date - {}", - hdr_value, e)), + Err(e) => Err(format!("Unable to parse: {} as date - {}", hdr_value, e)), }, - Err(e) => Err(format!("Unable to convert header {:?} to string {}", - hdr_value, e)), + Err(e) => Err(format!( + "Unable to convert header {:?} to string {}", + hdr_value, e + )), } } } @@ -173,8 +188,10 @@ impl TryFrom>> for HeaderValue { fn try_from(hdr_value: IntoHeaderValue>) -> Result { match HeaderValue::from_str(hdr_value.0.to_rfc3339().as_str()) { Ok(hdr_value) => Ok(hdr_value), - Err(e) => Err(format!("Unable to convert {:?} to a header: {}", - hdr_value, e)), + Err(e) => Err(format!( + "Unable to convert {:?} to a header: {}", + hdr_value, e + )), } } } diff --git a/samples/server/petstore/rust-axum/output/multipart-v3/src/lib.rs b/samples/server/petstore/rust-axum/output/multipart-v3/src/lib.rs index f0c2fbe49bc..ad0edc3812e 100644 --- a/samples/server/petstore/rust-axum/output/multipart-v3/src/lib.rs +++ b/samples/server/petstore/rust-axum/output/multipart-v3/src/lib.rs @@ -1,4 +1,12 @@ -#![allow(missing_docs, trivial_casts, unused_variables, unused_mut, unused_imports, unused_extern_crates, non_camel_case_types)] +#![allow( + missing_docs, + trivial_casts, + unused_variables, + unused_mut, + unused_imports, + unused_extern_crates, + non_camel_case_types +)] #![allow(unused_imports, unused_attributes)] #![allow(clippy::derive_partial_eq_without_eq, clippy::disallowed_names)] @@ -14,65 +22,60 @@ use types::*; pub const BASE_PATH: &str = ""; pub const API_VERSION: &str = "1.0.7"; - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum MultipartRelatedRequestPostResponse { /// OK - Status201_OK + Status201_OK, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum MultipartRequestPostResponse { /// OK - Status201_OK + Status201_OK, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum MultipleIdenticalMimeTypesPostResponse { /// OK - Status200_OK + Status200_OK, } - /// API #[async_trait] #[allow(clippy::ptr_arg)] pub trait Api { + /// MultipartRelatedRequestPost - POST /multipart_related_request + async fn multipart_related_request_post( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: axum::body::Body, + ) -> Result; - /// MultipartRelatedRequestPost - POST /multipart_related_request - async fn multipart_related_request_post( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: axum::body::Body, - ) -> Result; - - - /// MultipartRequestPost - POST /multipart_request - async fn multipart_request_post( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Multipart, - ) -> Result; - - - /// MultipleIdenticalMimeTypesPost - POST /multiple-identical-mime-types - async fn multiple_identical_mime_types_post( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: axum::body::Body, - ) -> Result; + /// MultipartRequestPost - POST /multipart_request + async fn multipart_request_post( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: Multipart, + ) -> Result; + /// MultipleIdenticalMimeTypesPost - POST /multiple-identical-mime-types + async fn multiple_identical_mime_types_post( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: axum::body::Body, + ) -> Result; } #[cfg(feature = "server")] diff --git a/samples/server/petstore/rust-axum/output/multipart-v3/src/models.rs b/samples/server/petstore/rust-axum/output/multipart-v3/src/models.rs index 6ccb7d3f84d..56ed14cbe8a 100644 --- a/samples/server/petstore/rust-axum/output/multipart-v3/src/models.rs +++ b/samples/server/petstore/rust-axum/output/multipart-v3/src/models.rs @@ -7,34 +7,24 @@ use validator::Validate; use crate::header; use crate::{models, types::*}; - - - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct MultipartRelatedRequest { #[serde(rename = "object_field")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub object_field: Option, #[serde(rename = "optional_binary_field")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub optional_binary_field: Option, #[serde(rename = "required_binary_field")] pub required_binary_field: ByteArray, - } - impl MultipartRelatedRequest { #[allow(clippy::new_without_default, clippy::too_many_arguments)] - pub fn new(required_binary_field: ByteArray, ) -> MultipartRelatedRequest { + pub fn new(required_binary_field: ByteArray) -> MultipartRelatedRequest { MultipartRelatedRequest { object_field: None, optional_binary_field: None, @@ -88,7 +78,11 @@ impl std::str::FromStr for MultipartRelatedRequest { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing MultipartRelatedRequest".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing MultipartRelatedRequest".to_string(), + ) + } }; if let Some(key) = key_result { @@ -110,7 +104,13 @@ impl std::str::FromStr for MultipartRelatedRequest { std::result::Result::Ok(MultipartRelatedRequest { object_field: intermediate_rep.object_field.into_iter().next(), optional_binary_field: intermediate_rep.optional_binary_field.into_iter().next(), - required_binary_field: intermediate_rep.required_binary_field.into_iter().next().ok_or_else(|| "required_binary_field missing in MultipartRelatedRequest".to_string())?, + required_binary_field: intermediate_rep + .required_binary_field + .into_iter() + .next() + .ok_or_else(|| { + "required_binary_field missing in MultipartRelatedRequest".to_string() + })?, }) } } @@ -121,13 +121,16 @@ impl std::str::FromStr for MultipartRelatedRequest { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for MultipartRelatedRequest - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for MultipartRelatedRequest - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -138,27 +141,25 @@ impl std::convert::TryFrom for header::IntoHeaderValue std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into MultipartRelatedRequest - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into MultipartRelatedRequest - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct MultipartRequestObjectField { @@ -166,15 +167,13 @@ pub struct MultipartRequestObjectField { pub field_a: String, #[serde(rename = "field_b")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub field_b: Option>, - } - impl MultipartRequestObjectField { #[allow(clippy::new_without_default, clippy::too_many_arguments)] - pub fn new(field_a: String, ) -> MultipartRequestObjectField { + pub fn new(field_a: String) -> MultipartRequestObjectField { MultipartRequestObjectField { field_a, field_b: None, @@ -188,18 +187,19 @@ impl MultipartRequestObjectField { impl std::string::ToString for MultipartRequestObjectField { fn to_string(&self) -> String { let params: Vec> = vec![ - Some("field_a".to_string()), Some(self.field_a.to_string()), - - self.field_b.as_ref().map(|field_b| { [ "field_b".to_string(), - field_b.iter().map(|x| x.to_string()).collect::>().join(","), - ].join(",") + field_b + .iter() + .map(|x| x.to_string()) + .collect::>() + .join(","), + ] + .join(",") }), - ]; params.into_iter().flatten().collect::>().join(",") @@ -230,7 +230,11 @@ impl std::str::FromStr for MultipartRequestObjectField { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing MultipartRequestObjectField".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing MultipartRequestObjectField".to_string(), + ) + } }; if let Some(key) = key_result { @@ -249,7 +253,11 @@ impl std::str::FromStr for MultipartRequestObjectField { // Use the intermediate representation to return the struct std::result::Result::Ok(MultipartRequestObjectField { - field_a: intermediate_rep.field_a.into_iter().next().ok_or_else(|| "field_a missing in MultipartRequestObjectField".to_string())?, + field_a: intermediate_rep + .field_a + .into_iter() + .next() + .ok_or_else(|| "field_a missing in MultipartRequestObjectField".to_string())?, field_b: intermediate_rep.field_b.into_iter().next(), }) } @@ -261,13 +269,16 @@ impl std::str::FromStr for MultipartRequestObjectField { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for MultipartRequestObjectField - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for MultipartRequestObjectField - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -278,41 +289,37 @@ impl std::convert::TryFrom for header::IntoHeaderValue std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into MultipartRequestObjectField - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into MultipartRequestObjectField - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct MultipleIdenticalMimeTypesPostRequest { #[serde(rename = "binary1")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub binary1: Option, #[serde(rename = "binary2")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub binary2: Option, - } - impl MultipleIdenticalMimeTypesPostRequest { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> MultipleIdenticalMimeTypesPostRequest { @@ -365,7 +372,12 @@ impl std::str::FromStr for MultipleIdenticalMimeTypesPostRequest { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing MultipleIdenticalMimeTypesPostRequest".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing MultipleIdenticalMimeTypesPostRequest" + .to_string(), + ) + } }; if let Some(key) = key_result { @@ -392,10 +404,14 @@ impl std::str::FromStr for MultipleIdenticalMimeTypesPostRequest { // Methods for converting between header::IntoHeaderValue and HeaderValue #[cfg(feature = "server")] -impl std::convert::TryFrom> for HeaderValue { +impl std::convert::TryFrom> + for HeaderValue +{ type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), @@ -407,7 +423,9 @@ impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom + for header::IntoHeaderValue +{ type Error = String; fn try_from(hdr_value: HeaderValue) -> std::result::Result { @@ -426,6 +444,3 @@ impl std::convert::TryFrom for header::IntoHeaderValue) + .route( + "/multipart_related_request", + post(multipart_related_request_post::), ) - .route("/multipart_request", - post(multipart_request_post::) - ) - .route("/multiple-identical-mime-types", - post(multiple_identical_mime_types_post::) + .route("/multipart_request", post(multipart_request_post::)) + .route( + "/multiple-identical-mime-types", + post(multiple_identical_mime_types_post::), ) .with_state(api_impl) } - #[tracing::instrument(skip_all)] -fn multipart_related_request_post_validation( -) -> std::result::Result<( -), ValidationErrors> -{ - -Ok(( -)) +fn multipart_related_request_post_validation() -> std::result::Result<(), ValidationErrors> { + Ok(()) } /// MultipartRelatedRequestPost - POST /multipart_related_request #[tracing::instrument(skip_all)] async fn multipart_related_request_post( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - body: axum::body::Body, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + body: axum::body::Body, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = + tokio::task::spawn_blocking(move || multipart_related_request_post_validation()) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - multipart_related_request_post_validation( - ) - ).await.unwrap(); - - let Ok(( - )) = validation else { - return Response::builder() + let Ok(()) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().multipart_related_request_post( - method, - host, - cookies, - body, - ).await; + let result = api_impl + .as_ref() + .multipart_related_request_post(method, host, cookies, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - MultipartRelatedRequestPostResponse::Status201_OK - => { + let resp = match result { + Ok(rsp) => match rsp { + MultipartRelatedRequestPostResponse::Status201_OK => { + let mut response = response.status(201); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(201); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] -fn multipart_request_post_validation( -) -> std::result::Result<( -), ValidationErrors> -{ - -Ok(( -)) +fn multipart_request_post_validation() -> std::result::Result<(), ValidationErrors> { + Ok(()) } /// MultipartRequestPost - POST /multipart_request #[tracing::instrument(skip_all)] async fn multipart_request_post( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - body: Multipart, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + body: Multipart, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || multipart_request_post_validation()) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - multipart_request_post_validation( - ) - ).await.unwrap(); - - let Ok(( - )) = validation else { - return Response::builder() + let Ok(()) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().multipart_request_post( - method, - host, - cookies, - body, - ).await; + let result = api_impl + .as_ref() + .multipart_request_post(method, host, cookies, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - MultipartRequestPostResponse::Status201_OK - => { + let resp = match result { + Ok(rsp) => match rsp { + MultipartRequestPostResponse::Status201_OK => { + let mut response = response.status(201); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(201); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] -fn multiple_identical_mime_types_post_validation( -) -> std::result::Result<( -), ValidationErrors> -{ - -Ok(( -)) +fn multiple_identical_mime_types_post_validation() -> std::result::Result<(), ValidationErrors> { + Ok(()) } /// MultipleIdenticalMimeTypesPost - POST /multiple-identical-mime-types #[tracing::instrument(skip_all)] async fn multiple_identical_mime_types_post( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - body: axum::body::Body, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + body: axum::body::Body, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = + tokio::task::spawn_blocking(move || multiple_identical_mime_types_post_validation()) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - multiple_identical_mime_types_post_validation( - ) - ).await.unwrap(); - - let Ok(( - )) = validation else { - return Response::builder() + let Ok(()) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().multiple_identical_mime_types_post( - method, - host, - cookies, - body, - ).await; + let result = api_impl + .as_ref() + .multiple_identical_mime_types_post(method, host, cookies, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - MultipleIdenticalMimeTypesPostResponse::Status200_OK - => { + let resp = match result { + Ok(rsp) => match rsp { + MultipleIdenticalMimeTypesPostResponse::Status200_OK => { + let mut response = response.status(200); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(200); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - diff --git a/samples/server/petstore/rust-axum/output/openapi-v3/src/header.rs b/samples/server/petstore/rust-axum/output/openapi-v3/src/header.rs index 4d1cc4c6dcc..7c530892fbf 100644 --- a/samples/server/petstore/rust-axum/output/openapi-v3/src/header.rs +++ b/samples/server/petstore/rust-axum/output/openapi-v3/src/header.rs @@ -30,11 +30,16 @@ macro_rules! ihv_generate { match hdr_value.to_str() { Ok(hdr_value) => match hdr_value.parse::<$t>() { Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value)), - Err(e) => Err(format!("Unable to parse {} as a string: {}", - stringify!($t), e)), + Err(e) => Err(format!( + "Unable to parse {} as a string: {}", + stringify!($t), + e + )), }, - Err(e) => Err(format!("Unable to parse header {:?} as a string - {}", - hdr_value, e)), + Err(e) => Err(format!( + "Unable to parse header {:?} as a string - {}", + hdr_value, e + )), } } } @@ -69,14 +74,17 @@ impl TryFrom for IntoHeaderValue> { match hdr_value.to_str() { Ok(hdr_value) => Ok(IntoHeaderValue( hdr_value - .split(',') - .filter_map(|x| match x.trim() { - "" => None, - y => Some(y.to_string()), - }) - .collect())), - Err(e) => Err(format!("Unable to parse header: {:?} as a string - {}", - hdr_value, e)), + .split(',') + .filter_map(|x| match x.trim() { + "" => None, + y => Some(y.to_string()), + }) + .collect(), + )), + Err(e) => Err(format!( + "Unable to parse header: {:?} as a string - {}", + hdr_value, e + )), } } } @@ -85,11 +93,13 @@ impl TryFrom>> for HeaderValue { type Error = String; fn try_from(hdr_value: IntoHeaderValue>) -> Result { - match HeaderValue::from_str(&hdr_value.0.join(", ")) { - Ok(hdr_value) => Ok(hdr_value), - Err(e) => Err(format!("Unable to convert {:?} into a header - {}", - hdr_value, e)) - } + match HeaderValue::from_str(&hdr_value.0.join(", ")) { + Ok(hdr_value) => Ok(hdr_value), + Err(e) => Err(format!( + "Unable to convert {:?} into a header - {}", + hdr_value, e + )), + } } } @@ -101,8 +111,7 @@ impl TryFrom for IntoHeaderValue { fn try_from(hdr_value: HeaderValue) -> Result { match hdr_value.to_str() { Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value.to_string())), - Err(e) => Err(format!("Unable to convert header {:?} to {}", - hdr_value, e)), + Err(e) => Err(format!("Unable to convert header {:?} to {}", hdr_value, e)), } } } @@ -113,8 +122,10 @@ impl TryFrom> for HeaderValue { fn try_from(hdr_value: IntoHeaderValue) -> Result { match HeaderValue::from_str(&hdr_value.0) { Ok(hdr_value) => Ok(hdr_value), - Err(e) => Err(format!("Unable to convert {:?} from a header {}", - hdr_value, e)) + Err(e) => Err(format!( + "Unable to convert {:?} from a header {}", + hdr_value, e + )), } } } @@ -128,11 +139,12 @@ impl TryFrom for IntoHeaderValue { match hdr_value.to_str() { Ok(hdr_value) => match hdr_value.parse() { Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value)), - Err(e) => Err(format!("Unable to parse bool from {} - {}", - hdr_value, e)), + Err(e) => Err(format!("Unable to parse bool from {} - {}", hdr_value, e)), }, - Err(e) => Err(format!("Unable to convert {:?} from a header {}", - hdr_value, e)), + Err(e) => Err(format!( + "Unable to convert {:?} from a header {}", + hdr_value, e + )), } } } @@ -143,8 +155,10 @@ impl TryFrom> for HeaderValue { fn try_from(hdr_value: IntoHeaderValue) -> Result { match HeaderValue::from_str(&hdr_value.0.to_string()) { Ok(hdr_value) => Ok(hdr_value), - Err(e) => Err(format!("Unable to convert: {:?} into a header: {}", - hdr_value, e)) + Err(e) => Err(format!( + "Unable to convert: {:?} into a header: {}", + hdr_value, e + )), } } } @@ -158,11 +172,12 @@ impl TryFrom for IntoHeaderValue> { match hdr_value.to_str() { Ok(hdr_value) => match DateTime::parse_from_rfc3339(hdr_value) { Ok(date) => Ok(IntoHeaderValue(date.with_timezone(&Utc))), - Err(e) => Err(format!("Unable to parse: {} as date - {}", - hdr_value, e)), + Err(e) => Err(format!("Unable to parse: {} as date - {}", hdr_value, e)), }, - Err(e) => Err(format!("Unable to convert header {:?} to string {}", - hdr_value, e)), + Err(e) => Err(format!( + "Unable to convert header {:?} to string {}", + hdr_value, e + )), } } } @@ -173,8 +188,10 @@ impl TryFrom>> for HeaderValue { fn try_from(hdr_value: IntoHeaderValue>) -> Result { match HeaderValue::from_str(hdr_value.0.to_rfc3339().as_str()) { Ok(hdr_value) => Ok(hdr_value), - Err(e) => Err(format!("Unable to convert {:?} to a header: {}", - hdr_value, e)), + Err(e) => Err(format!( + "Unable to convert {:?} to a header: {}", + hdr_value, e + )), } } } diff --git a/samples/server/petstore/rust-axum/output/openapi-v3/src/lib.rs b/samples/server/petstore/rust-axum/output/openapi-v3/src/lib.rs index b72ebe84cb8..a86c406ffee 100644 --- a/samples/server/petstore/rust-axum/output/openapi-v3/src/lib.rs +++ b/samples/server/petstore/rust-axum/output/openapi-v3/src/lib.rs @@ -1,4 +1,12 @@ -#![allow(missing_docs, trivial_casts, unused_variables, unused_mut, unused_imports, unused_extern_crates, non_camel_case_types)] +#![allow( + missing_docs, + trivial_casts, + unused_variables, + unused_mut, + unused_imports, + unused_extern_crates, + non_camel_case_types +)] #![allow(unused_imports, unused_attributes)] #![allow(clippy::derive_partial_eq_without_eq, clippy::disallowed_names)] @@ -14,569 +22,488 @@ use types::*; pub const BASE_PATH: &str = ""; pub const API_VERSION: &str = "1.0.7"; - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum AnyOfGetResponse { /// Success - Status200_Success - (models::AnyOfObject) - , + Status200_Success(models::AnyOfObject), /// AlternateSuccess - Status201_AlternateSuccess - (models::Model12345AnyOfObject) - , + Status201_AlternateSuccess(models::Model12345AnyOfObject), /// AnyOfSuccess - Status202_AnyOfSuccess - (models::AnyOfGet202Response) + Status202_AnyOfSuccess(models::AnyOfGet202Response), } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum CallbackWithHeaderPostResponse { /// OK - Status204_OK + Status204_OK, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum ComplexQueryParamGetResponse { /// Success - Status200_Success + Status200_Success, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum EnumInPathPathParamGetResponse { /// Success - Status200_Success + Status200_Success, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum JsonComplexQueryParamGetResponse { /// Success - Status200_Success + Status200_Success, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum MandatoryRequestHeaderGetResponse { /// Success - Status200_Success + Status200_Success, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum MergePatchJsonGetResponse { /// merge-patch+json-encoded response - Status200_Merge - (models::AnotherXmlObject) + Status200_Merge(models::AnotherXmlObject), } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum MultigetGetResponse { /// JSON rsp - Status200_JSONRsp - (models::AnotherXmlObject) - , + Status200_JSONRsp(models::AnotherXmlObject), /// XML rsp - Status201_XMLRsp - (String) - , + Status201_XMLRsp(String), /// octet rsp - Status202_OctetRsp - (ByteArray) - , + Status202_OctetRsp(ByteArray), /// string rsp - Status203_StringRsp - (String) - , + Status203_StringRsp(String), /// Duplicate Response long text. One. - Status204_DuplicateResponseLongText - (models::AnotherXmlObject) - , + Status204_DuplicateResponseLongText(models::AnotherXmlObject), /// Duplicate Response long text. Two. - Status205_DuplicateResponseLongText - (models::AnotherXmlObject) - , + Status205_DuplicateResponseLongText(models::AnotherXmlObject), /// Duplicate Response long text. Three. - Status206_DuplicateResponseLongText - (models::AnotherXmlObject) + Status206_DuplicateResponseLongText(models::AnotherXmlObject), } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum MultipleAuthSchemeGetResponse { /// Check that limiting to multiple required auth schemes works - Status200_CheckThatLimitingToMultipleRequiredAuthSchemesWorks + Status200_CheckThatLimitingToMultipleRequiredAuthSchemesWorks, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum OneOfGetResponse { /// Success - Status200_Success - (models::OneOfGet200Response) + Status200_Success(models::OneOfGet200Response), } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum OverrideServerGetResponse { /// Success. - Status204_Success + Status204_Success, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum ParamgetGetResponse { /// JSON rsp - Status200_JSONRsp - (models::AnotherXmlObject) + Status200_JSONRsp(models::AnotherXmlObject), } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum ReadonlyAuthSchemeGetResponse { /// Check that limiting to a single required auth scheme works - Status200_CheckThatLimitingToASingleRequiredAuthSchemeWorks + Status200_CheckThatLimitingToASingleRequiredAuthSchemeWorks, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum RegisterCallbackPostResponse { /// OK - Status204_OK + Status204_OK, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum RequiredOctetStreamPutResponse { /// OK - Status200_OK + Status200_OK, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum ResponsesWithHeadersGetResponse { /// Success - Status200_Success - { + Status200_Success { body: String, - success_info: - String - , - bool_header: - Option< - bool - > - , - object_header: - Option< - models::ObjectHeader - > - } - , + success_info: String, + bool_header: Option, + object_header: Option, + }, /// Precondition Failed - Status412_PreconditionFailed - { - further_info: - Option< - String - > - , - failure_info: - Option< - String - > - } + Status412_PreconditionFailed { + further_info: Option, + failure_info: Option, + }, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum Rfc7807GetResponse { /// OK - Status204_OK - (models::ObjectWithArrayOfObjects) - , + Status204_OK(models::ObjectWithArrayOfObjects), /// NotFound - Status404_NotFound - (models::ObjectWithArrayOfObjects) - , + Status404_NotFound(models::ObjectWithArrayOfObjects), /// NotAcceptable - Status406_NotAcceptable - (String) + Status406_NotAcceptable(String), } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum UntypedPropertyGetResponse { /// Check that untyped properties works - Status200_CheckThatUntypedPropertiesWorks + Status200_CheckThatUntypedPropertiesWorks, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum UuidGetResponse { /// Duplicate Response long text. One. - Status200_DuplicateResponseLongText - (uuid::Uuid) + Status200_DuplicateResponseLongText(uuid::Uuid), } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum XmlExtraPostResponse { /// OK - Status201_OK - , + Status201_OK, /// Bad Request - Status400_BadRequest + Status400_BadRequest, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum XmlOtherPostResponse { /// OK - Status201_OK - (String) - , + Status201_OK(String), /// Bad Request - Status400_BadRequest + Status400_BadRequest, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum XmlOtherPutResponse { /// OK - Status201_OK - , + Status201_OK, /// Bad Request - Status400_BadRequest + Status400_BadRequest, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum XmlPostResponse { /// OK - Status201_OK - , + Status201_OK, /// Bad Request - Status400_BadRequest + Status400_BadRequest, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum XmlPutResponse { /// OK - Status201_OK - , + Status201_OK, /// Bad Request - Status400_BadRequest + Status400_BadRequest, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum CreateRepoResponse { /// Success - Status200_Success + Status200_Success, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum GetRepoInfoResponse { /// OK - Status200_OK - (String) + Status200_OK(String), } - /// API #[async_trait] #[allow(clippy::ptr_arg)] pub trait Api { + /// AnyOfGet - GET /any-of + async fn any_of_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + query_params: models::AnyOfGetQueryParams, + ) -> Result; - /// AnyOfGet - GET /any-of - async fn any_of_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::AnyOfGetQueryParams, - ) -> Result; + /// CallbackWithHeaderPost - POST /callback-with-header + async fn callback_with_header_post( + &self, + method: Method, + host: Host, + cookies: CookieJar, + query_params: models::CallbackWithHeaderPostQueryParams, + ) -> Result; + /// ComplexQueryParamGet - GET /complex-query-param + async fn complex_query_param_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + query_params: models::ComplexQueryParamGetQueryParams, + ) -> Result; - /// CallbackWithHeaderPost - POST /callback-with-header - async fn callback_with_header_post( - &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::CallbackWithHeaderPostQueryParams, - ) -> Result; + /// EnumInPathPathParamGet - GET /enum_in_path/{path_param} + async fn enum_in_path_path_param_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::EnumInPathPathParamGetPathParams, + ) -> Result; + /// JsonComplexQueryParamGet - GET /json-complex-query-param + async fn json_complex_query_param_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + query_params: models::JsonComplexQueryParamGetQueryParams, + ) -> Result; - /// ComplexQueryParamGet - GET /complex-query-param - async fn complex_query_param_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::ComplexQueryParamGetQueryParams, - ) -> Result; + /// MandatoryRequestHeaderGet - GET /mandatory-request-header + async fn mandatory_request_header_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + header_params: models::MandatoryRequestHeaderGetHeaderParams, + ) -> Result; + /// MergePatchJsonGet - GET /merge-patch-json + async fn merge_patch_json_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; - /// EnumInPathPathParamGet - GET /enum_in_path/{path_param} - async fn enum_in_path_path_param_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::EnumInPathPathParamGetPathParams, - ) -> Result; + /// Get some stuff.. + /// + /// MultigetGet - GET /multiget + async fn multiget_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// MultipleAuthSchemeGet - GET /multiple_auth_scheme + async fn multiple_auth_scheme_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; - /// JsonComplexQueryParamGet - GET /json-complex-query-param - async fn json_complex_query_param_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::JsonComplexQueryParamGetQueryParams, - ) -> Result; + /// OneOfGet - GET /one-of + async fn one_of_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// OverrideServerGet - GET /override-server + async fn override_server_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; - /// MandatoryRequestHeaderGet - GET /mandatory-request-header - async fn mandatory_request_header_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - header_params: models::MandatoryRequestHeaderGetHeaderParams, - ) -> Result; + /// Get some stuff with parameters.. + /// + /// ParamgetGet - GET /paramget + async fn paramget_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + query_params: models::ParamgetGetQueryParams, + ) -> Result; + /// ReadonlyAuthSchemeGet - GET /readonly_auth_scheme + async fn readonly_auth_scheme_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; - /// MergePatchJsonGet - GET /merge-patch-json - async fn merge_patch_json_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + /// RegisterCallbackPost - POST /register-callback + async fn register_callback_post( + &self, + method: Method, + host: Host, + cookies: CookieJar, + query_params: models::RegisterCallbackPostQueryParams, + ) -> Result; + /// RequiredOctetStreamPut - PUT /required_octet_stream + async fn required_octet_stream_put( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: Bytes, + ) -> Result; - /// Get some stuff.. - /// - /// MultigetGet - GET /multiget - async fn multiget_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + /// ResponsesWithHeadersGet - GET /responses_with_headers + async fn responses_with_headers_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Rfc7807Get - GET /rfc7807 + async fn rfc7807_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; - /// MultipleAuthSchemeGet - GET /multiple_auth_scheme - async fn multiple_auth_scheme_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + /// UntypedPropertyGet - GET /untyped_property + async fn untyped_property_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: Option, + ) -> Result; + /// UuidGet - GET /uuid + async fn uuid_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; - /// OneOfGet - GET /one-of - async fn one_of_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + /// XmlExtraPost - POST /xml_extra + async fn xml_extra_post( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: Bytes, + ) -> Result; + /// XmlOtherPost - POST /xml_other + async fn xml_other_post( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: Bytes, + ) -> Result; - /// OverrideServerGet - GET /override-server - async fn override_server_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + /// XmlOtherPut - PUT /xml_other + async fn xml_other_put( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: Bytes, + ) -> Result; + /// Post an array. + /// + /// XmlPost - POST /xml + async fn xml_post( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: Bytes, + ) -> Result; - /// Get some stuff with parameters.. - /// - /// ParamgetGet - GET /paramget - async fn paramget_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::ParamgetGetQueryParams, - ) -> Result; + /// XmlPut - PUT /xml + async fn xml_put( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: Bytes, + ) -> Result; + /// CreateRepo - POST /repos + async fn create_repo( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: models::ObjectParam, + ) -> Result; - /// ReadonlyAuthSchemeGet - GET /readonly_auth_scheme - async fn readonly_auth_scheme_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - - /// RegisterCallbackPost - POST /register-callback - async fn register_callback_post( - &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::RegisterCallbackPostQueryParams, - ) -> Result; - - - /// RequiredOctetStreamPut - PUT /required_octet_stream - async fn required_octet_stream_put( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Bytes, - ) -> Result; - - - /// ResponsesWithHeadersGet - GET /responses_with_headers - async fn responses_with_headers_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - - /// Rfc7807Get - GET /rfc7807 - async fn rfc7807_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - - /// UntypedPropertyGet - GET /untyped_property - async fn untyped_property_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Option, - ) -> Result; - - - /// UuidGet - GET /uuid - async fn uuid_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - - /// XmlExtraPost - POST /xml_extra - async fn xml_extra_post( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Bytes, - ) -> Result; - - - /// XmlOtherPost - POST /xml_other - async fn xml_other_post( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Bytes, - ) -> Result; - - - /// XmlOtherPut - PUT /xml_other - async fn xml_other_put( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Bytes, - ) -> Result; - - - /// Post an array. - /// - /// XmlPost - POST /xml - async fn xml_post( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Bytes, - ) -> Result; - - - /// XmlPut - PUT /xml - async fn xml_put( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Bytes, - ) -> Result; - - - /// CreateRepo - POST /repos - async fn create_repo( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::ObjectParam, - ) -> Result; - - - /// GetRepoInfo - GET /repos/{repoId} - async fn get_repo_info( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::GetRepoInfoPathParams, - ) -> Result; - + /// GetRepoInfo - GET /repos/{repoId} + async fn get_repo_info( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::GetRepoInfoPathParams, + ) -> Result; } #[cfg(feature = "server")] diff --git a/samples/server/petstore/rust-axum/output/openapi-v3/src/models.rs b/samples/server/petstore/rust-axum/output/openapi-v3/src/models.rs index cfa2394362e..9c95d11a9e3 100644 --- a/samples/server/petstore/rust-axum/output/openapi-v3/src/models.rs +++ b/samples/server/petstore/rust-axum/output/openapi-v3/src/models.rs @@ -7,113 +7,80 @@ use validator::Validate; use crate::header; use crate::{models, types::*}; - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct AnyOfGetQueryParams { - /// list of any of objects - #[serde(rename = "any-of")] - #[validate( - length(min = 1), - )] - #[serde(skip_serializing_if="Option::is_none")] - pub any_of: Option>, - } +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct AnyOfGetQueryParams { + /// list of any of objects + #[serde(rename = "any-of")] + #[validate(length(min = 1))] + #[serde(skip_serializing_if = "Option::is_none")] + pub any_of: Option>, +} - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct CallbackWithHeaderPostQueryParams { - #[serde(rename = "url")] - pub url: String, - } +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct CallbackWithHeaderPostQueryParams { + #[serde(rename = "url")] + pub url: String, +} - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct ComplexQueryParamGetQueryParams { - #[serde(rename = "list-of-strings")] - #[serde(skip_serializing_if="Option::is_none")] - pub list_of_strings: Option>, - } +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct ComplexQueryParamGetQueryParams { + #[serde(rename = "list-of-strings")] + #[serde(skip_serializing_if = "Option::is_none")] + pub list_of_strings: Option>, +} - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct EnumInPathPathParamGetPathParams { - pub path_param: models::StringEnum, - } +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct EnumInPathPathParamGetPathParams { + pub path_param: models::StringEnum, +} +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct JsonComplexQueryParamGetQueryParams { + #[serde(rename = "list-of-strings")] + #[serde(skip_serializing_if = "Option::is_none")] + pub list_of_strings: Option>, +} - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct JsonComplexQueryParamGetQueryParams { - #[serde(rename = "list-of-strings")] - #[serde(skip_serializing_if="Option::is_none")] - pub list_of_strings: Option>, - } - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct MandatoryRequestHeaderGetHeaderParams { - pub x_header: String, - } - - - - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct ParamgetGetQueryParams { - /// The stuff to get - #[serde(rename = "uuid")] - #[serde(skip_serializing_if="Option::is_none")] - pub uuid: Option, - /// Some object to pass as query parameter - #[serde(rename = "someObject")] - #[serde(skip_serializing_if="Option::is_none")] - pub some_object: Option, - /// Some list to pass as query parameter - #[serde(rename = "someList")] - #[serde(skip_serializing_if="Option::is_none")] - pub some_list: Option>, - } - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct RegisterCallbackPostQueryParams { - #[serde(rename = "url")] - pub url: String, - } - - - - - - - - - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct GetRepoInfoPathParams { - pub repo_id: String, - } +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct MandatoryRequestHeaderGetHeaderParams { + pub x_header: String, +} +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct ParamgetGetQueryParams { + /// The stuff to get + #[serde(rename = "uuid")] + #[serde(skip_serializing_if = "Option::is_none")] + pub uuid: Option, + /// Some object to pass as query parameter + #[serde(rename = "someObject")] + #[serde(skip_serializing_if = "Option::is_none")] + pub some_object: Option, + /// Some list to pass as query parameter + #[serde(rename = "someList")] + #[serde(skip_serializing_if = "Option::is_none")] + pub some_list: Option>, +} +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct RegisterCallbackPostQueryParams { + #[serde(rename = "url")] + pub url: String, +} +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct GetRepoInfoPathParams { + pub repo_id: String, +} #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] @@ -125,13 +92,17 @@ impl validator::Validate for AdditionalPropertiesWithList { } } -impl std::convert::From>> for AdditionalPropertiesWithList { +impl std::convert::From>> + for AdditionalPropertiesWithList +{ fn from(x: std::collections::HashMap>) -> Self { AdditionalPropertiesWithList(x) } } -impl std::convert::From for std::collections::HashMap> { +impl std::convert::From + for std::collections::HashMap> +{ fn from(x: AdditionalPropertiesWithList) -> Self { x.0 } @@ -167,11 +138,12 @@ impl ::std::str::FromStr for AdditionalPropertiesWithList { type Err = &'static str; fn from_str(s: &str) -> std::result::Result { - std::result::Result::Err("Parsing additionalProperties for AdditionalPropertiesWithList is not supported") + std::result::Result::Err( + "Parsing additionalProperties for AdditionalPropertiesWithList is not supported", + ) } } - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct AnotherXmlArray(Vec); @@ -195,7 +167,7 @@ impl std::convert::From for Vec { } impl std::iter::FromIterator for AnotherXmlArray { - fn from_iter>(u: U) -> Self { + fn from_iter>(u: U) -> Self { AnotherXmlArray(Vec::::from_iter(u)) } } @@ -245,7 +217,10 @@ impl std::ops::DerefMut for AnotherXmlArray { /// Should be implemented in a serde serializer impl std::string::ToString for AnotherXmlArray { fn to_string(&self) -> String { - self.iter().map(|x| x.to_string()).collect::>().join(",") + self.iter() + .map(|x| x.to_string()) + .collect::>() + .join(",") } } @@ -257,28 +232,29 @@ impl std::str::FromStr for AnotherXmlArray { fn from_str(s: &str) -> std::result::Result { let mut items = vec![]; - for item in s.split(',') - { + for item in s.split(',') { items.push(item.parse()?); } std::result::Result::Ok(AnotherXmlArray(items)) } } - // Methods for converting between header::IntoHeaderValue and HeaderValue #[cfg(feature = "server")] impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for AnotherXmlArray - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for AnotherXmlArray - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -289,24 +265,25 @@ impl std::convert::TryFrom for header::IntoHeaderValue std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into AnotherXmlArray - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into AnotherXmlArray - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - #[derive(Debug, Clone, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct AnotherXmlInner(String); @@ -325,7 +302,7 @@ impl std::convert::From for AnotherXmlInner { impl std::string::ToString for AnotherXmlInner { fn to_string(&self) -> String { - self.0.to_string() + self.0.to_string() } } @@ -355,28 +332,20 @@ impl std::ops::DerefMut for AnotherXmlInner { } } - - /// An XML object - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct AnotherXmlObject { #[serde(rename = "inner_string")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub inner_string: Option, - } - impl AnotherXmlObject { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> AnotherXmlObject { - AnotherXmlObject { - inner_string: None, - } + AnotherXmlObject { inner_string: None } } } @@ -385,16 +354,10 @@ impl AnotherXmlObject { /// Should be implemented in a serde serializer impl std::string::ToString for AnotherXmlObject { fn to_string(&self) -> String { - let params: Vec> = vec![ - - self.inner_string.as_ref().map(|inner_string| { - [ - "inner_string".to_string(), - inner_string.to_string(), - ].join(",") - }), - - ]; + let params: Vec> = vec![self + .inner_string + .as_ref() + .map(|inner_string| ["inner_string".to_string(), inner_string.to_string()].join(","))]; params.into_iter().flatten().collect::>().join(",") } @@ -423,15 +386,25 @@ impl std::str::FromStr for AnotherXmlObject { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing AnotherXmlObject".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing AnotherXmlObject".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "inner_string" => intermediate_rep.inner_string.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing AnotherXmlObject".to_string()) + "inner_string" => intermediate_rep.inner_string.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing AnotherXmlObject".to_string(), + ) + } } } @@ -452,13 +425,16 @@ impl std::str::FromStr for AnotherXmlObject { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for AnotherXmlObject - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for AnotherXmlObject - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -469,33 +445,32 @@ impl std::convert::TryFrom for header::IntoHeaderValue std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into AnotherXmlObject - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into AnotherXmlObject - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - - /// Any of: /// - String /// - uuid::Uuid #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct AnyOfGet202Response(Box); -impl validator::Validate for AnyOfGet202Response -{ +impl validator::Validate for AnyOfGet202Response { fn validate(&self) -> std::result::Result<(), validator::ValidationErrors> { std::result::Result::Ok(()) } @@ -518,11 +493,6 @@ impl PartialEq for AnyOfGet202Response { } } - - - - - /// Test a model containing an anyOf /// Any of: @@ -530,8 +500,7 @@ impl PartialEq for AnyOfGet202Response { #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct AnyOfObject(Box); -impl validator::Validate for AnyOfObject -{ +impl validator::Validate for AnyOfObject { fn validate(&self) -> std::result::Result<(), validator::ValidationErrors> { std::result::Result::Ok(()) } @@ -554,15 +523,8 @@ impl PartialEq for AnyOfObject { } } - - - - - /// Test containing an anyOf object - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct AnyOfProperty { @@ -570,15 +532,13 @@ pub struct AnyOfProperty { pub required_any_of: models::AnyOfObject, #[serde(rename = "optionalAnyOf")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub optional_any_of: Option, - } - impl AnyOfProperty { #[allow(clippy::new_without_default, clippy::too_many_arguments)] - pub fn new(required_any_of: models::AnyOfObject, ) -> AnyOfProperty { + pub fn new(required_any_of: models::AnyOfObject) -> AnyOfProperty { AnyOfProperty { required_any_of, optional_any_of: None, @@ -626,17 +586,31 @@ impl std::str::FromStr for AnyOfProperty { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing AnyOfProperty".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing AnyOfProperty".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "requiredAnyOf" => intermediate_rep.required_any_of.push(::from_str(val).map_err(|x| x.to_string())?), + "requiredAnyOf" => intermediate_rep.required_any_of.push( + ::from_str(val) + .map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "optionalAnyOf" => intermediate_rep.optional_any_of.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing AnyOfProperty".to_string()) + "optionalAnyOf" => intermediate_rep.optional_any_of.push( + ::from_str(val) + .map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing AnyOfProperty".to_string(), + ) + } } } @@ -646,7 +620,11 @@ impl std::str::FromStr for AnyOfProperty { // Use the intermediate representation to return the struct std::result::Result::Ok(AnyOfProperty { - required_any_of: intermediate_rep.required_any_of.into_iter().next().ok_or_else(|| "requiredAnyOf missing in AnyOfProperty".to_string())?, + required_any_of: intermediate_rep + .required_any_of + .into_iter() + .next() + .ok_or_else(|| "requiredAnyOf missing in AnyOfProperty".to_string())?, optional_any_of: intermediate_rep.optional_any_of.into_iter().next(), }) } @@ -658,13 +636,16 @@ impl std::str::FromStr for AnyOfProperty { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for AnyOfProperty - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for AnyOfProperty - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -675,44 +656,41 @@ impl std::convert::TryFrom for header::IntoHeaderValue std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into AnyOfProperty - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into AnyOfProperty - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - /// An XML object - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct DuplicateXmlObject { #[serde(rename = "inner_string")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub inner_string: Option, #[serde(rename = "inner_array")] pub inner_array: models::XmlArray, - } - impl DuplicateXmlObject { #[allow(clippy::new_without_default, clippy::too_many_arguments)] - pub fn new(inner_array: models::XmlArray, ) -> DuplicateXmlObject { + pub fn new(inner_array: models::XmlArray) -> DuplicateXmlObject { DuplicateXmlObject { inner_string: None, inner_array, @@ -726,16 +704,10 @@ impl DuplicateXmlObject { impl std::string::ToString for DuplicateXmlObject { fn to_string(&self) -> String { let params: Vec> = vec![ - self.inner_string.as_ref().map(|inner_string| { - [ - "inner_string".to_string(), - inner_string.to_string(), - ].join(",") + ["inner_string".to_string(), inner_string.to_string()].join(",") }), - // Skipping inner_array in query parameter serialization - ]; params.into_iter().flatten().collect::>().join(",") @@ -766,17 +738,30 @@ impl std::str::FromStr for DuplicateXmlObject { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing DuplicateXmlObject".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing DuplicateXmlObject".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "inner_string" => intermediate_rep.inner_string.push(::from_str(val).map_err(|x| x.to_string())?), + "inner_string" => intermediate_rep.inner_string.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "inner_array" => intermediate_rep.inner_array.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing DuplicateXmlObject".to_string()) + "inner_array" => intermediate_rep.inner_array.push( + ::from_str(val) + .map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing DuplicateXmlObject".to_string(), + ) + } } } @@ -787,7 +772,11 @@ impl std::str::FromStr for DuplicateXmlObject { // Use the intermediate representation to return the struct std::result::Result::Ok(DuplicateXmlObject { inner_string: intermediate_rep.inner_string.into_iter().next(), - inner_array: intermediate_rep.inner_array.into_iter().next().ok_or_else(|| "inner_array missing in DuplicateXmlObject".to_string())?, + inner_array: intermediate_rep + .inner_array + .into_iter() + .next() + .ok_or_else(|| "inner_array missing in DuplicateXmlObject".to_string())?, }) } } @@ -798,13 +787,16 @@ impl std::str::FromStr for DuplicateXmlObject { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for DuplicateXmlObject - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for DuplicateXmlObject - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -815,31 +807,34 @@ impl std::convert::TryFrom for header::IntoHeaderValue std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into DuplicateXmlObject - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into DuplicateXmlObject - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - /// Test a model containing a special character in the enum /// Enumeration of values. /// Since this enum's variants do not hold data, we can easily define them as `#[repr(C)]` /// which helps with FFI. #[allow(non_camel_case_types)] #[repr(C)] -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize)] +#[derive( + Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize, +)] #[cfg_attr(feature = "conversion", derive(frunk_enum_derive::LabelledGenericEnum))] pub enum EnumWithStarObject { #[serde(rename = "FOO")] @@ -873,7 +868,6 @@ impl std::str::FromStr for EnumWithStarObject { } } - #[derive(Debug, Clone, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct Err(String); @@ -892,7 +886,7 @@ impl std::convert::From for Err { impl std::string::ToString for Err { fn to_string(&self) -> String { - self.0.to_string() + self.0.to_string() } } @@ -922,8 +916,6 @@ impl std::ops::DerefMut for Err { } } - - #[derive(Debug, Clone, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct Error(String); @@ -942,7 +934,7 @@ impl std::convert::From for Error { impl std::string::ToString for Error { fn to_string(&self) -> String { - self.0.to_string() + self.0.to_string() } } @@ -972,8 +964,6 @@ impl std::ops::DerefMut for Error { } } - - /// Test a model containing an anyOf that starts with a number /// Any of: @@ -981,8 +971,7 @@ impl std::ops::DerefMut for Error { #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct Model12345AnyOfObject(Box); -impl validator::Validate for Model12345AnyOfObject -{ +impl validator::Validate for Model12345AnyOfObject { fn validate(&self) -> std::result::Result<(), validator::ValidationErrors> { std::result::Result::Ok(()) } @@ -1005,30 +994,18 @@ impl PartialEq for Model12345AnyOfObject { } } - - - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct MultigetGet201Response { #[serde(rename = "foo")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub foo: Option, - } - impl MultigetGet201Response { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> MultigetGet201Response { - MultigetGet201Response { - foo: None, - } + MultigetGet201Response { foo: None } } } @@ -1037,16 +1014,10 @@ impl MultigetGet201Response { /// Should be implemented in a serde serializer impl std::string::ToString for MultigetGet201Response { fn to_string(&self) -> String { - let params: Vec> = vec![ - - self.foo.as_ref().map(|foo| { - [ - "foo".to_string(), - foo.to_string(), - ].join(",") - }), - - ]; + let params: Vec> = vec![self + .foo + .as_ref() + .map(|foo| ["foo".to_string(), foo.to_string()].join(","))]; params.into_iter().flatten().collect::>().join(",") } @@ -1075,15 +1046,25 @@ impl std::str::FromStr for MultigetGet201Response { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing MultigetGet201Response".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing MultigetGet201Response".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "foo" => intermediate_rep.foo.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing MultigetGet201Response".to_string()) + "foo" => intermediate_rep.foo.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing MultigetGet201Response".to_string(), + ) + } } } @@ -1104,13 +1085,16 @@ impl std::str::FromStr for MultigetGet201Response { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for MultigetGet201Response - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for MultigetGet201Response - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -1121,24 +1105,25 @@ impl std::convert::TryFrom for header::IntoHeaderValue std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into MultigetGet201Response - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into MultigetGet201Response - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - #[derive(Debug, Clone, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct MyId(i32); @@ -1174,8 +1159,6 @@ impl std::ops::DerefMut for MyId { } } - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct MyIdList(Vec); @@ -1199,7 +1182,7 @@ impl std::convert::From for Vec { } impl std::iter::FromIterator for MyIdList { - fn from_iter>(u: U) -> Self { + fn from_iter>(u: U) -> Self { MyIdList(Vec::::from_iter(u)) } } @@ -1249,7 +1232,10 @@ impl std::ops::DerefMut for MyIdList { /// Should be implemented in a serde serializer impl std::string::ToString for MyIdList { fn to_string(&self) -> String { - self.iter().map(|x| x.to_string()).collect::>().join(",") + self.iter() + .map(|x| x.to_string()) + .collect::>() + .join(",") } } @@ -1261,28 +1247,29 @@ impl std::str::FromStr for MyIdList { fn from_str(s: &str) -> std::result::Result { let mut items = vec![]; - for item in s.split(',') - { + for item in s.split(',') { items.push(item.parse()?); } std::result::Result::Ok(MyIdList(items)) } } - // Methods for converting between header::IntoHeaderValue and HeaderValue #[cfg(feature = "server")] impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for MyIdList - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for MyIdList - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -1293,27 +1280,25 @@ impl std::convert::TryFrom for header::IntoHeaderValue { fn try_from(hdr_value: HeaderValue) -> std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into MyIdList - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into MyIdList - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct NullableTest { @@ -1323,54 +1308,46 @@ pub struct NullableTest { #[serde(rename = "nullableWithNullDefault")] #[serde(deserialize_with = "deserialize_optional_nullable")] #[serde(default = "default_optional_nullable")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub nullable_with_null_default: Option>, #[serde(rename = "nullableWithPresentDefault")] #[serde(deserialize_with = "deserialize_optional_nullable")] #[serde(default = "default_optional_nullable")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub nullable_with_present_default: Option>, #[serde(rename = "nullableWithNoDefault")] #[serde(deserialize_with = "deserialize_optional_nullable")] #[serde(default = "default_optional_nullable")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub nullable_with_no_default: Option>, #[serde(rename = "nullableArray")] #[serde(deserialize_with = "deserialize_optional_nullable")] #[serde(default = "default_optional_nullable")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub nullable_array: Option>>, #[serde(rename = "min_item_test")] - #[validate( - length(min = 1), - )] - #[serde(skip_serializing_if="Option::is_none")] + #[validate(length(min = 1))] + #[serde(skip_serializing_if = "Option::is_none")] pub min_item_test: Option>, #[serde(rename = "max_item_test")] - #[validate( - length(max = 2), - )] - #[serde(skip_serializing_if="Option::is_none")] + #[validate(length(max = 2))] + #[serde(skip_serializing_if = "Option::is_none")] pub max_item_test: Option>, #[serde(rename = "min_max_item_test")] - #[validate( - length(min = 1, max = 3), - )] - #[serde(skip_serializing_if="Option::is_none")] + #[validate(length(min = 1, max = 3))] + #[serde(skip_serializing_if = "Option::is_none")] pub min_max_item_test: Option>, - } - impl NullableTest { #[allow(clippy::new_without_default, clippy::too_many_arguments)] - pub fn new(nullable: Nullable, ) -> NullableTest { + pub fn new(nullable: Nullable) -> NullableTest { NullableTest { nullable, nullable_with_null_default: None, @@ -1390,66 +1367,90 @@ impl NullableTest { impl std::string::ToString for NullableTest { fn to_string(&self) -> String { let params: Vec> = vec![ - Some("nullable".to_string()), - Some(self.nullable.as_ref().map_or("null".to_string(), |x| x.to_string())), - - - self.nullable_with_null_default.as_ref().map(|nullable_with_null_default| { - [ - "nullableWithNullDefault".to_string(), - nullable_with_null_default.as_ref().map_or("null".to_string(), |x| x.to_string()), - ].join(",") - }), - - - self.nullable_with_present_default.as_ref().map(|nullable_with_present_default| { - [ - "nullableWithPresentDefault".to_string(), - nullable_with_present_default.as_ref().map_or("null".to_string(), |x| x.to_string()), - ].join(",") - }), - - - self.nullable_with_no_default.as_ref().map(|nullable_with_no_default| { - [ - "nullableWithNoDefault".to_string(), - nullable_with_no_default.as_ref().map_or("null".to_string(), |x| x.to_string()), - ].join(",") - }), - - + Some( + self.nullable + .as_ref() + .map_or("null".to_string(), |x| x.to_string()), + ), + self.nullable_with_null_default + .as_ref() + .map(|nullable_with_null_default| { + [ + "nullableWithNullDefault".to_string(), + nullable_with_null_default + .as_ref() + .map_or("null".to_string(), |x| x.to_string()), + ] + .join(",") + }), + self.nullable_with_present_default + .as_ref() + .map(|nullable_with_present_default| { + [ + "nullableWithPresentDefault".to_string(), + nullable_with_present_default + .as_ref() + .map_or("null".to_string(), |x| x.to_string()), + ] + .join(",") + }), + self.nullable_with_no_default + .as_ref() + .map(|nullable_with_no_default| { + [ + "nullableWithNoDefault".to_string(), + nullable_with_no_default + .as_ref() + .map_or("null".to_string(), |x| x.to_string()), + ] + .join(",") + }), self.nullable_array.as_ref().map(|nullable_array| { [ "nullableArray".to_string(), - nullable_array.as_ref().map_or("null".to_string(), |x| x.iter().map(|x| x.to_string()).collect::>().join(",")), - ].join(",") + nullable_array.as_ref().map_or("null".to_string(), |x| { + x.iter() + .map(|x| x.to_string()) + .collect::>() + .join(",") + }), + ] + .join(",") }), - - self.min_item_test.as_ref().map(|min_item_test| { [ "min_item_test".to_string(), - min_item_test.iter().map(|x| x.to_string()).collect::>().join(","), - ].join(",") + min_item_test + .iter() + .map(|x| x.to_string()) + .collect::>() + .join(","), + ] + .join(",") }), - - self.max_item_test.as_ref().map(|max_item_test| { [ "max_item_test".to_string(), - max_item_test.iter().map(|x| x.to_string()).collect::>().join(","), - ].join(",") + max_item_test + .iter() + .map(|x| x.to_string()) + .collect::>() + .join(","), + ] + .join(",") }), - - self.min_max_item_test.as_ref().map(|min_max_item_test| { [ "min_max_item_test".to_string(), - min_max_item_test.iter().map(|x| x.to_string()).collect::>().join(","), - ].join(",") + min_max_item_test + .iter() + .map(|x| x.to_string()) + .collect::>() + .join(","), + ] + .join(",") }), - ]; params.into_iter().flatten().collect::>().join(",") @@ -1486,21 +1487,61 @@ impl std::str::FromStr for NullableTest { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing NullableTest".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing NullableTest".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { - "nullable" => return std::result::Result::Err("Parsing a nullable type in this style is not supported in NullableTest".to_string()), - "nullableWithNullDefault" => return std::result::Result::Err("Parsing a nullable type in this style is not supported in NullableTest".to_string()), - "nullableWithPresentDefault" => return std::result::Result::Err("Parsing a nullable type in this style is not supported in NullableTest".to_string()), - "nullableWithNoDefault" => return std::result::Result::Err("Parsing a nullable type in this style is not supported in NullableTest".to_string()), - "nullableArray" => return std::result::Result::Err("Parsing a container in this style is not supported in NullableTest".to_string()), - "min_item_test" => return std::result::Result::Err("Parsing a container in this style is not supported in NullableTest".to_string()), - "max_item_test" => return std::result::Result::Err("Parsing a container in this style is not supported in NullableTest".to_string()), - "min_max_item_test" => return std::result::Result::Err("Parsing a container in this style is not supported in NullableTest".to_string()), - _ => return std::result::Result::Err("Unexpected key while parsing NullableTest".to_string()) + "nullable" => return std::result::Result::Err( + "Parsing a nullable type in this style is not supported in NullableTest" + .to_string(), + ), + "nullableWithNullDefault" => return std::result::Result::Err( + "Parsing a nullable type in this style is not supported in NullableTest" + .to_string(), + ), + "nullableWithPresentDefault" => return std::result::Result::Err( + "Parsing a nullable type in this style is not supported in NullableTest" + .to_string(), + ), + "nullableWithNoDefault" => return std::result::Result::Err( + "Parsing a nullable type in this style is not supported in NullableTest" + .to_string(), + ), + "nullableArray" => { + return std::result::Result::Err( + "Parsing a container in this style is not supported in NullableTest" + .to_string(), + ) + } + "min_item_test" => { + return std::result::Result::Err( + "Parsing a container in this style is not supported in NullableTest" + .to_string(), + ) + } + "max_item_test" => { + return std::result::Result::Err( + "Parsing a container in this style is not supported in NullableTest" + .to_string(), + ) + } + "min_max_item_test" => { + return std::result::Result::Err( + "Parsing a container in this style is not supported in NullableTest" + .to_string(), + ) + } + _ => { + return std::result::Result::Err( + "Unexpected key while parsing NullableTest".to_string(), + ) + } } } @@ -1510,11 +1551,21 @@ impl std::str::FromStr for NullableTest { // Use the intermediate representation to return the struct std::result::Result::Ok(NullableTest { - nullable: std::result::Result::Err("Nullable types not supported in NullableTest".to_string())?, - nullable_with_null_default: std::result::Result::Err("Nullable types not supported in NullableTest".to_string())?, - nullable_with_present_default: std::result::Result::Err("Nullable types not supported in NullableTest".to_string())?, - nullable_with_no_default: std::result::Result::Err("Nullable types not supported in NullableTest".to_string())?, - nullable_array: std::result::Result::Err("Nullable types not supported in NullableTest".to_string())?, + nullable: std::result::Result::Err( + "Nullable types not supported in NullableTest".to_string(), + )?, + nullable_with_null_default: std::result::Result::Err( + "Nullable types not supported in NullableTest".to_string(), + )?, + nullable_with_present_default: std::result::Result::Err( + "Nullable types not supported in NullableTest".to_string(), + )?, + nullable_with_no_default: std::result::Result::Err( + "Nullable types not supported in NullableTest".to_string(), + )?, + nullable_array: std::result::Result::Err( + "Nullable types not supported in NullableTest".to_string(), + )?, min_item_test: intermediate_rep.min_item_test.into_iter().next(), max_item_test: intermediate_rep.max_item_test.into_iter().next(), min_max_item_test: intermediate_rep.min_max_item_test.into_iter().next(), @@ -1528,13 +1579,16 @@ impl std::str::FromStr for NullableTest { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for NullableTest - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for NullableTest - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -1545,27 +1599,25 @@ impl std::convert::TryFrom for header::IntoHeaderValue std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into NullableTest - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into NullableTest - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct ObjectHeader { @@ -1573,15 +1625,13 @@ pub struct ObjectHeader { pub required_object_header: bool, #[serde(rename = "optionalObjectHeader")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub optional_object_header: Option, - } - impl ObjectHeader { #[allow(clippy::new_without_default, clippy::too_many_arguments)] - pub fn new(required_object_header: bool, ) -> ObjectHeader { + pub fn new(required_object_header: bool) -> ObjectHeader { ObjectHeader { required_object_header, optional_object_header: None, @@ -1595,18 +1645,17 @@ impl ObjectHeader { impl std::string::ToString for ObjectHeader { fn to_string(&self) -> String { let params: Vec> = vec![ - Some("requiredObjectHeader".to_string()), Some(self.required_object_header.to_string()), - - - self.optional_object_header.as_ref().map(|optional_object_header| { - [ - "optionalObjectHeader".to_string(), - optional_object_header.to_string(), - ].join(",") - }), - + self.optional_object_header + .as_ref() + .map(|optional_object_header| { + [ + "optionalObjectHeader".to_string(), + optional_object_header.to_string(), + ] + .join(",") + }), ]; params.into_iter().flatten().collect::>().join(",") @@ -1637,17 +1686,29 @@ impl std::str::FromStr for ObjectHeader { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing ObjectHeader".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing ObjectHeader".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "requiredObjectHeader" => intermediate_rep.required_object_header.push(::from_str(val).map_err(|x| x.to_string())?), + "requiredObjectHeader" => intermediate_rep.required_object_header.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "optionalObjectHeader" => intermediate_rep.optional_object_header.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing ObjectHeader".to_string()) + "optionalObjectHeader" => intermediate_rep.optional_object_header.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing ObjectHeader".to_string(), + ) + } } } @@ -1657,7 +1718,11 @@ impl std::str::FromStr for ObjectHeader { // Use the intermediate representation to return the struct std::result::Result::Ok(ObjectHeader { - required_object_header: intermediate_rep.required_object_header.into_iter().next().ok_or_else(|| "requiredObjectHeader missing in ObjectHeader".to_string())?, + required_object_header: intermediate_rep + .required_object_header + .into_iter() + .next() + .ok_or_else(|| "requiredObjectHeader missing in ObjectHeader".to_string())?, optional_object_header: intermediate_rep.optional_object_header.into_iter().next(), }) } @@ -1669,13 +1734,16 @@ impl std::str::FromStr for ObjectHeader { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for ObjectHeader - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for ObjectHeader - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -1686,27 +1754,25 @@ impl std::convert::TryFrom for header::IntoHeaderValue std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into ObjectHeader - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into ObjectHeader - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct ObjectParam { @@ -1714,15 +1780,13 @@ pub struct ObjectParam { pub required_param: bool, #[serde(rename = "optionalParam")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub optional_param: Option, - } - impl ObjectParam { #[allow(clippy::new_without_default, clippy::too_many_arguments)] - pub fn new(required_param: bool, ) -> ObjectParam { + pub fn new(required_param: bool) -> ObjectParam { ObjectParam { required_param, optional_param: None, @@ -1736,18 +1800,11 @@ impl ObjectParam { impl std::string::ToString for ObjectParam { fn to_string(&self) -> String { let params: Vec> = vec![ - Some("requiredParam".to_string()), Some(self.required_param.to_string()), - - self.optional_param.as_ref().map(|optional_param| { - [ - "optionalParam".to_string(), - optional_param.to_string(), - ].join(",") + ["optionalParam".to_string(), optional_param.to_string()].join(",") }), - ]; params.into_iter().flatten().collect::>().join(",") @@ -1778,17 +1835,29 @@ impl std::str::FromStr for ObjectParam { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing ObjectParam".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing ObjectParam".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "requiredParam" => intermediate_rep.required_param.push(::from_str(val).map_err(|x| x.to_string())?), + "requiredParam" => intermediate_rep.required_param.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "optionalParam" => intermediate_rep.optional_param.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing ObjectParam".to_string()) + "optionalParam" => intermediate_rep.optional_param.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing ObjectParam".to_string(), + ) + } } } @@ -1798,7 +1867,11 @@ impl std::str::FromStr for ObjectParam { // Use the intermediate representation to return the struct std::result::Result::Ok(ObjectParam { - required_param: intermediate_rep.required_param.into_iter().next().ok_or_else(|| "requiredParam missing in ObjectParam".to_string())?, + required_param: intermediate_rep + .required_param + .into_iter() + .next() + .ok_or_else(|| "requiredParam missing in ObjectParam".to_string())?, optional_param: intermediate_rep.optional_param.into_iter().next(), }) } @@ -1810,13 +1883,16 @@ impl std::str::FromStr for ObjectParam { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for ObjectParam - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for ObjectParam - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -1827,27 +1903,25 @@ impl std::convert::TryFrom for header::IntoHeaderValue fn try_from(hdr_value: HeaderValue) -> std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into ObjectParam - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into ObjectParam - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct ObjectUntypedProps { @@ -1858,19 +1932,20 @@ pub struct ObjectUntypedProps { pub required_untyped_nullable: Nullable, #[serde(rename = "not_required_untyped")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub not_required_untyped: Option, #[serde(rename = "not_required_untyped_nullable")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub not_required_untyped_nullable: Option, - } - impl ObjectUntypedProps { #[allow(clippy::new_without_default, clippy::too_many_arguments)] - pub fn new(required_untyped: crate::types::Object, required_untyped_nullable: Nullable, ) -> ObjectUntypedProps { + pub fn new( + required_untyped: crate::types::Object, + required_untyped_nullable: Nullable, + ) -> ObjectUntypedProps { ObjectUntypedProps { required_untyped, required_untyped_nullable, @@ -1926,7 +2001,11 @@ impl std::str::FromStr for ObjectUntypedProps { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing ObjectUntypedProps".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing ObjectUntypedProps".to_string(), + ) + } }; if let Some(key) = key_result { @@ -1949,10 +2028,19 @@ impl std::str::FromStr for ObjectUntypedProps { // Use the intermediate representation to return the struct std::result::Result::Ok(ObjectUntypedProps { - required_untyped: intermediate_rep.required_untyped.into_iter().next().ok_or_else(|| "required_untyped missing in ObjectUntypedProps".to_string())?, - required_untyped_nullable: std::result::Result::Err("Nullable types not supported in ObjectUntypedProps".to_string())?, + required_untyped: intermediate_rep + .required_untyped + .into_iter() + .next() + .ok_or_else(|| "required_untyped missing in ObjectUntypedProps".to_string())?, + required_untyped_nullable: std::result::Result::Err( + "Nullable types not supported in ObjectUntypedProps".to_string(), + )?, not_required_untyped: intermediate_rep.not_required_untyped.into_iter().next(), - not_required_untyped_nullable: intermediate_rep.not_required_untyped_nullable.into_iter().next(), + not_required_untyped_nullable: intermediate_rep + .not_required_untyped_nullable + .into_iter() + .next(), }) } } @@ -1963,13 +2051,16 @@ impl std::str::FromStr for ObjectUntypedProps { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for ObjectUntypedProps - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for ObjectUntypedProps - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -1980,43 +2071,37 @@ impl std::convert::TryFrom for header::IntoHeaderValue std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into ObjectUntypedProps - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into ObjectUntypedProps - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct ObjectWithArrayOfObjects { #[serde(rename = "objectArray")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub object_array: Option>, - } - impl ObjectWithArrayOfObjects { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> ObjectWithArrayOfObjects { - ObjectWithArrayOfObjects { - object_array: None, - } + ObjectWithArrayOfObjects { object_array: None } } } @@ -2025,16 +2110,17 @@ impl ObjectWithArrayOfObjects { /// Should be implemented in a serde serializer impl std::string::ToString for ObjectWithArrayOfObjects { fn to_string(&self) -> String { - let params: Vec> = vec![ - - self.object_array.as_ref().map(|object_array| { - [ - "objectArray".to_string(), - object_array.iter().map(|x| x.to_string()).collect::>().join(","), - ].join(",") - }), - - ]; + let params: Vec> = vec![self.object_array.as_ref().map(|object_array| { + [ + "objectArray".to_string(), + object_array + .iter() + .map(|x| x.to_string()) + .collect::>() + .join(","), + ] + .join(",") + })]; params.into_iter().flatten().collect::>().join(",") } @@ -2063,7 +2149,11 @@ impl std::str::FromStr for ObjectWithArrayOfObjects { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing ObjectWithArrayOfObjects".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing ObjectWithArrayOfObjects".to_string(), + ) + } }; if let Some(key) = key_result { @@ -2091,13 +2181,16 @@ impl std::str::FromStr for ObjectWithArrayOfObjects { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for ObjectWithArrayOfObjects - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for ObjectWithArrayOfObjects - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -2108,24 +2201,25 @@ impl std::convert::TryFrom for header::IntoHeaderValue std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into ObjectWithArrayOfObjects - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into ObjectWithArrayOfObjects - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - #[derive(Debug, Clone, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct Ok(String); @@ -2144,7 +2238,7 @@ impl std::convert::From for Ok { impl std::string::ToString for Ok { fn to_string(&self) -> String { - self.0.to_string() + self.0.to_string() } } @@ -2174,18 +2268,13 @@ impl std::ops::DerefMut for Ok { } } - - - - /// One of: /// - Vec /// - i32 #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct OneOfGet200Response(Box); -impl validator::Validate for OneOfGet200Response -{ +impl validator::Validate for OneOfGet200Response { fn validate(&self) -> std::result::Result<(), validator::ValidationErrors> { std::result::Result::Ok(()) } @@ -2208,10 +2297,6 @@ impl PartialEq for OneOfGet200Response { } } - - - - #[derive(Debug, Clone, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct OptionalObjectHeader(i32); @@ -2247,8 +2332,6 @@ impl std::ops::DerefMut for OptionalObjectHeader { } } - - #[derive(Debug, Clone, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct RequiredObjectHeader(bool); @@ -2284,8 +2367,6 @@ impl std::ops::DerefMut for RequiredObjectHeader { } } - - #[derive(Debug, Clone, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct Result(String); @@ -2304,7 +2385,7 @@ impl std::convert::From for Result { impl std::string::ToString for Result { fn to_string(&self) -> String { - self.0.to_string() + self.0.to_string() } } @@ -2334,14 +2415,14 @@ impl std::ops::DerefMut for Result { } } - - /// Enumeration of values. /// Since this enum's variants do not hold data, we can easily define them as `#[repr(C)]` /// which helps with FFI. #[allow(non_camel_case_types)] #[repr(C)] -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize)] +#[derive( + Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize, +)] #[cfg_attr(feature = "conversion", derive(frunk_enum_derive::LabelledGenericEnum))] pub enum StringEnum { #[serde(rename = "FOO")] @@ -2371,7 +2452,6 @@ impl std::str::FromStr for StringEnum { } } - #[derive(Debug, Clone, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct StringObject(String); @@ -2390,7 +2470,7 @@ impl std::convert::From for StringObject { impl std::string::ToString for StringObject { fn to_string(&self) -> String { - self.0.to_string() + self.0.to_string() } } @@ -2420,8 +2500,6 @@ impl std::ops::DerefMut for StringObject { } } - - /// Test a model containing a UUID #[derive(Debug, Clone, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] @@ -2458,8 +2536,6 @@ impl std::ops::DerefMut for UuidObject { } } - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct XmlArray(Vec); @@ -2483,7 +2559,7 @@ impl std::convert::From for Vec { } impl std::iter::FromIterator for XmlArray { - fn from_iter>(u: U) -> Self { + fn from_iter>(u: U) -> Self { XmlArray(Vec::::from_iter(u)) } } @@ -2533,7 +2609,10 @@ impl std::ops::DerefMut for XmlArray { /// Should be implemented in a serde serializer impl std::string::ToString for XmlArray { fn to_string(&self) -> String { - self.iter().map(|x| x.to_string()).collect::>().join(",") + self.iter() + .map(|x| x.to_string()) + .collect::>() + .join(",") } } @@ -2545,28 +2624,29 @@ impl std::str::FromStr for XmlArray { fn from_str(s: &str) -> std::result::Result { let mut items = vec![]; - for item in s.split(',') - { + for item in s.split(',') { items.push(item.parse()?); } std::result::Result::Ok(XmlArray(items)) } } - // Methods for converting between header::IntoHeaderValue and HeaderValue #[cfg(feature = "server")] impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for XmlArray - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for XmlArray - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -2577,24 +2657,25 @@ impl std::convert::TryFrom for header::IntoHeaderValue { fn try_from(hdr_value: HeaderValue) -> std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into XmlArray - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into XmlArray - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - #[derive(Debug, Clone, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct XmlInner(String); @@ -2613,7 +2694,7 @@ impl std::convert::From for XmlInner { impl std::string::ToString for XmlInner { fn to_string(&self) -> String { - self.0.to_string() + self.0.to_string() } } @@ -2643,26 +2724,20 @@ impl std::ops::DerefMut for XmlInner { } } - - /// An XML object - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct XmlObject { #[serde(rename = "innerString")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub inner_string: Option, #[serde(rename = "other_inner_rename")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub other_inner_rename: Option, - } - impl XmlObject { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> XmlObject { @@ -2679,22 +2754,16 @@ impl XmlObject { impl std::string::ToString for XmlObject { fn to_string(&self) -> String { let params: Vec> = vec![ - self.inner_string.as_ref().map(|inner_string| { - [ - "innerString".to_string(), - inner_string.to_string(), - ].join(",") + ["innerString".to_string(), inner_string.to_string()].join(",") }), - - self.other_inner_rename.as_ref().map(|other_inner_rename| { [ "other_inner_rename".to_string(), other_inner_rename.to_string(), - ].join(",") + ] + .join(",") }), - ]; params.into_iter().flatten().collect::>().join(",") @@ -2725,17 +2794,29 @@ impl std::str::FromStr for XmlObject { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing XmlObject".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing XmlObject".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "innerString" => intermediate_rep.inner_string.push(::from_str(val).map_err(|x| x.to_string())?), + "innerString" => intermediate_rep.inner_string.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "other_inner_rename" => intermediate_rep.other_inner_rename.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing XmlObject".to_string()) + "other_inner_rename" => intermediate_rep.other_inner_rename.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing XmlObject".to_string(), + ) + } } } @@ -2757,13 +2838,16 @@ impl std::str::FromStr for XmlObject { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for XmlObject - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for XmlObject - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -2774,20 +2858,21 @@ impl std::convert::TryFrom for header::IntoHeaderValue { fn try_from(hdr_value: HeaderValue) -> std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into XmlObject - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into XmlObject - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - diff --git a/samples/server/petstore/rust-axum/output/openapi-v3/src/server/mod.rs b/samples/server/petstore/rust-axum/output/openapi-v3/src/server/mod.rs index eea66d5a3dd..b471568f253 100644 --- a/samples/server/petstore/rust-axum/output/openapi-v3/src/server/mod.rs +++ b/samples/server/petstore/rust-axum/output/openapi-v3/src/server/mod.rs @@ -12,33 +12,15 @@ use crate::{header, types::*}; #[allow(unused_imports)] use crate::models; -use crate::{Api, - AnyOfGetResponse, - CallbackWithHeaderPostResponse, - ComplexQueryParamGetResponse, - EnumInPathPathParamGetResponse, - JsonComplexQueryParamGetResponse, - MandatoryRequestHeaderGetResponse, - MergePatchJsonGetResponse, - MultigetGetResponse, - MultipleAuthSchemeGetResponse, - OneOfGetResponse, - OverrideServerGetResponse, - ParamgetGetResponse, - ReadonlyAuthSchemeGetResponse, - RegisterCallbackPostResponse, - RequiredOctetStreamPutResponse, - ResponsesWithHeadersGetResponse, - Rfc7807GetResponse, - UntypedPropertyGetResponse, - UuidGetResponse, - XmlExtraPostResponse, - XmlOtherPostResponse, - XmlOtherPutResponse, - XmlPostResponse, - XmlPutResponse, - CreateRepoResponse, - GetRepoInfoResponse +use crate::{ + AnyOfGetResponse, Api, CallbackWithHeaderPostResponse, ComplexQueryParamGetResponse, + CreateRepoResponse, EnumInPathPathParamGetResponse, GetRepoInfoResponse, + JsonComplexQueryParamGetResponse, MandatoryRequestHeaderGetResponse, MergePatchJsonGetResponse, + MultigetGetResponse, MultipleAuthSchemeGetResponse, OneOfGetResponse, + OverrideServerGetResponse, ParamgetGetResponse, ReadonlyAuthSchemeGetResponse, + RegisterCallbackPostResponse, RequiredOctetStreamPutResponse, ResponsesWithHeadersGetResponse, + Rfc7807GetResponse, UntypedPropertyGetResponse, UuidGetResponse, XmlExtraPostResponse, + XmlOtherPostResponse, XmlOtherPutResponse, XmlPostResponse, XmlPutResponse, }; /// Setup API Server. @@ -49,893 +31,801 @@ where { // build our application with a route Router::new() - .route("/any-of", - get(any_of_get::) + .route("/any-of", get(any_of_get::)) + .route( + "/callback-with-header", + post(callback_with_header_post::), ) - .route("/callback-with-header", - post(callback_with_header_post::) + .route("/complex-query-param", get(complex_query_param_get::)) + .route( + "/enum_in_path/:path_param", + get(enum_in_path_path_param_get::), ) - .route("/complex-query-param", - get(complex_query_param_get::) + .route( + "/json-complex-query-param", + get(json_complex_query_param_get::), ) - .route("/enum_in_path/:path_param", - get(enum_in_path_path_param_get::) + .route( + "/mandatory-request-header", + get(mandatory_request_header_get::), ) - .route("/json-complex-query-param", - get(json_complex_query_param_get::) + .route("/merge-patch-json", get(merge_patch_json_get::)) + .route("/multiget", get(multiget_get::)) + .route( + "/multiple_auth_scheme", + get(multiple_auth_scheme_get::), ) - .route("/mandatory-request-header", - get(mandatory_request_header_get::) + .route("/one-of", get(one_of_get::)) + .route("/override-server", get(override_server_get::)) + .route("/paramget", get(paramget_get::)) + .route( + "/readonly_auth_scheme", + get(readonly_auth_scheme_get::), ) - .route("/merge-patch-json", - get(merge_patch_json_get::) + .route("/register-callback", post(register_callback_post::)) + .route("/repos", post(create_repo::)) + .route( + "/repos/:repo_id", + get(get_repo_info::).get(get_repo_info::), ) - .route("/multiget", - get(multiget_get::) + .route( + "/required_octet_stream", + put(required_octet_stream_put::), ) - .route("/multiple_auth_scheme", - get(multiple_auth_scheme_get::) + .route( + "/responses_with_headers", + get(responses_with_headers_get::), ) - .route("/one-of", - get(one_of_get::) - ) - .route("/override-server", - get(override_server_get::) - ) - .route("/paramget", - get(paramget_get::) - ) - .route("/readonly_auth_scheme", - get(readonly_auth_scheme_get::) - ) - .route("/register-callback", - post(register_callback_post::) - ) - .route("/repos", - post(create_repo::) - ) - .route("/repos/:repo_id", - get(get_repo_info::).get(get_repo_info::) - ) - .route("/required_octet_stream", - put(required_octet_stream_put::) - ) - .route("/responses_with_headers", - get(responses_with_headers_get::) - ) - .route("/rfc7807", - get(rfc7807_get::) - ) - .route("/untyped_property", - get(untyped_property_get::) - ) - .route("/uuid", - get(uuid_get::) - ) - .route("/xml", - post(xml_post::).put(xml_put::) - ) - .route("/xml_extra", - post(xml_extra_post::) - ) - .route("/xml_other", - post(xml_other_post::).put(xml_other_put::) + .route("/rfc7807", get(rfc7807_get::)) + .route("/untyped_property", get(untyped_property_get::)) + .route("/uuid", get(uuid_get::)) + .route("/xml", post(xml_post::).put(xml_put::)) + .route("/xml_extra", post(xml_extra_post::)) + .route( + "/xml_other", + post(xml_other_post::).put(xml_other_put::), ) .with_state(api_impl) } - #[tracing::instrument(skip_all)] fn any_of_get_validation( - query_params: models::AnyOfGetQueryParams, -) -> std::result::Result<( - models::AnyOfGetQueryParams, -), ValidationErrors> -{ - query_params.validate()?; + query_params: models::AnyOfGetQueryParams, +) -> std::result::Result<(models::AnyOfGetQueryParams,), ValidationErrors> { + query_params.validate()?; -Ok(( - query_params, -)) + Ok((query_params,)) } /// AnyOfGet - GET /any-of #[tracing::instrument(skip_all)] async fn any_of_get( - method: Method, - host: Host, - cookies: CookieJar, - Query(query_params): Query, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + Query(query_params): Query, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + let validation = any_of_get_validation(query_params); - let validation = - any_of_get_validation( - query_params, - ) - ; - - let Ok(( - query_params, - )) = validation else { - return Response::builder() + let Ok((query_params,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().any_of_get( - method, - host, - cookies, - query_params, - ).await; + let result = api_impl + .as_ref() + .any_of_get(method, host, cookies, query_params) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - AnyOfGetResponse::Status200_Success - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + AnyOfGetResponse::Status200_Success(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("application/json").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("application/json").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = tokio::task::spawn_blocking(move || { + serde_json::to_vec(&body).map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) + }) + .await + .unwrap()?; + response.body(Body::from(body_content)) + } + AnyOfGetResponse::Status201_AlternateSuccess(body) => { + let mut response = response.status(201); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("application/json").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let body_content = tokio::task::spawn_blocking(move || - serde_json::to_vec(&body).map_err(|e| { - error!(error = ?e); - StatusCode::INTERNAL_SERVER_ERROR - })).await.unwrap()?; - response.body(Body::from(body_content)) - }, - AnyOfGetResponse::Status201_AlternateSuccess - (body) - => { + let body_content = tokio::task::spawn_blocking(move || { + serde_json::to_vec(&body).map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) + }) + .await + .unwrap()?; + response.body(Body::from(body_content)) + } + AnyOfGetResponse::Status202_AnyOfSuccess(body) => { + let mut response = response.status(202); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("application/json").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(201); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("application/json").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = tokio::task::spawn_blocking(move || { + serde_json::to_vec(&body).map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) + }) + .await + .unwrap()?; + response.body(Body::from(body_content)) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = tokio::task::spawn_blocking(move || - serde_json::to_vec(&body).map_err(|e| { - error!(error = ?e); - StatusCode::INTERNAL_SERVER_ERROR - })).await.unwrap()?; - response.body(Body::from(body_content)) - }, - AnyOfGetResponse::Status202_AnyOfSuccess - (body) - => { - - let mut response = response.status(202); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("application/json").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } - - let body_content = tokio::task::spawn_blocking(move || - serde_json::to_vec(&body).map_err(|e| { - error!(error = ?e); - StatusCode::INTERNAL_SERVER_ERROR - })).await.unwrap()?; - response.body(Body::from(body_content)) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] fn callback_with_header_post_validation( - query_params: models::CallbackWithHeaderPostQueryParams, -) -> std::result::Result<( - models::CallbackWithHeaderPostQueryParams, -), ValidationErrors> -{ - query_params.validate()?; + query_params: models::CallbackWithHeaderPostQueryParams, +) -> std::result::Result<(models::CallbackWithHeaderPostQueryParams,), ValidationErrors> { + query_params.validate()?; -Ok(( - query_params, -)) + Ok((query_params,)) } /// CallbackWithHeaderPost - POST /callback-with-header #[tracing::instrument(skip_all)] async fn callback_with_header_post( - method: Method, - host: Host, - cookies: CookieJar, - Query(query_params): Query, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + Query(query_params): Query, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + let validation = callback_with_header_post_validation(query_params); - let validation = - callback_with_header_post_validation( - query_params, - ) - ; - - let Ok(( - query_params, - )) = validation else { - return Response::builder() + let Ok((query_params,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().callback_with_header_post( - method, - host, - cookies, - query_params, - ).await; + let result = api_impl + .as_ref() + .callback_with_header_post(method, host, cookies, query_params) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - CallbackWithHeaderPostResponse::Status204_OK - => { + let resp = match result { + Ok(rsp) => match rsp { + CallbackWithHeaderPostResponse::Status204_OK => { + let mut response = response.status(204); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(204); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] fn complex_query_param_get_validation( - query_params: models::ComplexQueryParamGetQueryParams, -) -> std::result::Result<( - models::ComplexQueryParamGetQueryParams, -), ValidationErrors> -{ - query_params.validate()?; + query_params: models::ComplexQueryParamGetQueryParams, +) -> std::result::Result<(models::ComplexQueryParamGetQueryParams,), ValidationErrors> { + query_params.validate()?; -Ok(( - query_params, -)) + Ok((query_params,)) } /// ComplexQueryParamGet - GET /complex-query-param #[tracing::instrument(skip_all)] async fn complex_query_param_get( - method: Method, - host: Host, - cookies: CookieJar, - Query(query_params): Query, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + Query(query_params): Query, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + let validation = complex_query_param_get_validation(query_params); - let validation = - complex_query_param_get_validation( - query_params, - ) - ; - - let Ok(( - query_params, - )) = validation else { - return Response::builder() + let Ok((query_params,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().complex_query_param_get( - method, - host, - cookies, - query_params, - ).await; + let result = api_impl + .as_ref() + .complex_query_param_get(method, host, cookies, query_params) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - ComplexQueryParamGetResponse::Status200_Success - => { + let resp = match result { + Ok(rsp) => match rsp { + ComplexQueryParamGetResponse::Status200_Success => { + let mut response = response.status(200); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(200); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] fn enum_in_path_path_param_get_validation( - path_params: models::EnumInPathPathParamGetPathParams, -) -> std::result::Result<( - models::EnumInPathPathParamGetPathParams, -), ValidationErrors> -{ - path_params.validate()?; + path_params: models::EnumInPathPathParamGetPathParams, +) -> std::result::Result<(models::EnumInPathPathParamGetPathParams,), ValidationErrors> { + path_params.validate()?; -Ok(( - path_params, -)) + Ok((path_params,)) } /// EnumInPathPathParamGet - GET /enum_in_path/{path_param} #[tracing::instrument(skip_all)] async fn enum_in_path_path_param_get( - method: Method, - host: Host, - cookies: CookieJar, - Path(path_params): Path, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + Path(path_params): Path, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + let validation = enum_in_path_path_param_get_validation(path_params); - let validation = - enum_in_path_path_param_get_validation( - path_params, - ) - ; - - let Ok(( - path_params, - )) = validation else { - return Response::builder() + let Ok((path_params,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().enum_in_path_path_param_get( - method, - host, - cookies, - path_params, - ).await; + let result = api_impl + .as_ref() + .enum_in_path_path_param_get(method, host, cookies, path_params) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - EnumInPathPathParamGetResponse::Status200_Success - => { + let resp = match result { + Ok(rsp) => match rsp { + EnumInPathPathParamGetResponse::Status200_Success => { + let mut response = response.status(200); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(200); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] fn json_complex_query_param_get_validation( - query_params: models::JsonComplexQueryParamGetQueryParams, -) -> std::result::Result<( - models::JsonComplexQueryParamGetQueryParams, -), ValidationErrors> -{ - query_params.validate()?; + query_params: models::JsonComplexQueryParamGetQueryParams, +) -> std::result::Result<(models::JsonComplexQueryParamGetQueryParams,), ValidationErrors> { + query_params.validate()?; -Ok(( - query_params, -)) + Ok((query_params,)) } /// JsonComplexQueryParamGet - GET /json-complex-query-param #[tracing::instrument(skip_all)] async fn json_complex_query_param_get( - method: Method, - host: Host, - cookies: CookieJar, - Query(query_params): Query, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + Query(query_params): Query, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + let validation = json_complex_query_param_get_validation(query_params); - let validation = - json_complex_query_param_get_validation( - query_params, - ) - ; - - let Ok(( - query_params, - )) = validation else { - return Response::builder() + let Ok((query_params,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().json_complex_query_param_get( - method, - host, - cookies, - query_params, - ).await; + let result = api_impl + .as_ref() + .json_complex_query_param_get(method, host, cookies, query_params) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - JsonComplexQueryParamGetResponse::Status200_Success - => { + let resp = match result { + Ok(rsp) => match rsp { + JsonComplexQueryParamGetResponse::Status200_Success => { + let mut response = response.status(200); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(200); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] fn mandatory_request_header_get_validation( - header_params: models::MandatoryRequestHeaderGetHeaderParams, -) -> std::result::Result<( - models::MandatoryRequestHeaderGetHeaderParams, -), ValidationErrors> -{ - header_params.validate()?; + header_params: models::MandatoryRequestHeaderGetHeaderParams, +) -> std::result::Result<(models::MandatoryRequestHeaderGetHeaderParams,), ValidationErrors> { + header_params.validate()?; -Ok(( - header_params, -)) + Ok((header_params,)) } /// MandatoryRequestHeaderGet - GET /mandatory-request-header #[tracing::instrument(skip_all)] async fn mandatory_request_header_get( - method: Method, - host: Host, - cookies: CookieJar, - headers: HeaderMap, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + headers: HeaderMap, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { // Header parameters let header_params = { - let header_x_header = headers.get(HeaderName::from_static("x-header")); + let header_x_header = headers.get(HeaderName::from_static("x-header")); - let header_x_header = match header_x_header { - Some(v) => match header::IntoHeaderValue::::try_from((*v).clone()) { - Ok(result) => - result.0, - Err(err) => { - return Response::builder() - .status(StatusCode::BAD_REQUEST) - .body(Body::from(format!("Invalid header X-Header - {}", err))).map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }); + let header_x_header = match header_x_header { + Some(v) => match header::IntoHeaderValue::::try_from((*v).clone()) { + Ok(result) => result.0, + Err(err) => { + return Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Invalid header X-Header - {}", err))) + .map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }); + } + }, + None => { + return Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from("Missing required header X-Header")) + .map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }); + } + }; - }, - }, - None => { - return Response::builder() - .status(StatusCode::BAD_REQUEST) - .body(Body::from("Missing required header X-Header")).map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }); - } - }; + models::MandatoryRequestHeaderGetHeaderParams { + x_header: header_x_header, + } + }; - models::MandatoryRequestHeaderGetHeaderParams { - x_header: header_x_header, - } - }; + let validation = mandatory_request_header_get_validation(header_params); - - let validation = - mandatory_request_header_get_validation( - header_params, - ) - ; - - let Ok(( - header_params, - )) = validation else { - return Response::builder() + let Ok((header_params,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().mandatory_request_header_get( - method, - host, - cookies, - header_params, - ).await; + let result = api_impl + .as_ref() + .mandatory_request_header_get(method, host, cookies, header_params) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - MandatoryRequestHeaderGetResponse::Status200_Success - => { + let resp = match result { + Ok(rsp) => match rsp { + MandatoryRequestHeaderGetResponse::Status200_Success => { + let mut response = response.status(200); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(200); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] -fn merge_patch_json_get_validation( -) -> std::result::Result<( -), ValidationErrors> -{ - -Ok(( -)) +fn merge_patch_json_get_validation() -> std::result::Result<(), ValidationErrors> { + Ok(()) } /// MergePatchJsonGet - GET /merge-patch-json #[tracing::instrument(skip_all)] async fn merge_patch_json_get( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + let validation = merge_patch_json_get_validation(); - let validation = - merge_patch_json_get_validation( - ) - ; - - let Ok(( - )) = validation else { - return Response::builder() + let Ok(()) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().merge_patch_json_get( - method, - host, - cookies, - ).await; + let result = api_impl + .as_ref() + .merge_patch_json_get(method, host, cookies) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - MergePatchJsonGetResponse::Status200_Merge - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + MergePatchJsonGetResponse::Status200_Merge(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("application/merge-patch+json").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("application/merge-patch+json").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = tokio::task::spawn_blocking(move || { + serde_json::to_vec(&body).map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) + }) + .await + .unwrap()?; + response.body(Body::from(body_content)) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = tokio::task::spawn_blocking(move || - serde_json::to_vec(&body).map_err(|e| { - error!(error = ?e); - StatusCode::INTERNAL_SERVER_ERROR - })).await.unwrap()?; - response.body(Body::from(body_content)) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] -fn multiget_get_validation( -) -> std::result::Result<( -), ValidationErrors> -{ - -Ok(( -)) +fn multiget_get_validation() -> std::result::Result<(), ValidationErrors> { + Ok(()) } /// MultigetGet - GET /multiget #[tracing::instrument(skip_all)] async fn multiget_get( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + let validation = multiget_get_validation(); - let validation = - multiget_get_validation( - ) - ; - - let Ok(( - )) = validation else { - return Response::builder() + let Ok(()) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().multiget_get( - method, - host, - cookies, - ).await; + let result = api_impl.as_ref().multiget_get(method, host, cookies).await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - MultigetGetResponse::Status200_JSONRsp - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + MultigetGetResponse::Status200_JSONRsp(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("application/json").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("application/json").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = tokio::task::spawn_blocking(move || { + serde_json::to_vec(&body).map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) + }) + .await + .unwrap()?; + response.body(Body::from(body_content)) + } + MultigetGetResponse::Status201_XMLRsp(body) => { + let mut response = response.status(201); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("text/plain").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let body_content = tokio::task::spawn_blocking(move || - serde_json::to_vec(&body).map_err(|e| { - error!(error = ?e); - StatusCode::INTERNAL_SERVER_ERROR - })).await.unwrap()?; - response.body(Body::from(body_content)) - }, - MultigetGetResponse::Status201_XMLRsp - (body) - => { + let body_content = body; + response.body(Body::from(body_content)) + } + MultigetGetResponse::Status202_OctetRsp(body) => { + let mut response = response.status(202); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("application/octet-stream").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(201); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("text/plain").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = body.0; + response.body(Body::from(body_content)) + } + MultigetGetResponse::Status203_StringRsp(body) => { + let mut response = response.status(203); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("text/plain").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let body_content = body; - response.body(Body::from(body_content)) - }, - MultigetGetResponse::Status202_OctetRsp - (body) - => { + let body_content = body; + response.body(Body::from(body_content)) + } + MultigetGetResponse::Status204_DuplicateResponseLongText(body) => { + let mut response = response.status(204); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("application/json").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(202); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("application/octet-stream").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = tokio::task::spawn_blocking(move || { + serde_json::to_vec(&body).map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) + }) + .await + .unwrap()?; + response.body(Body::from(body_content)) + } + MultigetGetResponse::Status205_DuplicateResponseLongText(body) => { + let mut response = response.status(205); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("application/json").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let body_content = body.0; - response.body(Body::from(body_content)) - }, - MultigetGetResponse::Status203_StringRsp - (body) - => { + let body_content = tokio::task::spawn_blocking(move || { + serde_json::to_vec(&body).map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) + }) + .await + .unwrap()?; + response.body(Body::from(body_content)) + } + MultigetGetResponse::Status206_DuplicateResponseLongText(body) => { + let mut response = response.status(206); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("application/json").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(203); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("text/plain").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = tokio::task::spawn_blocking(move || { + serde_json::to_vec(&body).map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) + }) + .await + .unwrap()?; + response.body(Body::from(body_content)) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = body; - response.body(Body::from(body_content)) - }, - MultigetGetResponse::Status204_DuplicateResponseLongText - (body) - => { - - let mut response = response.status(204); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("application/json").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } - - let body_content = tokio::task::spawn_blocking(move || - serde_json::to_vec(&body).map_err(|e| { - error!(error = ?e); - StatusCode::INTERNAL_SERVER_ERROR - })).await.unwrap()?; - response.body(Body::from(body_content)) - }, - MultigetGetResponse::Status205_DuplicateResponseLongText - (body) - => { - - let mut response = response.status(205); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("application/json").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } - - let body_content = tokio::task::spawn_blocking(move || - serde_json::to_vec(&body).map_err(|e| { - error!(error = ?e); - StatusCode::INTERNAL_SERVER_ERROR - })).await.unwrap()?; - response.body(Body::from(body_content)) - }, - MultigetGetResponse::Status206_DuplicateResponseLongText - (body) - => { - - let mut response = response.status(206); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("application/json").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } - - let body_content = tokio::task::spawn_blocking(move || - serde_json::to_vec(&body).map_err(|e| { - error!(error = ?e); - StatusCode::INTERNAL_SERVER_ERROR - })).await.unwrap()?; - response.body(Body::from(body_content)) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] -fn multiple_auth_scheme_get_validation( -) -> std::result::Result<( -), ValidationErrors> -{ - -Ok(( -)) +fn multiple_auth_scheme_get_validation() -> std::result::Result<(), ValidationErrors> { + Ok(()) } /// MultipleAuthSchemeGet - GET /multiple_auth_scheme #[tracing::instrument(skip_all)] async fn multiple_auth_scheme_get( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + let validation = multiple_auth_scheme_get_validation(); - let validation = - multiple_auth_scheme_get_validation( - ) - ; - - let Ok(( - )) = validation else { - return Response::builder() + let Ok(()) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().multiple_auth_scheme_get( - method, - host, - cookies, - ).await; + let result = api_impl + .as_ref() + .multiple_auth_scheme_get(method, host, cookies) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { + let resp = match result { Ok(rsp) => match rsp { MultipleAuthSchemeGetResponse::Status200_CheckThatLimitingToMultipleRequiredAuthSchemesWorks => { @@ -951,281 +841,245 @@ where }, }; - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] -fn one_of_get_validation( -) -> std::result::Result<( -), ValidationErrors> -{ - -Ok(( -)) +fn one_of_get_validation() -> std::result::Result<(), ValidationErrors> { + Ok(()) } /// OneOfGet - GET /one-of #[tracing::instrument(skip_all)] async fn one_of_get( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + let validation = one_of_get_validation(); - let validation = - one_of_get_validation( - ) - ; - - let Ok(( - )) = validation else { - return Response::builder() + let Ok(()) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().one_of_get( - method, - host, - cookies, - ).await; + let result = api_impl.as_ref().one_of_get(method, host, cookies).await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - OneOfGetResponse::Status200_Success - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + OneOfGetResponse::Status200_Success(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("application/json").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("application/json").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = tokio::task::spawn_blocking(move || { + serde_json::to_vec(&body).map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) + }) + .await + .unwrap()?; + response.body(Body::from(body_content)) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = tokio::task::spawn_blocking(move || - serde_json::to_vec(&body).map_err(|e| { - error!(error = ?e); - StatusCode::INTERNAL_SERVER_ERROR - })).await.unwrap()?; - response.body(Body::from(body_content)) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] -fn override_server_get_validation( -) -> std::result::Result<( -), ValidationErrors> -{ - -Ok(( -)) +fn override_server_get_validation() -> std::result::Result<(), ValidationErrors> { + Ok(()) } /// OverrideServerGet - GET /override-server #[tracing::instrument(skip_all)] async fn override_server_get( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + let validation = override_server_get_validation(); - let validation = - override_server_get_validation( - ) - ; - - let Ok(( - )) = validation else { - return Response::builder() + let Ok(()) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().override_server_get( - method, - host, - cookies, - ).await; + let result = api_impl + .as_ref() + .override_server_get(method, host, cookies) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - OverrideServerGetResponse::Status204_Success - => { + let resp = match result { + Ok(rsp) => match rsp { + OverrideServerGetResponse::Status204_Success => { + let mut response = response.status(204); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(204); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] fn paramget_get_validation( - query_params: models::ParamgetGetQueryParams, -) -> std::result::Result<( - models::ParamgetGetQueryParams, -), ValidationErrors> -{ - query_params.validate()?; + query_params: models::ParamgetGetQueryParams, +) -> std::result::Result<(models::ParamgetGetQueryParams,), ValidationErrors> { + query_params.validate()?; -Ok(( - query_params, -)) + Ok((query_params,)) } /// ParamgetGet - GET /paramget #[tracing::instrument(skip_all)] async fn paramget_get( - method: Method, - host: Host, - cookies: CookieJar, - Query(query_params): Query, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + Query(query_params): Query, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + let validation = paramget_get_validation(query_params); - let validation = - paramget_get_validation( - query_params, - ) - ; - - let Ok(( - query_params, - )) = validation else { - return Response::builder() + let Ok((query_params,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().paramget_get( - method, - host, - cookies, - query_params, - ).await; + let result = api_impl + .as_ref() + .paramget_get(method, host, cookies, query_params) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - ParamgetGetResponse::Status200_JSONRsp - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + ParamgetGetResponse::Status200_JSONRsp(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("application/json").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("application/json").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = tokio::task::spawn_blocking(move || { + serde_json::to_vec(&body).map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) + }) + .await + .unwrap()?; + response.body(Body::from(body_content)) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = tokio::task::spawn_blocking(move || - serde_json::to_vec(&body).map_err(|e| { - error!(error = ?e); - StatusCode::INTERNAL_SERVER_ERROR - })).await.unwrap()?; - response.body(Body::from(body_content)) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] -fn readonly_auth_scheme_get_validation( -) -> std::result::Result<( -), ValidationErrors> -{ - -Ok(( -)) +fn readonly_auth_scheme_get_validation() -> std::result::Result<(), ValidationErrors> { + Ok(()) } /// ReadonlyAuthSchemeGet - GET /readonly_auth_scheme #[tracing::instrument(skip_all)] async fn readonly_auth_scheme_get( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + let validation = readonly_auth_scheme_get_validation(); - let validation = - readonly_auth_scheme_get_validation( - ) - ; - - let Ok(( - )) = validation else { - return Response::builder() + let Ok(()) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().readonly_auth_scheme_get( - method, - host, - cookies, - ).await; + let result = api_impl + .as_ref() + .readonly_auth_scheme_get(method, host, cookies) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { + let resp = match result { Ok(rsp) => match rsp { ReadonlyAuthSchemeGetResponse::Status200_CheckThatLimitingToASingleRequiredAuthSchemeWorks => { @@ -1241,1199 +1095,1008 @@ where }, }; - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] fn register_callback_post_validation( - query_params: models::RegisterCallbackPostQueryParams, -) -> std::result::Result<( - models::RegisterCallbackPostQueryParams, -), ValidationErrors> -{ - query_params.validate()?; + query_params: models::RegisterCallbackPostQueryParams, +) -> std::result::Result<(models::RegisterCallbackPostQueryParams,), ValidationErrors> { + query_params.validate()?; -Ok(( - query_params, -)) + Ok((query_params,)) } /// RegisterCallbackPost - POST /register-callback #[tracing::instrument(skip_all)] async fn register_callback_post( - method: Method, - host: Host, - cookies: CookieJar, - Query(query_params): Query, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + Query(query_params): Query, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + let validation = register_callback_post_validation(query_params); - let validation = - register_callback_post_validation( - query_params, - ) - ; - - let Ok(( - query_params, - )) = validation else { - return Response::builder() + let Ok((query_params,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().register_callback_post( - method, - host, - cookies, - query_params, - ).await; + let result = api_impl + .as_ref() + .register_callback_post(method, host, cookies, query_params) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - RegisterCallbackPostResponse::Status204_OK - => { + let resp = match result { + Ok(rsp) => match rsp { + RegisterCallbackPostResponse::Status204_OK => { + let mut response = response.status(204); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(204); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct RequiredOctetStreamPutBodyValidator<'a> { - body: &'a [u8], - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct RequiredOctetStreamPutBodyValidator<'a> { + body: &'a [u8], +} #[tracing::instrument(skip_all)] fn required_octet_stream_put_validation( - body: Bytes, -) -> std::result::Result<( - Bytes, -), ValidationErrors> -{ - -Ok(( - body, -)) + body: Bytes, +) -> std::result::Result<(Bytes,), ValidationErrors> { + Ok((body,)) } /// RequiredOctetStreamPut - PUT /required_octet_stream #[tracing::instrument(skip_all)] async fn required_octet_stream_put( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - body: Bytes, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + body: Bytes, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + let validation = required_octet_stream_put_validation(body); - let validation = - required_octet_stream_put_validation( - body, - ) - ; - - let Ok(( - body, - )) = validation else { - return Response::builder() + let Ok((body,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().required_octet_stream_put( - method, - host, - cookies, - body, - ).await; + let result = api_impl + .as_ref() + .required_octet_stream_put(method, host, cookies, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - RequiredOctetStreamPutResponse::Status200_OK - => { + let resp = match result { + Ok(rsp) => match rsp { + RequiredOctetStreamPutResponse::Status200_OK => { + let mut response = response.status(200); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(200); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] -fn responses_with_headers_get_validation( -) -> std::result::Result<( -), ValidationErrors> -{ - -Ok(( -)) +fn responses_with_headers_get_validation() -> std::result::Result<(), ValidationErrors> { + Ok(()) } /// ResponsesWithHeadersGet - GET /responses_with_headers #[tracing::instrument(skip_all)] async fn responses_with_headers_get( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + let validation = responses_with_headers_get_validation(); - let validation = - responses_with_headers_get_validation( - ) - ; - - let Ok(( - )) = validation else { - return Response::builder() + let Ok(()) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().responses_with_headers_get( - method, - host, - cookies, - ).await; + let result = api_impl + .as_ref() + .responses_with_headers_get(method, host, cookies) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - ResponsesWithHeadersGetResponse::Status200_Success - { - body, - success_info, - bool_header, - object_header - } - => { - let success_info = match header::IntoHeaderValue(success_info).try_into() { - Ok(val) => val, - Err(e) => { - return Response::builder() + let resp = match result { + Ok(rsp) => match rsp { + ResponsesWithHeadersGetResponse::Status200_Success { + body, + success_info, + bool_header, + object_header, + } => { + let success_info = match header::IntoHeaderValue(success_info).try_into() { + Ok(val) => val, + Err(e) => { + return Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling success_info header - {}", e))).map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }); - } - }; + } + }; - - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - HeaderName::from_static("success-info"), - success_info - ); - } - if let Some(bool_header) = bool_header { - let bool_header = match header::IntoHeaderValue(bool_header).try_into() { - Ok(val) => val, - Err(e) => { - return Response::builder() + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert(HeaderName::from_static("success-info"), success_info); + } + if let Some(bool_header) = bool_header { + let bool_header = match header::IntoHeaderValue(bool_header).try_into() { + Ok(val) => val, + Err(e) => { + return Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling bool_header header - {}", e))).map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }); - } - }; + } + }; - - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - HeaderName::from_static("bool-header"), - bool_header - ); - } - } - if let Some(object_header) = object_header { - let object_header = match header::IntoHeaderValue(object_header).try_into() { - Ok(val) => val, - Err(e) => { - return Response::builder() + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers + .insert(HeaderName::from_static("bool-header"), bool_header); + } + } + if let Some(object_header) = object_header { + let object_header = match header::IntoHeaderValue(object_header).try_into() { + Ok(val) => val, + Err(e) => { + return Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling object_header header - {}", e))).map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }); - } - }; + } + }; - - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - HeaderName::from_static("object-header"), - object_header - ); - } - } + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers + .insert(HeaderName::from_static("object-header"), object_header); + } + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("application/json").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("application/json").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let body_content = tokio::task::spawn_blocking(move || - serde_json::to_vec(&body).map_err(|e| { - error!(error = ?e); - StatusCode::INTERNAL_SERVER_ERROR - })).await.unwrap()?; - response.body(Body::from(body_content)) - }, - ResponsesWithHeadersGetResponse::Status412_PreconditionFailed - { - further_info, - failure_info - } - => { - if let Some(further_info) = further_info { - let further_info = match header::IntoHeaderValue(further_info).try_into() { - Ok(val) => val, - Err(e) => { - return Response::builder() + let body_content = tokio::task::spawn_blocking(move || { + serde_json::to_vec(&body).map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) + }) + .await + .unwrap()?; + response.body(Body::from(body_content)) + } + ResponsesWithHeadersGetResponse::Status412_PreconditionFailed { + further_info, + failure_info, + } => { + if let Some(further_info) = further_info { + let further_info = match header::IntoHeaderValue(further_info).try_into() { + Ok(val) => val, + Err(e) => { + return Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling further_info header - {}", e))).map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }); - } - }; + } + }; - - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - HeaderName::from_static("further-info"), - further_info - ); - } - } - if let Some(failure_info) = failure_info { - let failure_info = match header::IntoHeaderValue(failure_info).try_into() { - Ok(val) => val, - Err(e) => { - return Response::builder() + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers + .insert(HeaderName::from_static("further-info"), further_info); + } + } + if let Some(failure_info) = failure_info { + let failure_info = match header::IntoHeaderValue(failure_info).try_into() { + Ok(val) => val, + Err(e) => { + return Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling failure_info header - {}", e))).map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }); - } - }; + } + }; - - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - HeaderName::from_static("failure-info"), - failure_info - ); - } - } + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers + .insert(HeaderName::from_static("failure-info"), failure_info); + } + } - let mut response = response.status(412); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; + let mut response = response.status(412); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] -fn rfc7807_get_validation( -) -> std::result::Result<( -), ValidationErrors> -{ - -Ok(( -)) +fn rfc7807_get_validation() -> std::result::Result<(), ValidationErrors> { + Ok(()) } /// Rfc7807Get - GET /rfc7807 #[tracing::instrument(skip_all)] async fn rfc7807_get( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + let validation = rfc7807_get_validation(); - let validation = - rfc7807_get_validation( - ) - ; - - let Ok(( - )) = validation else { - return Response::builder() + let Ok(()) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().rfc7807_get( - method, - host, - cookies, - ).await; + let result = api_impl.as_ref().rfc7807_get(method, host, cookies).await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - Rfc7807GetResponse::Status204_OK - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + Rfc7807GetResponse::Status204_OK(body) => { + let mut response = response.status(204); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("application/json").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(204); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("application/json").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = tokio::task::spawn_blocking(move || { + serde_json::to_vec(&body).map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) + }) + .await + .unwrap()?; + response.body(Body::from(body_content)) + } + Rfc7807GetResponse::Status404_NotFound(body) => { + let mut response = response.status(404); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("application/problem+json").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let body_content = tokio::task::spawn_blocking(move || - serde_json::to_vec(&body).map_err(|e| { - error!(error = ?e); - StatusCode::INTERNAL_SERVER_ERROR - })).await.unwrap()?; - response.body(Body::from(body_content)) - }, - Rfc7807GetResponse::Status404_NotFound - (body) - => { + let body_content = tokio::task::spawn_blocking(move || { + serde_json::to_vec(&body).map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) + }) + .await + .unwrap()?; + response.body(Body::from(body_content)) + } + Rfc7807GetResponse::Status406_NotAcceptable(body) => { + let mut response = response.status(406); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("text/plain").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(404); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("application/problem+json").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = body; + response.body(Body::from(body_content)) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = tokio::task::spawn_blocking(move || - serde_json::to_vec(&body).map_err(|e| { - error!(error = ?e); - StatusCode::INTERNAL_SERVER_ERROR - })).await.unwrap()?; - response.body(Body::from(body_content)) - }, - Rfc7807GetResponse::Status406_NotAcceptable - (body) - => { - - let mut response = response.status(406); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("text/plain").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } - - let body_content = body; - response.body(Body::from(body_content)) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct UntypedPropertyGetBodyValidator<'a> { - #[validate] - body: &'a models::ObjectUntypedProps, - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct UntypedPropertyGetBodyValidator<'a> { + #[validate] + body: &'a models::ObjectUntypedProps, +} #[tracing::instrument(skip_all)] fn untyped_property_get_validation( - body: Option, -) -> std::result::Result<( - Option, -), ValidationErrors> -{ - if let Some(body) = &body { - let b = UntypedPropertyGetBodyValidator { body }; - b.validate()?; - } + body: Option, +) -> std::result::Result<(Option,), ValidationErrors> { + if let Some(body) = &body { + let b = UntypedPropertyGetBodyValidator { body }; + b.validate()?; + } -Ok(( - body, -)) + Ok((body,)) } /// UntypedPropertyGet - GET /untyped_property #[tracing::instrument(skip_all)] async fn untyped_property_get( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - Json(body): Json>, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + Json(body): Json>, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + let validation = untyped_property_get_validation(body); - let validation = - untyped_property_get_validation( - body, - ) - ; - - let Ok(( - body, - )) = validation else { - return Response::builder() + let Ok((body,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().untyped_property_get( - method, - host, - cookies, - body, - ).await; + let result = api_impl + .as_ref() + .untyped_property_get(method, host, cookies, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - UntypedPropertyGetResponse::Status200_CheckThatUntypedPropertiesWorks - => { + let resp = match result { + Ok(rsp) => match rsp { + UntypedPropertyGetResponse::Status200_CheckThatUntypedPropertiesWorks => { + let mut response = response.status(200); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(200); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] -fn uuid_get_validation( -) -> std::result::Result<( -), ValidationErrors> -{ - -Ok(( -)) +fn uuid_get_validation() -> std::result::Result<(), ValidationErrors> { + Ok(()) } /// UuidGet - GET /uuid #[tracing::instrument(skip_all)] async fn uuid_get( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + let validation = uuid_get_validation(); - let validation = - uuid_get_validation( - ) - ; - - let Ok(( - )) = validation else { - return Response::builder() + let Ok(()) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().uuid_get( - method, - host, - cookies, - ).await; + let result = api_impl.as_ref().uuid_get(method, host, cookies).await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - UuidGetResponse::Status200_DuplicateResponseLongText - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + UuidGetResponse::Status200_DuplicateResponseLongText(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("application/json").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("application/json").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = tokio::task::spawn_blocking(move || { + serde_json::to_vec(&body).map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) + }) + .await + .unwrap()?; + response.body(Body::from(body_content)) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = tokio::task::spawn_blocking(move || - serde_json::to_vec(&body).map_err(|e| { - error!(error = ?e); - StatusCode::INTERNAL_SERVER_ERROR - })).await.unwrap()?; - response.body(Body::from(body_content)) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct XmlExtraPostBodyValidator<'a> { - body: &'a [u8], - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct XmlExtraPostBodyValidator<'a> { + body: &'a [u8], +} #[tracing::instrument(skip_all)] -fn xml_extra_post_validation( - body: Bytes, -) -> std::result::Result<( - Bytes, -), ValidationErrors> -{ - -Ok(( - body, -)) +fn xml_extra_post_validation(body: Bytes) -> std::result::Result<(Bytes,), ValidationErrors> { + Ok((body,)) } /// XmlExtraPost - POST /xml_extra #[tracing::instrument(skip_all)] async fn xml_extra_post( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - body: Bytes, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + body: Bytes, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + let validation = xml_extra_post_validation(body); - let validation = - xml_extra_post_validation( - body, - ) - ; - - let Ok(( - body, - )) = validation else { - return Response::builder() + let Ok((body,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().xml_extra_post( - method, - host, - cookies, - body, - ).await; + let result = api_impl + .as_ref() + .xml_extra_post(method, host, cookies, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - XmlExtraPostResponse::Status201_OK - => { + let resp = match result { + Ok(rsp) => match rsp { + XmlExtraPostResponse::Status201_OK => { + let mut response = response.status(201); + response.body(Body::empty()) + } + XmlExtraPostResponse::Status400_BadRequest => { + let mut response = response.status(400); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(201); - response.body(Body::empty()) - }, - XmlExtraPostResponse::Status400_BadRequest - => { - - let mut response = response.status(400); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct XmlOtherPostBodyValidator<'a> { - body: &'a [u8], - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct XmlOtherPostBodyValidator<'a> { + body: &'a [u8], +} #[tracing::instrument(skip_all)] -fn xml_other_post_validation( - body: Bytes, -) -> std::result::Result<( - Bytes, -), ValidationErrors> -{ - -Ok(( - body, -)) +fn xml_other_post_validation(body: Bytes) -> std::result::Result<(Bytes,), ValidationErrors> { + Ok((body,)) } /// XmlOtherPost - POST /xml_other #[tracing::instrument(skip_all)] async fn xml_other_post( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - body: Bytes, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + body: Bytes, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + let validation = xml_other_post_validation(body); - let validation = - xml_other_post_validation( - body, - ) - ; - - let Ok(( - body, - )) = validation else { - return Response::builder() + let Ok((body,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().xml_other_post( - method, - host, - cookies, - body, - ).await; + let result = api_impl + .as_ref() + .xml_other_post(method, host, cookies, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - XmlOtherPostResponse::Status201_OK - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + XmlOtherPostResponse::Status201_OK(body) => { + let mut response = response.status(201); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("text/plain").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(201); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("text/plain").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = body; + response.body(Body::from(body_content)) + } + XmlOtherPostResponse::Status400_BadRequest => { + let mut response = response.status(400); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = body; - response.body(Body::from(body_content)) - }, - XmlOtherPostResponse::Status400_BadRequest - => { - - let mut response = response.status(400); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct XmlOtherPutBodyValidator<'a> { - body: &'a [u8], - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct XmlOtherPutBodyValidator<'a> { + body: &'a [u8], +} #[tracing::instrument(skip_all)] -fn xml_other_put_validation( - body: Bytes, -) -> std::result::Result<( - Bytes, -), ValidationErrors> -{ - -Ok(( - body, -)) +fn xml_other_put_validation(body: Bytes) -> std::result::Result<(Bytes,), ValidationErrors> { + Ok((body,)) } /// XmlOtherPut - PUT /xml_other #[tracing::instrument(skip_all)] async fn xml_other_put( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - body: Bytes, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + body: Bytes, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + let validation = xml_other_put_validation(body); - let validation = - xml_other_put_validation( - body, - ) - ; - - let Ok(( - body, - )) = validation else { - return Response::builder() + let Ok((body,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().xml_other_put( - method, - host, - cookies, - body, - ).await; + let result = api_impl + .as_ref() + .xml_other_put(method, host, cookies, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - XmlOtherPutResponse::Status201_OK - => { + let resp = match result { + Ok(rsp) => match rsp { + XmlOtherPutResponse::Status201_OK => { + let mut response = response.status(201); + response.body(Body::empty()) + } + XmlOtherPutResponse::Status400_BadRequest => { + let mut response = response.status(400); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(201); - response.body(Body::empty()) - }, - XmlOtherPutResponse::Status400_BadRequest - => { - - let mut response = response.status(400); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct XmlPostBodyValidator<'a> { - body: &'a [u8], - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct XmlPostBodyValidator<'a> { + body: &'a [u8], +} #[tracing::instrument(skip_all)] -fn xml_post_validation( - body: Bytes, -) -> std::result::Result<( - Bytes, -), ValidationErrors> -{ - -Ok(( - body, -)) +fn xml_post_validation(body: Bytes) -> std::result::Result<(Bytes,), ValidationErrors> { + Ok((body,)) } /// XmlPost - POST /xml #[tracing::instrument(skip_all)] async fn xml_post( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - body: Bytes, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + body: Bytes, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + let validation = xml_post_validation(body); - let validation = - xml_post_validation( - body, - ) - ; - - let Ok(( - body, - )) = validation else { - return Response::builder() + let Ok((body,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().xml_post( - method, - host, - cookies, - body, - ).await; + let result = api_impl + .as_ref() + .xml_post(method, host, cookies, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - XmlPostResponse::Status201_OK - => { + let resp = match result { + Ok(rsp) => match rsp { + XmlPostResponse::Status201_OK => { + let mut response = response.status(201); + response.body(Body::empty()) + } + XmlPostResponse::Status400_BadRequest => { + let mut response = response.status(400); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(201); - response.body(Body::empty()) - }, - XmlPostResponse::Status400_BadRequest - => { - - let mut response = response.status(400); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct XmlPutBodyValidator<'a> { - body: &'a [u8], - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct XmlPutBodyValidator<'a> { + body: &'a [u8], +} #[tracing::instrument(skip_all)] -fn xml_put_validation( - body: Bytes, -) -> std::result::Result<( - Bytes, -), ValidationErrors> -{ - -Ok(( - body, -)) +fn xml_put_validation(body: Bytes) -> std::result::Result<(Bytes,), ValidationErrors> { + Ok((body,)) } /// XmlPut - PUT /xml #[tracing::instrument(skip_all)] async fn xml_put( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - body: Bytes, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + body: Bytes, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + let validation = xml_put_validation(body); - let validation = - xml_put_validation( - body, - ) - ; - - let Ok(( - body, - )) = validation else { - return Response::builder() + let Ok((body,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().xml_put( - method, - host, - cookies, - body, - ).await; + let result = api_impl.as_ref().xml_put(method, host, cookies, body).await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - XmlPutResponse::Status201_OK - => { + let resp = match result { + Ok(rsp) => match rsp { + XmlPutResponse::Status201_OK => { + let mut response = response.status(201); + response.body(Body::empty()) + } + XmlPutResponse::Status400_BadRequest => { + let mut response = response.status(400); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(201); - response.body(Body::empty()) - }, - XmlPutResponse::Status400_BadRequest - => { - - let mut response = response.status(400); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct CreateRepoBodyValidator<'a> { - #[validate] - body: &'a models::ObjectParam, - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct CreateRepoBodyValidator<'a> { + #[validate] + body: &'a models::ObjectParam, +} #[tracing::instrument(skip_all)] fn create_repo_validation( - body: models::ObjectParam, -) -> std::result::Result<( - models::ObjectParam, -), ValidationErrors> -{ - let b = CreateRepoBodyValidator { body: &body }; - b.validate()?; + body: models::ObjectParam, +) -> std::result::Result<(models::ObjectParam,), ValidationErrors> { + let b = CreateRepoBodyValidator { body: &body }; + b.validate()?; -Ok(( - body, -)) + Ok((body,)) } /// CreateRepo - POST /repos #[tracing::instrument(skip_all)] async fn create_repo( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - Json(body): Json, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + Json(body): Json, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + let validation = create_repo_validation(body); - let validation = - create_repo_validation( - body, - ) - ; - - let Ok(( - body, - )) = validation else { - return Response::builder() + let Ok((body,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().create_repo( - method, - host, - cookies, - body, - ).await; + let result = api_impl + .as_ref() + .create_repo(method, host, cookies, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - CreateRepoResponse::Status200_Success - => { + let resp = match result { + Ok(rsp) => match rsp { + CreateRepoResponse::Status200_Success => { + let mut response = response.status(200); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(200); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] fn get_repo_info_validation( - path_params: models::GetRepoInfoPathParams, -) -> std::result::Result<( - models::GetRepoInfoPathParams, -), ValidationErrors> -{ - path_params.validate()?; + path_params: models::GetRepoInfoPathParams, +) -> std::result::Result<(models::GetRepoInfoPathParams,), ValidationErrors> { + path_params.validate()?; -Ok(( - path_params, -)) + Ok((path_params,)) } /// GetRepoInfo - GET /repos/{repoId} #[tracing::instrument(skip_all)] async fn get_repo_info( - method: Method, - host: Host, - cookies: CookieJar, - Path(path_params): Path, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + Path(path_params): Path, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + let validation = get_repo_info_validation(path_params); - let validation = - get_repo_info_validation( - path_params, - ) - ; - - let Ok(( - path_params, - )) = validation else { - return Response::builder() + let Ok((path_params,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().get_repo_info( - method, - host, - cookies, - path_params, - ).await; + let result = api_impl + .as_ref() + .get_repo_info(method, host, cookies, path_params) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - GetRepoInfoResponse::Status200_OK - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + GetRepoInfoResponse::Status200_OK(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("application/json").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("application/json").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = tokio::task::spawn_blocking(move || { + serde_json::to_vec(&body).map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) + }) + .await + .unwrap()?; + response.body(Body::from(body_content)) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = tokio::task::spawn_blocking(move || - serde_json::to_vec(&body).map_err(|e| { - error!(error = ?e); - StatusCode::INTERNAL_SERVER_ERROR - })).await.unwrap()?; - response.body(Body::from(body_content)) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - diff --git a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/header.rs b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/header.rs index 4d1cc4c6dcc..7c530892fbf 100644 --- a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/header.rs +++ b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/header.rs @@ -30,11 +30,16 @@ macro_rules! ihv_generate { match hdr_value.to_str() { Ok(hdr_value) => match hdr_value.parse::<$t>() { Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value)), - Err(e) => Err(format!("Unable to parse {} as a string: {}", - stringify!($t), e)), + Err(e) => Err(format!( + "Unable to parse {} as a string: {}", + stringify!($t), + e + )), }, - Err(e) => Err(format!("Unable to parse header {:?} as a string - {}", - hdr_value, e)), + Err(e) => Err(format!( + "Unable to parse header {:?} as a string - {}", + hdr_value, e + )), } } } @@ -69,14 +74,17 @@ impl TryFrom for IntoHeaderValue> { match hdr_value.to_str() { Ok(hdr_value) => Ok(IntoHeaderValue( hdr_value - .split(',') - .filter_map(|x| match x.trim() { - "" => None, - y => Some(y.to_string()), - }) - .collect())), - Err(e) => Err(format!("Unable to parse header: {:?} as a string - {}", - hdr_value, e)), + .split(',') + .filter_map(|x| match x.trim() { + "" => None, + y => Some(y.to_string()), + }) + .collect(), + )), + Err(e) => Err(format!( + "Unable to parse header: {:?} as a string - {}", + hdr_value, e + )), } } } @@ -85,11 +93,13 @@ impl TryFrom>> for HeaderValue { type Error = String; fn try_from(hdr_value: IntoHeaderValue>) -> Result { - match HeaderValue::from_str(&hdr_value.0.join(", ")) { - Ok(hdr_value) => Ok(hdr_value), - Err(e) => Err(format!("Unable to convert {:?} into a header - {}", - hdr_value, e)) - } + match HeaderValue::from_str(&hdr_value.0.join(", ")) { + Ok(hdr_value) => Ok(hdr_value), + Err(e) => Err(format!( + "Unable to convert {:?} into a header - {}", + hdr_value, e + )), + } } } @@ -101,8 +111,7 @@ impl TryFrom for IntoHeaderValue { fn try_from(hdr_value: HeaderValue) -> Result { match hdr_value.to_str() { Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value.to_string())), - Err(e) => Err(format!("Unable to convert header {:?} to {}", - hdr_value, e)), + Err(e) => Err(format!("Unable to convert header {:?} to {}", hdr_value, e)), } } } @@ -113,8 +122,10 @@ impl TryFrom> for HeaderValue { fn try_from(hdr_value: IntoHeaderValue) -> Result { match HeaderValue::from_str(&hdr_value.0) { Ok(hdr_value) => Ok(hdr_value), - Err(e) => Err(format!("Unable to convert {:?} from a header {}", - hdr_value, e)) + Err(e) => Err(format!( + "Unable to convert {:?} from a header {}", + hdr_value, e + )), } } } @@ -128,11 +139,12 @@ impl TryFrom for IntoHeaderValue { match hdr_value.to_str() { Ok(hdr_value) => match hdr_value.parse() { Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value)), - Err(e) => Err(format!("Unable to parse bool from {} - {}", - hdr_value, e)), + Err(e) => Err(format!("Unable to parse bool from {} - {}", hdr_value, e)), }, - Err(e) => Err(format!("Unable to convert {:?} from a header {}", - hdr_value, e)), + Err(e) => Err(format!( + "Unable to convert {:?} from a header {}", + hdr_value, e + )), } } } @@ -143,8 +155,10 @@ impl TryFrom> for HeaderValue { fn try_from(hdr_value: IntoHeaderValue) -> Result { match HeaderValue::from_str(&hdr_value.0.to_string()) { Ok(hdr_value) => Ok(hdr_value), - Err(e) => Err(format!("Unable to convert: {:?} into a header: {}", - hdr_value, e)) + Err(e) => Err(format!( + "Unable to convert: {:?} into a header: {}", + hdr_value, e + )), } } } @@ -158,11 +172,12 @@ impl TryFrom for IntoHeaderValue> { match hdr_value.to_str() { Ok(hdr_value) => match DateTime::parse_from_rfc3339(hdr_value) { Ok(date) => Ok(IntoHeaderValue(date.with_timezone(&Utc))), - Err(e) => Err(format!("Unable to parse: {} as date - {}", - hdr_value, e)), + Err(e) => Err(format!("Unable to parse: {} as date - {}", hdr_value, e)), }, - Err(e) => Err(format!("Unable to convert header {:?} to string {}", - hdr_value, e)), + Err(e) => Err(format!( + "Unable to convert header {:?} to string {}", + hdr_value, e + )), } } } @@ -173,8 +188,10 @@ impl TryFrom>> for HeaderValue { fn try_from(hdr_value: IntoHeaderValue>) -> Result { match HeaderValue::from_str(hdr_value.0.to_rfc3339().as_str()) { Ok(hdr_value) => Ok(hdr_value), - Err(e) => Err(format!("Unable to convert {:?} to a header: {}", - hdr_value, e)), + Err(e) => Err(format!( + "Unable to convert {:?} to a header: {}", + hdr_value, e + )), } } } diff --git a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/lib.rs b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/lib.rs index a19cbbbba29..553ab355813 100644 --- a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/lib.rs +++ b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/lib.rs @@ -1,4 +1,12 @@ -#![allow(missing_docs, trivial_casts, unused_variables, unused_mut, unused_imports, unused_extern_crates, non_camel_case_types)] +#![allow( + missing_docs, + trivial_casts, + unused_variables, + unused_mut, + unused_imports, + unused_extern_crates, + non_camel_case_types +)] #![allow(unused_imports, unused_attributes)] #![allow(clippy::derive_partial_eq_without_eq, clippy::disallowed_names)] @@ -14,772 +22,695 @@ use types::*; pub const BASE_PATH: &str = "/v2"; pub const API_VERSION: &str = "1.0.0"; - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum TestSpecialTagsResponse { /// successful operation - Status200_SuccessfulOperation - (models::Client) + Status200_SuccessfulOperation(models::Client), } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum Call123exampleResponse { /// success - Status200_Success + Status200_Success, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum FakeOuterBooleanSerializeResponse { /// Output boolean - Status200_OutputBoolean - (bool) + Status200_OutputBoolean(bool), } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum FakeOuterCompositeSerializeResponse { /// Output composite - Status200_OutputComposite - (models::OuterComposite) + Status200_OutputComposite(models::OuterComposite), } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum FakeOuterNumberSerializeResponse { /// Output number - Status200_OutputNumber - (f64) + Status200_OutputNumber(f64), } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum FakeOuterStringSerializeResponse { /// Output string - Status200_OutputString - (String) + Status200_OutputString(String), } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum FakeResponseWithNumericalDescriptionResponse { /// 1234 - Status200 + Status200, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum HyphenParamResponse { /// Success - Status200_Success + Status200_Success, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum TestBodyWithQueryParamsResponse { /// Success - Status200_Success + Status200_Success, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum TestClientModelResponse { /// successful operation - Status200_SuccessfulOperation - (models::Client) + Status200_SuccessfulOperation(models::Client), } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum TestEndpointParametersResponse { /// Invalid username supplied - Status400_InvalidUsernameSupplied - , + Status400_InvalidUsernameSupplied, /// User not found - Status404_UserNotFound + Status404_UserNotFound, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum TestEnumParametersResponse { /// Invalid request - Status400_InvalidRequest - , + Status400_InvalidRequest, /// Not found - Status404_NotFound + Status404_NotFound, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum TestInlineAdditionalPropertiesResponse { /// successful operation - Status200_SuccessfulOperation + Status200_SuccessfulOperation, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum TestJsonFormDataResponse { /// successful operation - Status200_SuccessfulOperation + Status200_SuccessfulOperation, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum TestClassnameResponse { /// successful operation - Status200_SuccessfulOperation - (models::Client) + Status200_SuccessfulOperation(models::Client), } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum AddPetResponse { /// Invalid input - Status405_InvalidInput + Status405_InvalidInput, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum DeletePetResponse { /// Invalid pet value - Status400_InvalidPetValue + Status400_InvalidPetValue, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum FindPetsByStatusResponse { /// successful operation - Status200_SuccessfulOperation - (String) - , + Status200_SuccessfulOperation(String), /// Invalid status value - Status400_InvalidStatusValue + Status400_InvalidStatusValue, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum FindPetsByTagsResponse { /// successful operation - Status200_SuccessfulOperation - (String) - , + Status200_SuccessfulOperation(String), /// Invalid tag value - Status400_InvalidTagValue + Status400_InvalidTagValue, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum GetPetByIdResponse { /// successful operation - Status200_SuccessfulOperation - (String) - , + Status200_SuccessfulOperation(String), /// Invalid ID supplied - Status400_InvalidIDSupplied - , + Status400_InvalidIDSupplied, /// Pet not found - Status404_PetNotFound + Status404_PetNotFound, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum UpdatePetResponse { /// Invalid ID supplied - Status400_InvalidIDSupplied - , + Status400_InvalidIDSupplied, /// Pet not found - Status404_PetNotFound - , + Status404_PetNotFound, /// Validation exception - Status405_ValidationException + Status405_ValidationException, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum UpdatePetWithFormResponse { /// Invalid input - Status405_InvalidInput + Status405_InvalidInput, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum UploadFileResponse { /// successful operation - Status200_SuccessfulOperation - (models::ApiResponse) + Status200_SuccessfulOperation(models::ApiResponse), } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum DeleteOrderResponse { /// Invalid ID supplied - Status400_InvalidIDSupplied - , + Status400_InvalidIDSupplied, /// Order not found - Status404_OrderNotFound + Status404_OrderNotFound, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum GetInventoryResponse { /// successful operation - Status200_SuccessfulOperation - (std::collections::HashMap) + Status200_SuccessfulOperation(std::collections::HashMap), } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum GetOrderByIdResponse { /// successful operation - Status200_SuccessfulOperation - (String) - , + Status200_SuccessfulOperation(String), /// Invalid ID supplied - Status400_InvalidIDSupplied - , + Status400_InvalidIDSupplied, /// Order not found - Status404_OrderNotFound + Status404_OrderNotFound, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum PlaceOrderResponse { /// successful operation - Status200_SuccessfulOperation - (String) - , + Status200_SuccessfulOperation(String), /// Invalid Order - Status400_InvalidOrder + Status400_InvalidOrder, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum CreateUserResponse { /// successful operation - Status0_SuccessfulOperation + Status0_SuccessfulOperation, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum CreateUsersWithArrayInputResponse { /// successful operation - Status0_SuccessfulOperation + Status0_SuccessfulOperation, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum CreateUsersWithListInputResponse { /// successful operation - Status0_SuccessfulOperation + Status0_SuccessfulOperation, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum DeleteUserResponse { /// Invalid username supplied - Status400_InvalidUsernameSupplied - , + Status400_InvalidUsernameSupplied, /// User not found - Status404_UserNotFound + Status404_UserNotFound, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum GetUserByNameResponse { /// successful operation - Status200_SuccessfulOperation - (String) - , + Status200_SuccessfulOperation(String), /// Invalid username supplied - Status400_InvalidUsernameSupplied - , + Status400_InvalidUsernameSupplied, /// User not found - Status404_UserNotFound + Status404_UserNotFound, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum LoginUserResponse { /// successful operation - Status200_SuccessfulOperation - { + Status200_SuccessfulOperation { body: String, - x_rate_limit: - Option< - i32 - > - , - x_expires_after: - Option< - chrono::DateTime:: - > - } - , + x_rate_limit: Option, + x_expires_after: Option>, + }, /// Invalid username/password supplied - Status400_InvalidUsername + Status400_InvalidUsername, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum LogoutUserResponse { /// successful operation - Status0_SuccessfulOperation + Status0_SuccessfulOperation, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum UpdateUserResponse { /// Invalid user supplied - Status400_InvalidUserSupplied - , + Status400_InvalidUserSupplied, /// User not found - Status404_UserNotFound + Status404_UserNotFound, } - /// API #[async_trait] #[allow(clippy::ptr_arg)] pub trait Api { - - /// To test special tags. - /// - /// TestSpecialTags - PATCH /v2/another-fake/dummy - async fn test_special_tags( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::Client, - ) -> Result; - - - /// Call123example - GET /v2/fake/operation-with-numeric-id - async fn call123example( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - - /// FakeOuterBooleanSerialize - POST /v2/fake/outer/boolean - async fn fake_outer_boolean_serialize( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Option, - ) -> Result; - - - /// FakeOuterCompositeSerialize - POST /v2/fake/outer/composite - async fn fake_outer_composite_serialize( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Option, - ) -> Result; - - - /// FakeOuterNumberSerialize - POST /v2/fake/outer/number - async fn fake_outer_number_serialize( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Option, - ) -> Result; - - - /// FakeOuterStringSerialize - POST /v2/fake/outer/string - async fn fake_outer_string_serialize( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Option, - ) -> Result; - - - /// FakeResponseWithNumericalDescription - GET /v2/fake/response-with-numerical-description - async fn fake_response_with_numerical_description( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - - /// HyphenParam - GET /v2/fake/hyphenParam/{hyphen-param} - async fn hyphen_param( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::HyphenParamPathParams, - ) -> Result; - - - /// TestBodyWithQueryParams - PUT /v2/fake/body-with-query-params - async fn test_body_with_query_params( - &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::TestBodyWithQueryParamsQueryParams, - body: models::User, - ) -> Result; - - - /// To test \"client\" model. - /// - /// TestClientModel - PATCH /v2/fake - async fn test_client_model( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::Client, - ) -> Result; - - - /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트. - /// - /// TestEndpointParameters - POST /v2/fake - async fn test_endpoint_parameters( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - - /// To test enum parameters. - /// - /// TestEnumParameters - GET /v2/fake - async fn test_enum_parameters( - &self, - method: Method, - host: Host, - cookies: CookieJar, - header_params: models::TestEnumParametersHeaderParams, - query_params: models::TestEnumParametersQueryParams, - ) -> Result; - - - /// test inline additionalProperties. - /// - /// TestInlineAdditionalProperties - POST /v2/fake/inline-additionalProperties - async fn test_inline_additional_properties( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: std::collections::HashMap, - ) -> Result; - - - /// test json serialization of form data. - /// - /// TestJsonFormData - GET /v2/fake/jsonFormData - async fn test_json_form_data( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - - /// To test class name in snake case. - /// - /// TestClassname - PATCH /v2/fake_classname_test - async fn test_classname( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::Client, - ) -> Result; - - - /// Add a new pet to the store. - /// - /// AddPet - POST /v2/pet - async fn add_pet( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::Pet, - ) -> Result; - - - /// Deletes a pet. - /// - /// DeletePet - DELETE /v2/pet/{petId} - async fn delete_pet( - &self, - method: Method, - host: Host, - cookies: CookieJar, - header_params: models::DeletePetHeaderParams, - path_params: models::DeletePetPathParams, - ) -> Result; - - - /// Finds Pets by status. - /// - /// FindPetsByStatus - GET /v2/pet/findByStatus - async fn find_pets_by_status( - &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::FindPetsByStatusQueryParams, - ) -> Result; - - - /// Finds Pets by tags. - /// - /// FindPetsByTags - GET /v2/pet/findByTags - async fn find_pets_by_tags( - &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::FindPetsByTagsQueryParams, - ) -> Result; - - - /// Find pet by ID. - /// - /// GetPetById - GET /v2/pet/{petId} - async fn get_pet_by_id( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::GetPetByIdPathParams, - ) -> Result; - - - /// Update an existing pet. - /// - /// UpdatePet - PUT /v2/pet - async fn update_pet( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::Pet, - ) -> Result; - - - /// Updates a pet in the store with form data. - /// - /// UpdatePetWithForm - POST /v2/pet/{petId} - async fn update_pet_with_form( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::UpdatePetWithFormPathParams, - ) -> Result; - - - /// uploads an image. - /// - /// UploadFile - POST /v2/pet/{petId}/uploadImage - async fn upload_file( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::UploadFilePathParams, - body: Multipart, - ) -> Result; - - - /// Delete purchase order by ID. - /// - /// DeleteOrder - DELETE /v2/store/order/{order_id} - async fn delete_order( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::DeleteOrderPathParams, - ) -> Result; - - - /// Returns pet inventories by status. - /// - /// GetInventory - GET /v2/store/inventory - async fn get_inventory( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - - /// Find purchase order by ID. - /// - /// GetOrderById - GET /v2/store/order/{order_id} - async fn get_order_by_id( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::GetOrderByIdPathParams, - ) -> Result; - - - /// Place an order for a pet. - /// - /// PlaceOrder - POST /v2/store/order - async fn place_order( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::Order, - ) -> Result; - - - /// Create user. - /// - /// CreateUser - POST /v2/user - async fn create_user( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::User, - ) -> Result; - - - /// Creates list of users with given input array. - /// - /// CreateUsersWithArrayInput - POST /v2/user/createWithArray - async fn create_users_with_array_input( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Vec, - ) -> Result; - - - /// Creates list of users with given input array. - /// - /// CreateUsersWithListInput - POST /v2/user/createWithList - async fn create_users_with_list_input( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Vec, - ) -> Result; - - - /// Delete user. - /// - /// DeleteUser - DELETE /v2/user/{username} - async fn delete_user( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::DeleteUserPathParams, - ) -> Result; - - - /// Get user by user name. - /// - /// GetUserByName - GET /v2/user/{username} - async fn get_user_by_name( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::GetUserByNamePathParams, - ) -> Result; - - - /// Logs user into the system. - /// - /// LoginUser - GET /v2/user/login - async fn login_user( - &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::LoginUserQueryParams, - ) -> Result; - - - /// Logs out current logged in user session. - /// - /// LogoutUser - GET /v2/user/logout - async fn logout_user( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - - /// Updated user. - /// - /// UpdateUser - PUT /v2/user/{username} - async fn update_user( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::UpdateUserPathParams, - body: models::User, - ) -> Result; - + /// To test special tags. + /// + /// TestSpecialTags - PATCH /v2/another-fake/dummy + async fn test_special_tags( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: models::Client, + ) -> Result; + + /// Call123example - GET /v2/fake/operation-with-numeric-id + async fn call123example( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + + /// FakeOuterBooleanSerialize - POST /v2/fake/outer/boolean + async fn fake_outer_boolean_serialize( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: Option, + ) -> Result; + + /// FakeOuterCompositeSerialize - POST /v2/fake/outer/composite + async fn fake_outer_composite_serialize( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: Option, + ) -> Result; + + /// FakeOuterNumberSerialize - POST /v2/fake/outer/number + async fn fake_outer_number_serialize( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: Option, + ) -> Result; + + /// FakeOuterStringSerialize - POST /v2/fake/outer/string + async fn fake_outer_string_serialize( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: Option, + ) -> Result; + + /// FakeResponseWithNumericalDescription - GET /v2/fake/response-with-numerical-description + async fn fake_response_with_numerical_description( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + + /// HyphenParam - GET /v2/fake/hyphenParam/{hyphen-param} + async fn hyphen_param( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::HyphenParamPathParams, + ) -> Result; + + /// TestBodyWithQueryParams - PUT /v2/fake/body-with-query-params + async fn test_body_with_query_params( + &self, + method: Method, + host: Host, + cookies: CookieJar, + query_params: models::TestBodyWithQueryParamsQueryParams, + body: models::User, + ) -> Result; + + /// To test \"client\" model. + /// + /// TestClientModel - PATCH /v2/fake + async fn test_client_model( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: models::Client, + ) -> Result; + + /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트. + /// + /// TestEndpointParameters - POST /v2/fake + async fn test_endpoint_parameters( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + + /// To test enum parameters. + /// + /// TestEnumParameters - GET /v2/fake + async fn test_enum_parameters( + &self, + method: Method, + host: Host, + cookies: CookieJar, + header_params: models::TestEnumParametersHeaderParams, + query_params: models::TestEnumParametersQueryParams, + ) -> Result; + + /// test inline additionalProperties. + /// + /// TestInlineAdditionalProperties - POST /v2/fake/inline-additionalProperties + async fn test_inline_additional_properties( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: std::collections::HashMap, + ) -> Result; + + /// test json serialization of form data. + /// + /// TestJsonFormData - GET /v2/fake/jsonFormData + async fn test_json_form_data( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + + /// To test class name in snake case. + /// + /// TestClassname - PATCH /v2/fake_classname_test + async fn test_classname( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: models::Client, + ) -> Result; + + /// Add a new pet to the store. + /// + /// AddPet - POST /v2/pet + async fn add_pet( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: models::Pet, + ) -> Result; + + /// Deletes a pet. + /// + /// DeletePet - DELETE /v2/pet/{petId} + async fn delete_pet( + &self, + method: Method, + host: Host, + cookies: CookieJar, + header_params: models::DeletePetHeaderParams, + path_params: models::DeletePetPathParams, + ) -> Result; + + /// Finds Pets by status. + /// + /// FindPetsByStatus - GET /v2/pet/findByStatus + async fn find_pets_by_status( + &self, + method: Method, + host: Host, + cookies: CookieJar, + query_params: models::FindPetsByStatusQueryParams, + ) -> Result; + + /// Finds Pets by tags. + /// + /// FindPetsByTags - GET /v2/pet/findByTags + async fn find_pets_by_tags( + &self, + method: Method, + host: Host, + cookies: CookieJar, + query_params: models::FindPetsByTagsQueryParams, + ) -> Result; + + /// Find pet by ID. + /// + /// GetPetById - GET /v2/pet/{petId} + async fn get_pet_by_id( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::GetPetByIdPathParams, + ) -> Result; + + /// Update an existing pet. + /// + /// UpdatePet - PUT /v2/pet + async fn update_pet( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: models::Pet, + ) -> Result; + + /// Updates a pet in the store with form data. + /// + /// UpdatePetWithForm - POST /v2/pet/{petId} + async fn update_pet_with_form( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::UpdatePetWithFormPathParams, + ) -> Result; + + /// uploads an image. + /// + /// UploadFile - POST /v2/pet/{petId}/uploadImage + async fn upload_file( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::UploadFilePathParams, + body: Multipart, + ) -> Result; + + /// Delete purchase order by ID. + /// + /// DeleteOrder - DELETE /v2/store/order/{order_id} + async fn delete_order( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::DeleteOrderPathParams, + ) -> Result; + + /// Returns pet inventories by status. + /// + /// GetInventory - GET /v2/store/inventory + async fn get_inventory( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + + /// Find purchase order by ID. + /// + /// GetOrderById - GET /v2/store/order/{order_id} + async fn get_order_by_id( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::GetOrderByIdPathParams, + ) -> Result; + + /// Place an order for a pet. + /// + /// PlaceOrder - POST /v2/store/order + async fn place_order( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: models::Order, + ) -> Result; + + /// Create user. + /// + /// CreateUser - POST /v2/user + async fn create_user( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: models::User, + ) -> Result; + + /// Creates list of users with given input array. + /// + /// CreateUsersWithArrayInput - POST /v2/user/createWithArray + async fn create_users_with_array_input( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: Vec, + ) -> Result; + + /// Creates list of users with given input array. + /// + /// CreateUsersWithListInput - POST /v2/user/createWithList + async fn create_users_with_list_input( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: Vec, + ) -> Result; + + /// Delete user. + /// + /// DeleteUser - DELETE /v2/user/{username} + async fn delete_user( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::DeleteUserPathParams, + ) -> Result; + + /// Get user by user name. + /// + /// GetUserByName - GET /v2/user/{username} + async fn get_user_by_name( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::GetUserByNamePathParams, + ) -> Result; + + /// Logs user into the system. + /// + /// LoginUser - GET /v2/user/login + async fn login_user( + &self, + method: Method, + host: Host, + cookies: CookieJar, + query_params: models::LoginUserQueryParams, + ) -> Result; + + /// Logs out current logged in user session. + /// + /// LogoutUser - GET /v2/user/logout + async fn logout_user( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + + /// Updated user. + /// + /// UpdateUser - PUT /v2/user/{username} + async fn update_user( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::UpdateUserPathParams, + body: models::User, + ) -> Result; } #[cfg(feature = "server")] diff --git a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/models.rs b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/models.rs index 3ba9efc9eb7..0ea52014407 100644 --- a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/models.rs +++ b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/models.rs @@ -7,218 +7,163 @@ use validator::Validate; use crate::header; use crate::{models, types::*}; - - - - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct HyphenParamPathParams { - /// Parameter with hyphen in name - pub hyphen_param: String, - } +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct HyphenParamPathParams { + /// Parameter with hyphen in name + pub hyphen_param: String, +} +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct TestBodyWithQueryParamsQueryParams { + #[serde(rename = "query")] + pub query: String, +} - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct TestBodyWithQueryParamsQueryParams { - #[serde(rename = "query")] - pub query: String, - } +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct TestEnumParametersHeaderParams { + pub enum_header_string_array: Option>, + pub enum_header_string: Option, +} - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct TestEnumParametersHeaderParams { - pub enum_header_string_array: Option>, - pub enum_header_string: Option, - } +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct TestEnumParametersQueryParams { + /// Query parameter enum test (string array) + /// Note: inline enums are not fully supported by openapi-generator + #[serde(rename = "enum_query_string_array")] + #[serde(skip_serializing_if = "Option::is_none")] + pub enum_query_string_array: Option>, + /// Query parameter enum test (string) + /// Note: inline enums are not fully supported by openapi-generator + #[serde(rename = "enum_query_string")] + #[serde(skip_serializing_if = "Option::is_none")] + pub enum_query_string: Option, + /// Query parameter enum test (double) + /// Note: inline enums are not fully supported by openapi-generator + #[serde(rename = "enum_query_integer")] + #[serde(skip_serializing_if = "Option::is_none")] + pub enum_query_integer: Option, + /// Query parameter enum test (double) + /// Note: inline enums are not fully supported by openapi-generator + #[serde(rename = "enum_query_double")] + #[serde(skip_serializing_if = "Option::is_none")] + pub enum_query_double: Option, +} - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct TestEnumParametersQueryParams { - /// Query parameter enum test (string array) - /// Note: inline enums are not fully supported by openapi-generator - #[serde(rename = "enum_query_string_array")] - #[serde(skip_serializing_if="Option::is_none")] - pub enum_query_string_array: Option>, - /// Query parameter enum test (string) - /// Note: inline enums are not fully supported by openapi-generator - #[serde(rename = "enum_query_string")] - #[serde(skip_serializing_if="Option::is_none")] - pub enum_query_string: Option, - /// Query parameter enum test (double) - /// Note: inline enums are not fully supported by openapi-generator - #[serde(rename = "enum_query_integer")] - #[serde(skip_serializing_if="Option::is_none")] - pub enum_query_integer: Option, - /// Query parameter enum test (double) - /// Note: inline enums are not fully supported by openapi-generator - #[serde(rename = "enum_query_double")] - #[serde(skip_serializing_if="Option::is_none")] - pub enum_query_double: Option, - } +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct DeletePetHeaderParams { + pub api_key: Option, +} - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct DeletePetHeaderParams { - pub api_key: Option, - } +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct DeletePetPathParams { + /// Pet id to delete + pub pet_id: i64, +} - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct DeletePetPathParams { - /// Pet id to delete - pub pet_id: i64, - } +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct FindPetsByStatusQueryParams { + /// Status values that need to be considered for filter + /// Note: inline enums are not fully supported by openapi-generator + #[serde(rename = "status")] + pub status: Vec, +} +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct FindPetsByTagsQueryParams { + /// Tags to filter by + #[serde(rename = "tags")] + pub tags: Vec, +} - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct FindPetsByStatusQueryParams { - /// Status values that need to be considered for filter - /// Note: inline enums are not fully supported by openapi-generator - #[serde(rename = "status")] - pub status: Vec, - } +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct GetPetByIdPathParams { + /// ID of pet to return + pub pet_id: i64, +} - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct FindPetsByTagsQueryParams { - /// Tags to filter by - #[serde(rename = "tags")] - pub tags: Vec, - } +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct UpdatePetWithFormPathParams { + /// ID of pet that needs to be updated + pub pet_id: i64, +} - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct GetPetByIdPathParams { - /// ID of pet to return - pub pet_id: i64, - } - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct UpdatePetWithFormPathParams { - /// ID of pet that needs to be updated - pub pet_id: i64, - } - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct UploadFilePathParams { - /// ID of pet to update - pub pet_id: i64, - } - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct DeleteOrderPathParams { - /// ID of the order that needs to be deleted - pub order_id: String, - } - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct GetOrderByIdPathParams { - /// ID of pet that needs to be fetched - #[validate( - range(min = 1, max = 5), - )] - pub order_id: i64, - } - - - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct DeleteUserPathParams { - /// The name that needs to be deleted - pub username: String, - } - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct GetUserByNamePathParams { - /// The name that needs to be fetched. Use user1 for testing. - pub username: String, - } - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct LoginUserQueryParams { - /// The user name for login - #[serde(rename = "username")] - pub username: String, - /// The password for login in clear text - #[serde(rename = "password")] - pub password: String, - } - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct UpdateUserPathParams { - /// name that need to be deleted - pub username: String, - } +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct UploadFilePathParams { + /// ID of pet to update + pub pet_id: i64, +} +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct DeleteOrderPathParams { + /// ID of the order that needs to be deleted + pub order_id: String, +} +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct GetOrderByIdPathParams { + /// ID of pet that needs to be fetched + #[validate(range(min = 1, max = 5))] + pub order_id: i64, +} +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct DeleteUserPathParams { + /// The name that needs to be deleted + pub username: String, +} +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct GetUserByNamePathParams { + /// The name that needs to be fetched. Use user1 for testing. + pub username: String, +} +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct LoginUserQueryParams { + /// The user name for login + #[serde(rename = "username")] + pub username: String, + /// The password for login in clear text + #[serde(rename = "password")] + pub password: String, +} +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct UpdateUserPathParams { + /// name that need to be deleted + pub username: String, +} #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct AdditionalPropertiesClass { #[serde(rename = "map_property")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub map_property: Option>, #[serde(rename = "map_of_map_property")] - #[serde(skip_serializing_if="Option::is_none")] - pub map_of_map_property: Option>>, - + #[serde(skip_serializing_if = "Option::is_none")] + pub map_of_map_property: + Option>>, } - impl AdditionalPropertiesClass { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> AdditionalPropertiesClass { @@ -258,7 +203,8 @@ impl std::str::FromStr for AdditionalPropertiesClass { #[allow(dead_code)] struct IntermediateRep { pub map_property: Vec>, - pub map_of_map_property: Vec>>, + pub map_of_map_property: + Vec>>, } let mut intermediate_rep = IntermediateRep::default(); @@ -270,7 +216,11 @@ impl std::str::FromStr for AdditionalPropertiesClass { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing AdditionalPropertiesClass".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing AdditionalPropertiesClass".to_string(), + ) + } }; if let Some(key) = key_result { @@ -300,13 +250,16 @@ impl std::str::FromStr for AdditionalPropertiesClass { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for AdditionalPropertiesClass - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for AdditionalPropertiesClass - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -317,27 +270,25 @@ impl std::convert::TryFrom for header::IntoHeaderValue std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into AdditionalPropertiesClass - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into AdditionalPropertiesClass - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct Animal { @@ -345,15 +296,13 @@ pub struct Animal { pub class_name: String, #[serde(rename = "color")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub color: Option, - } - impl Animal { #[allow(clippy::new_without_default, clippy::too_many_arguments)] - pub fn new(class_name: String, ) -> Animal { + pub fn new(class_name: String) -> Animal { Animal { class_name, color: Some("red".to_string()), @@ -367,18 +316,11 @@ impl Animal { impl std::string::ToString for Animal { fn to_string(&self) -> String { let params: Vec> = vec![ - Some("className".to_string()), Some(self.class_name.to_string()), - - - self.color.as_ref().map(|color| { - [ - "color".to_string(), - color.to_string(), - ].join(",") - }), - + self.color + .as_ref() + .map(|color| ["color".to_string(), color.to_string()].join(",")), ]; params.into_iter().flatten().collect::>().join(",") @@ -409,17 +351,29 @@ impl std::str::FromStr for Animal { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing Animal".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing Animal".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "className" => intermediate_rep.class_name.push(::from_str(val).map_err(|x| x.to_string())?), + "className" => intermediate_rep.class_name.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "color" => intermediate_rep.color.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing Animal".to_string()) + "color" => intermediate_rep.color.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing Animal".to_string(), + ) + } } } @@ -429,7 +383,11 @@ impl std::str::FromStr for Animal { // Use the intermediate representation to return the struct std::result::Result::Ok(Animal { - class_name: intermediate_rep.class_name.into_iter().next().ok_or_else(|| "className missing in Animal".to_string())?, + class_name: intermediate_rep + .class_name + .into_iter() + .next() + .ok_or_else(|| "className missing in Animal".to_string())?, color: intermediate_rep.color.into_iter().next(), }) } @@ -441,13 +399,16 @@ impl std::str::FromStr for Animal { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for Animal - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for Animal - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -458,24 +419,25 @@ impl std::convert::TryFrom for header::IntoHeaderValue { fn try_from(hdr_value: HeaderValue) -> std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into Animal - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into Animal - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct AnimalFarm(Vec); @@ -499,7 +461,7 @@ impl std::convert::From for Vec { } impl std::iter::FromIterator for AnimalFarm { - fn from_iter>(u: U) -> Self { + fn from_iter>(u: U) -> Self { AnimalFarm(Vec::::from_iter(u)) } } @@ -549,7 +511,10 @@ impl std::ops::DerefMut for AnimalFarm { /// Should be implemented in a serde serializer impl std::string::ToString for AnimalFarm { fn to_string(&self) -> String { - self.iter().map(|x| x.to_string()).collect::>().join(",") + self.iter() + .map(|x| x.to_string()) + .collect::>() + .join(",") } } @@ -561,28 +526,29 @@ impl std::str::FromStr for AnimalFarm { fn from_str(s: &str) -> std::result::Result { let mut items = vec![]; - for item in s.split(',') - { + for item in s.split(',') { items.push(item.parse()?); } std::result::Result::Ok(AnimalFarm(items)) } } - // Methods for converting between header::IntoHeaderValue and HeaderValue #[cfg(feature = "server")] impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for AnimalFarm - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for AnimalFarm - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -593,45 +559,41 @@ impl std::convert::TryFrom for header::IntoHeaderValue fn try_from(hdr_value: HeaderValue) -> std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into AnimalFarm - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into AnimalFarm - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct ApiResponse { #[serde(rename = "code")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub code: Option, #[serde(rename = "type")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub r#type: Option, #[serde(rename = "message")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub message: Option, - } - impl ApiResponse { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> ApiResponse { @@ -649,30 +611,15 @@ impl ApiResponse { impl std::string::ToString for ApiResponse { fn to_string(&self) -> String { let params: Vec> = vec![ - - self.code.as_ref().map(|code| { - [ - "code".to_string(), - code.to_string(), - ].join(",") - }), - - - self.r#type.as_ref().map(|r#type| { - [ - "type".to_string(), - r#type.to_string(), - ].join(",") - }), - - - self.message.as_ref().map(|message| { - [ - "message".to_string(), - message.to_string(), - ].join(",") - }), - + self.code + .as_ref() + .map(|code| ["code".to_string(), code.to_string()].join(",")), + self.r#type + .as_ref() + .map(|r#type| ["type".to_string(), r#type.to_string()].join(",")), + self.message + .as_ref() + .map(|message| ["message".to_string(), message.to_string()].join(",")), ]; params.into_iter().flatten().collect::>().join(",") @@ -704,19 +651,33 @@ impl std::str::FromStr for ApiResponse { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing ApiResponse".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing ApiResponse".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "code" => intermediate_rep.code.push(::from_str(val).map_err(|x| x.to_string())?), + "code" => intermediate_rep.code.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "type" => intermediate_rep.r#type.push(::from_str(val).map_err(|x| x.to_string())?), + "type" => intermediate_rep.r#type.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "message" => intermediate_rep.message.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing ApiResponse".to_string()) + "message" => intermediate_rep.message.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing ApiResponse".to_string(), + ) + } } } @@ -739,13 +700,16 @@ impl std::str::FromStr for ApiResponse { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for ApiResponse - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for ApiResponse - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -756,37 +720,33 @@ impl std::convert::TryFrom for header::IntoHeaderValue fn try_from(hdr_value: HeaderValue) -> std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into ApiResponse - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into ApiResponse - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct ArrayOfArrayOfNumberOnly { #[serde(rename = "ArrayArrayNumber")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub array_array_number: Option>>, - } - impl ArrayOfArrayOfNumberOnly { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> ArrayOfArrayOfNumberOnly { @@ -833,7 +793,11 @@ impl std::str::FromStr for ArrayOfArrayOfNumberOnly { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing ArrayOfArrayOfNumberOnly".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing ArrayOfArrayOfNumberOnly".to_string(), + ) + } }; if let Some(key) = key_result { @@ -861,13 +825,16 @@ impl std::str::FromStr for ArrayOfArrayOfNumberOnly { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for ArrayOfArrayOfNumberOnly - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for ArrayOfArrayOfNumberOnly - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -878,43 +845,37 @@ impl std::convert::TryFrom for header::IntoHeaderValue std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into ArrayOfArrayOfNumberOnly - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into ArrayOfArrayOfNumberOnly - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct ArrayOfNumberOnly { #[serde(rename = "ArrayNumber")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub array_number: Option>, - } - impl ArrayOfNumberOnly { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> ArrayOfNumberOnly { - ArrayOfNumberOnly { - array_number: None, - } + ArrayOfNumberOnly { array_number: None } } } @@ -923,16 +884,17 @@ impl ArrayOfNumberOnly { /// Should be implemented in a serde serializer impl std::string::ToString for ArrayOfNumberOnly { fn to_string(&self) -> String { - let params: Vec> = vec![ - - self.array_number.as_ref().map(|array_number| { - [ - "ArrayNumber".to_string(), - array_number.iter().map(|x| x.to_string()).collect::>().join(","), - ].join(",") - }), - - ]; + let params: Vec> = vec![self.array_number.as_ref().map(|array_number| { + [ + "ArrayNumber".to_string(), + array_number + .iter() + .map(|x| x.to_string()) + .collect::>() + .join(","), + ] + .join(",") + })]; params.into_iter().flatten().collect::>().join(",") } @@ -961,14 +923,25 @@ impl std::str::FromStr for ArrayOfNumberOnly { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing ArrayOfNumberOnly".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing ArrayOfNumberOnly".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { - "ArrayNumber" => return std::result::Result::Err("Parsing a container in this style is not supported in ArrayOfNumberOnly".to_string()), - _ => return std::result::Result::Err("Unexpected key while parsing ArrayOfNumberOnly".to_string()) + "ArrayNumber" => return std::result::Result::Err( + "Parsing a container in this style is not supported in ArrayOfNumberOnly" + .to_string(), + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing ArrayOfNumberOnly".to_string(), + ) + } } } @@ -989,13 +962,16 @@ impl std::str::FromStr for ArrayOfNumberOnly { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for ArrayOfNumberOnly - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for ArrayOfNumberOnly - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -1006,50 +982,46 @@ impl std::convert::TryFrom for header::IntoHeaderValue std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into ArrayOfNumberOnly - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into ArrayOfNumberOnly - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct ArrayTest { #[serde(rename = "array_of_string")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub array_of_string: Option>, #[serde(rename = "array_array_of_integer")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub array_array_of_integer: Option>>, #[serde(rename = "array_array_of_model")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub array_array_of_model: Option>>, -/// Note: inline enums are not fully supported by openapi-generator + /// Note: inline enums are not fully supported by openapi-generator #[serde(rename = "array_of_enum")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub array_of_enum: Option>, - } - impl ArrayTest { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> ArrayTest { @@ -1068,26 +1040,31 @@ impl ArrayTest { impl std::string::ToString for ArrayTest { fn to_string(&self) -> String { let params: Vec> = vec![ - self.array_of_string.as_ref().map(|array_of_string| { [ "array_of_string".to_string(), - array_of_string.iter().map(|x| x.to_string()).collect::>().join(","), - ].join(",") + array_of_string + .iter() + .map(|x| x.to_string()) + .collect::>() + .join(","), + ] + .join(",") }), - // Skipping array_array_of_integer in query parameter serialization // Skipping array_array_of_model in query parameter serialization - - self.array_of_enum.as_ref().map(|array_of_enum| { [ "array_of_enum".to_string(), - array_of_enum.iter().map(|x| x.to_string()).collect::>().join(","), - ].join(",") + array_of_enum + .iter() + .map(|x| x.to_string()) + .collect::>() + .join(","), + ] + .join(",") }), - ]; params.into_iter().flatten().collect::>().join(",") @@ -1120,17 +1097,45 @@ impl std::str::FromStr for ArrayTest { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing ArrayTest".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing ArrayTest".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { - "array_of_string" => return std::result::Result::Err("Parsing a container in this style is not supported in ArrayTest".to_string()), - "array_array_of_integer" => return std::result::Result::Err("Parsing a container in this style is not supported in ArrayTest".to_string()), - "array_array_of_model" => return std::result::Result::Err("Parsing a container in this style is not supported in ArrayTest".to_string()), - "array_of_enum" => return std::result::Result::Err("Parsing a container in this style is not supported in ArrayTest".to_string()), - _ => return std::result::Result::Err("Unexpected key while parsing ArrayTest".to_string()) + "array_of_string" => { + return std::result::Result::Err( + "Parsing a container in this style is not supported in ArrayTest" + .to_string(), + ) + } + "array_array_of_integer" => { + return std::result::Result::Err( + "Parsing a container in this style is not supported in ArrayTest" + .to_string(), + ) + } + "array_array_of_model" => { + return std::result::Result::Err( + "Parsing a container in this style is not supported in ArrayTest" + .to_string(), + ) + } + "array_of_enum" => { + return std::result::Result::Err( + "Parsing a container in this style is not supported in ArrayTest" + .to_string(), + ) + } + _ => { + return std::result::Result::Err( + "Unexpected key while parsing ArrayTest".to_string(), + ) + } } } @@ -1154,13 +1159,16 @@ impl std::str::FromStr for ArrayTest { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for ArrayTest - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for ArrayTest - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -1171,58 +1179,54 @@ impl std::convert::TryFrom for header::IntoHeaderValue { fn try_from(hdr_value: HeaderValue) -> std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into ArrayTest - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into ArrayTest - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct Capitalization { #[serde(rename = "smallCamel")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub small_camel: Option, #[serde(rename = "CapitalCamel")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub capital_camel: Option, #[serde(rename = "small_Snake")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub small_snake: Option, #[serde(rename = "Capital_Snake")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub capital_snake: Option, #[serde(rename = "SCA_ETH_Flow_Points")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub sca_eth_flow_points: Option, -/// Name of the pet + /// Name of the pet #[serde(rename = "ATT_NAME")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub att_name: Option, - } - impl Capitalization { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> Capitalization { @@ -1243,54 +1247,30 @@ impl Capitalization { impl std::string::ToString for Capitalization { fn to_string(&self) -> String { let params: Vec> = vec![ - - self.small_camel.as_ref().map(|small_camel| { - [ - "smallCamel".to_string(), - small_camel.to_string(), - ].join(",") - }), - - + self.small_camel + .as_ref() + .map(|small_camel| ["smallCamel".to_string(), small_camel.to_string()].join(",")), self.capital_camel.as_ref().map(|capital_camel| { - [ - "CapitalCamel".to_string(), - capital_camel.to_string(), - ].join(",") + ["CapitalCamel".to_string(), capital_camel.to_string()].join(",") }), - - - self.small_snake.as_ref().map(|small_snake| { - [ - "small_Snake".to_string(), - small_snake.to_string(), - ].join(",") - }), - - + self.small_snake + .as_ref() + .map(|small_snake| ["small_Snake".to_string(), small_snake.to_string()].join(",")), self.capital_snake.as_ref().map(|capital_snake| { - [ - "Capital_Snake".to_string(), - capital_snake.to_string(), - ].join(",") + ["Capital_Snake".to_string(), capital_snake.to_string()].join(",") }), - - - self.sca_eth_flow_points.as_ref().map(|sca_eth_flow_points| { - [ - "SCA_ETH_Flow_Points".to_string(), - sca_eth_flow_points.to_string(), - ].join(",") - }), - - - self.att_name.as_ref().map(|att_name| { - [ - "ATT_NAME".to_string(), - att_name.to_string(), - ].join(",") - }), - + self.sca_eth_flow_points + .as_ref() + .map(|sca_eth_flow_points| { + [ + "SCA_ETH_Flow_Points".to_string(), + sca_eth_flow_points.to_string(), + ] + .join(",") + }), + self.att_name + .as_ref() + .map(|att_name| ["ATT_NAME".to_string(), att_name.to_string()].join(",")), ]; params.into_iter().flatten().collect::>().join(",") @@ -1325,25 +1305,45 @@ impl std::str::FromStr for Capitalization { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing Capitalization".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing Capitalization".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "smallCamel" => intermediate_rep.small_camel.push(::from_str(val).map_err(|x| x.to_string())?), + "smallCamel" => intermediate_rep.small_camel.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "CapitalCamel" => intermediate_rep.capital_camel.push(::from_str(val).map_err(|x| x.to_string())?), + "CapitalCamel" => intermediate_rep.capital_camel.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "small_Snake" => intermediate_rep.small_snake.push(::from_str(val).map_err(|x| x.to_string())?), + "small_Snake" => intermediate_rep.small_snake.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "Capital_Snake" => intermediate_rep.capital_snake.push(::from_str(val).map_err(|x| x.to_string())?), + "Capital_Snake" => intermediate_rep.capital_snake.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "SCA_ETH_Flow_Points" => intermediate_rep.sca_eth_flow_points.push(::from_str(val).map_err(|x| x.to_string())?), + "SCA_ETH_Flow_Points" => intermediate_rep.sca_eth_flow_points.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "ATT_NAME" => intermediate_rep.att_name.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing Capitalization".to_string()) + "ATT_NAME" => intermediate_rep.att_name.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing Capitalization".to_string(), + ) + } } } @@ -1369,13 +1369,16 @@ impl std::str::FromStr for Capitalization { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for Capitalization - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for Capitalization - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -1386,27 +1389,25 @@ impl std::convert::TryFrom for header::IntoHeaderValue std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into Capitalization - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into Capitalization - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct Cat { @@ -1414,19 +1415,17 @@ pub struct Cat { pub class_name: String, #[serde(rename = "color")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub color: Option, #[serde(rename = "declawed")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub declawed: Option, - } - impl Cat { #[allow(clippy::new_without_default, clippy::too_many_arguments)] - pub fn new(class_name: String, ) -> Cat { + pub fn new(class_name: String) -> Cat { Cat { class_name, color: Some("red".to_string()), @@ -1441,26 +1440,14 @@ impl Cat { impl std::string::ToString for Cat { fn to_string(&self) -> String { let params: Vec> = vec![ - Some("className".to_string()), Some(self.class_name.to_string()), - - - self.color.as_ref().map(|color| { - [ - "color".to_string(), - color.to_string(), - ].join(",") - }), - - - self.declawed.as_ref().map(|declawed| { - [ - "declawed".to_string(), - declawed.to_string(), - ].join(",") - }), - + self.color + .as_ref() + .map(|color| ["color".to_string(), color.to_string()].join(",")), + self.declawed + .as_ref() + .map(|declawed| ["declawed".to_string(), declawed.to_string()].join(",")), ]; params.into_iter().flatten().collect::>().join(",") @@ -1492,19 +1479,31 @@ impl std::str::FromStr for Cat { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing Cat".to_string()) + None => { + return std::result::Result::Err("Missing value while parsing Cat".to_string()) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "className" => intermediate_rep.class_name.push(::from_str(val).map_err(|x| x.to_string())?), + "className" => intermediate_rep.class_name.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "color" => intermediate_rep.color.push(::from_str(val).map_err(|x| x.to_string())?), + "color" => intermediate_rep.color.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "declawed" => intermediate_rep.declawed.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing Cat".to_string()) + "declawed" => intermediate_rep.declawed.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing Cat".to_string(), + ) + } } } @@ -1514,7 +1513,11 @@ impl std::str::FromStr for Cat { // Use the intermediate representation to return the struct std::result::Result::Ok(Cat { - class_name: intermediate_rep.class_name.into_iter().next().ok_or_else(|| "className missing in Cat".to_string())?, + class_name: intermediate_rep + .class_name + .into_iter() + .next() + .ok_or_else(|| "className missing in Cat".to_string())?, color: intermediate_rep.color.into_iter().next(), declawed: intermediate_rep.declawed.into_iter().next(), }) @@ -1530,10 +1533,11 @@ impl std::convert::TryFrom> for HeaderValue { fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for Cat - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for Cat - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -1544,41 +1548,35 @@ impl std::convert::TryFrom for header::IntoHeaderValue { fn try_from(hdr_value: HeaderValue) -> std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into Cat - {}", - value, err)) - } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Ok(value) => match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) + } + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into Cat - {}", + value, err + )), + }, + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct Category { #[serde(rename = "id")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub id: Option, #[serde(rename = "name")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub name: Option, - } - impl Category { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> Category { @@ -1595,22 +1593,12 @@ impl Category { impl std::string::ToString for Category { fn to_string(&self) -> String { let params: Vec> = vec![ - - self.id.as_ref().map(|id| { - [ - "id".to_string(), - id.to_string(), - ].join(",") - }), - - - self.name.as_ref().map(|name| { - [ - "name".to_string(), - name.to_string(), - ].join(",") - }), - + self.id + .as_ref() + .map(|id| ["id".to_string(), id.to_string()].join(",")), + self.name + .as_ref() + .map(|name| ["name".to_string(), name.to_string()].join(",")), ]; params.into_iter().flatten().collect::>().join(",") @@ -1641,17 +1629,29 @@ impl std::str::FromStr for Category { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing Category".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing Category".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "id" => intermediate_rep.id.push(::from_str(val).map_err(|x| x.to_string())?), + "id" => intermediate_rep.id.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "name" => intermediate_rep.name.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing Category".to_string()) + "name" => intermediate_rep.name.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing Category".to_string(), + ) + } } } @@ -1673,13 +1673,16 @@ impl std::str::FromStr for Category { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for Category - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for Category - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -1690,44 +1693,39 @@ impl std::convert::TryFrom for header::IntoHeaderValue { fn try_from(hdr_value: HeaderValue) -> std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into Category - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into Category - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - /// Model for testing model with \"_class\" property - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct ClassModel { #[serde(rename = "_class")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub _class: Option, - } - impl ClassModel { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> ClassModel { - ClassModel { - _class: None, - } + ClassModel { _class: None } } } @@ -1736,16 +1734,10 @@ impl ClassModel { /// Should be implemented in a serde serializer impl std::string::ToString for ClassModel { fn to_string(&self) -> String { - let params: Vec> = vec![ - - self._class.as_ref().map(|_class| { - [ - "_class".to_string(), - _class.to_string(), - ].join(",") - }), - - ]; + let params: Vec> = vec![self + ._class + .as_ref() + .map(|_class| ["_class".to_string(), _class.to_string()].join(","))]; params.into_iter().flatten().collect::>().join(",") } @@ -1774,15 +1766,25 @@ impl std::str::FromStr for ClassModel { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing ClassModel".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing ClassModel".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "_class" => intermediate_rep._class.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing ClassModel".to_string()) + "_class" => intermediate_rep._class.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing ClassModel".to_string(), + ) + } } } @@ -1803,13 +1805,16 @@ impl std::str::FromStr for ClassModel { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for ClassModel - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for ClassModel - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -1820,43 +1825,37 @@ impl std::convert::TryFrom for header::IntoHeaderValue fn try_from(hdr_value: HeaderValue) -> std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into ClassModel - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into ClassModel - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct Client { #[serde(rename = "client")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub client: Option, - } - impl Client { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> Client { - Client { - client: None, - } + Client { client: None } } } @@ -1865,16 +1864,10 @@ impl Client { /// Should be implemented in a serde serializer impl std::string::ToString for Client { fn to_string(&self) -> String { - let params: Vec> = vec![ - - self.client.as_ref().map(|client| { - [ - "client".to_string(), - client.to_string(), - ].join(",") - }), - - ]; + let params: Vec> = vec![self + .client + .as_ref() + .map(|client| ["client".to_string(), client.to_string()].join(","))]; params.into_iter().flatten().collect::>().join(",") } @@ -1903,15 +1896,25 @@ impl std::str::FromStr for Client { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing Client".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing Client".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "client" => intermediate_rep.client.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing Client".to_string()) + "client" => intermediate_rep.client.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing Client".to_string(), + ) + } } } @@ -1932,13 +1935,16 @@ impl std::str::FromStr for Client { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for Client - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for Client - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -1949,27 +1955,25 @@ impl std::convert::TryFrom for header::IntoHeaderValue { fn try_from(hdr_value: HeaderValue) -> std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into Client - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into Client - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct Dog { @@ -1977,19 +1981,17 @@ pub struct Dog { pub class_name: String, #[serde(rename = "color")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub color: Option, #[serde(rename = "breed")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub breed: Option, - } - impl Dog { #[allow(clippy::new_without_default, clippy::too_many_arguments)] - pub fn new(class_name: String, ) -> Dog { + pub fn new(class_name: String) -> Dog { Dog { class_name, color: Some("red".to_string()), @@ -2004,26 +2006,14 @@ impl Dog { impl std::string::ToString for Dog { fn to_string(&self) -> String { let params: Vec> = vec![ - Some("className".to_string()), Some(self.class_name.to_string()), - - - self.color.as_ref().map(|color| { - [ - "color".to_string(), - color.to_string(), - ].join(",") - }), - - - self.breed.as_ref().map(|breed| { - [ - "breed".to_string(), - breed.to_string(), - ].join(",") - }), - + self.color + .as_ref() + .map(|color| ["color".to_string(), color.to_string()].join(",")), + self.breed + .as_ref() + .map(|breed| ["breed".to_string(), breed.to_string()].join(",")), ]; params.into_iter().flatten().collect::>().join(",") @@ -2055,19 +2045,31 @@ impl std::str::FromStr for Dog { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing Dog".to_string()) + None => { + return std::result::Result::Err("Missing value while parsing Dog".to_string()) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "className" => intermediate_rep.class_name.push(::from_str(val).map_err(|x| x.to_string())?), + "className" => intermediate_rep.class_name.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "color" => intermediate_rep.color.push(::from_str(val).map_err(|x| x.to_string())?), + "color" => intermediate_rep.color.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "breed" => intermediate_rep.breed.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing Dog".to_string()) + "breed" => intermediate_rep.breed.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing Dog".to_string(), + ) + } } } @@ -2077,7 +2079,11 @@ impl std::str::FromStr for Dog { // Use the intermediate representation to return the struct std::result::Result::Ok(Dog { - class_name: intermediate_rep.class_name.into_iter().next().ok_or_else(|| "className missing in Dog".to_string())?, + class_name: intermediate_rep + .class_name + .into_iter() + .next() + .ok_or_else(|| "className missing in Dog".to_string())?, color: intermediate_rep.color.into_iter().next(), breed: intermediate_rep.breed.into_iter().next(), }) @@ -2093,10 +2099,11 @@ impl std::convert::TryFrom> for HeaderValue { fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for Dog - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for Dog - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -2107,37 +2114,31 @@ impl std::convert::TryFrom for header::IntoHeaderValue { fn try_from(hdr_value: HeaderValue) -> std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into Dog - {}", - value, err)) - } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Ok(value) => match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) + } + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into Dog - {}", + value, err + )), + }, + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct DollarSpecialLeftSquareBracketModelPeriodNameRightSquareBracket { #[serde(rename = "$special[property.name]")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub dollar_special_left_square_bracket_property_period_name_right_square_bracket: Option, - } - impl DollarSpecialLeftSquareBracketModelPeriodNameRightSquareBracket { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> DollarSpecialLeftSquareBracketModelPeriodNameRightSquareBracket { @@ -2178,7 +2179,8 @@ impl std::str::FromStr for DollarSpecialLeftSquareBracketModelPeriodNameRightSqu #[derive(Default)] #[allow(dead_code)] struct IntermediateRep { - pub dollar_special_left_square_bracket_property_period_name_right_square_bracket: Vec, + pub dollar_special_left_square_bracket_property_period_name_right_square_bracket: + Vec, } let mut intermediate_rep = IntermediateRep::default(); @@ -2216,10 +2218,18 @@ impl std::str::FromStr for DollarSpecialLeftSquareBracketModelPeriodNameRightSqu // Methods for converting between header::IntoHeaderValue and HeaderValue #[cfg(feature = "server")] -impl std::convert::TryFrom> for HeaderValue { +impl + std::convert::TryFrom< + header::IntoHeaderValue, + > for HeaderValue +{ type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue< + DollarSpecialLeftSquareBracketModelPeriodNameRightSquareBracket, + >, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), @@ -2231,7 +2241,9 @@ impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom + for header::IntoHeaderValue +{ type Error = String; fn try_from(hdr_value: HeaderValue) -> std::result::Result { @@ -2251,33 +2263,25 @@ impl std::convert::TryFrom for header::IntoHeaderValue, -/// Note: inline enums are not fully supported by openapi-generator + /// Note: inline enums are not fully supported by openapi-generator #[serde(rename = "array_enum")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub array_enum: Option>, -/// Note: inline enums are not fully supported by openapi-generator + /// Note: inline enums are not fully supported by openapi-generator #[serde(rename = "array_array_enum")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub array_array_enum: Option>>, - } - impl EnumArrays { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> EnumArrays { @@ -2295,24 +2299,21 @@ impl EnumArrays { impl std::string::ToString for EnumArrays { fn to_string(&self) -> String { let params: Vec> = vec![ - - self.just_symbol.as_ref().map(|just_symbol| { - [ - "just_symbol".to_string(), - just_symbol.to_string(), - ].join(",") - }), - - + self.just_symbol + .as_ref() + .map(|just_symbol| ["just_symbol".to_string(), just_symbol.to_string()].join(",")), self.array_enum.as_ref().map(|array_enum| { [ "array_enum".to_string(), - array_enum.iter().map(|x| x.to_string()).collect::>().join(","), - ].join(",") + array_enum + .iter() + .map(|x| x.to_string()) + .collect::>() + .join(","), + ] + .join(",") }), - // Skipping array_array_enum in query parameter serialization - ]; params.into_iter().flatten().collect::>().join(",") @@ -2344,17 +2345,37 @@ impl std::str::FromStr for EnumArrays { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing EnumArrays".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing EnumArrays".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "just_symbol" => intermediate_rep.just_symbol.push(::from_str(val).map_err(|x| x.to_string())?), - "array_enum" => return std::result::Result::Err("Parsing a container in this style is not supported in EnumArrays".to_string()), - "array_array_enum" => return std::result::Result::Err("Parsing a container in this style is not supported in EnumArrays".to_string()), - _ => return std::result::Result::Err("Unexpected key while parsing EnumArrays".to_string()) + "just_symbol" => intermediate_rep.just_symbol.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + "array_enum" => { + return std::result::Result::Err( + "Parsing a container in this style is not supported in EnumArrays" + .to_string(), + ) + } + "array_array_enum" => { + return std::result::Result::Err( + "Parsing a container in this style is not supported in EnumArrays" + .to_string(), + ) + } + _ => { + return std::result::Result::Err( + "Unexpected key while parsing EnumArrays".to_string(), + ) + } } } @@ -2377,13 +2398,16 @@ impl std::str::FromStr for EnumArrays { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for EnumArrays - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for EnumArrays - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -2394,30 +2418,33 @@ impl std::convert::TryFrom for header::IntoHeaderValue fn try_from(hdr_value: HeaderValue) -> std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into EnumArrays - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into EnumArrays - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - /// Enumeration of values. /// Since this enum's variants do not hold data, we can easily define them as `#[repr(C)]` /// which helps with FFI. #[allow(non_camel_case_types)] #[repr(C)] -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize)] +#[derive( + Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize, +)] #[cfg_attr(feature = "conversion", derive(frunk_enum_derive::LabelledGenericEnum))] pub enum EnumClass { #[serde(rename = "_abc")] @@ -2451,42 +2478,36 @@ impl std::str::FromStr for EnumClass { } } - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct EnumTest { -/// Note: inline enums are not fully supported by openapi-generator + /// Note: inline enums are not fully supported by openapi-generator #[serde(rename = "enum_string")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub enum_string: Option, -/// Note: inline enums are not fully supported by openapi-generator + /// Note: inline enums are not fully supported by openapi-generator #[serde(rename = "enum_string_required")] pub enum_string_required: String, -/// Note: inline enums are not fully supported by openapi-generator + /// Note: inline enums are not fully supported by openapi-generator #[serde(rename = "enum_integer")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub enum_integer: Option, -/// Note: inline enums are not fully supported by openapi-generator + /// Note: inline enums are not fully supported by openapi-generator #[serde(rename = "enum_number")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub enum_number: Option, #[serde(rename = "outerEnum")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub outer_enum: Option, - } - impl EnumTest { #[allow(clippy::new_without_default, clippy::too_many_arguments)] - pub fn new(enum_string_required: String, ) -> EnumTest { + pub fn new(enum_string_required: String) -> EnumTest { EnumTest { enum_string: None, enum_string_required, @@ -2503,36 +2524,18 @@ impl EnumTest { impl std::string::ToString for EnumTest { fn to_string(&self) -> String { let params: Vec> = vec![ - - self.enum_string.as_ref().map(|enum_string| { - [ - "enum_string".to_string(), - enum_string.to_string(), - ].join(",") - }), - - + self.enum_string + .as_ref() + .map(|enum_string| ["enum_string".to_string(), enum_string.to_string()].join(",")), Some("enum_string_required".to_string()), Some(self.enum_string_required.to_string()), - - self.enum_integer.as_ref().map(|enum_integer| { - [ - "enum_integer".to_string(), - enum_integer.to_string(), - ].join(",") + ["enum_integer".to_string(), enum_integer.to_string()].join(",") }), - - - self.enum_number.as_ref().map(|enum_number| { - [ - "enum_number".to_string(), - enum_number.to_string(), - ].join(",") - }), - + self.enum_number + .as_ref() + .map(|enum_number| ["enum_number".to_string(), enum_number.to_string()].join(",")), // Skipping outerEnum in query parameter serialization - ]; params.into_iter().flatten().collect::>().join(",") @@ -2566,23 +2569,42 @@ impl std::str::FromStr for EnumTest { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing EnumTest".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing EnumTest".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "enum_string" => intermediate_rep.enum_string.push(::from_str(val).map_err(|x| x.to_string())?), + "enum_string" => intermediate_rep.enum_string.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "enum_string_required" => intermediate_rep.enum_string_required.push(::from_str(val).map_err(|x| x.to_string())?), + "enum_string_required" => intermediate_rep.enum_string_required.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "enum_integer" => intermediate_rep.enum_integer.push(::from_str(val).map_err(|x| x.to_string())?), + "enum_integer" => intermediate_rep.enum_integer.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "enum_number" => intermediate_rep.enum_number.push(::from_str(val).map_err(|x| x.to_string())?), + "enum_number" => intermediate_rep.enum_number.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "outerEnum" => intermediate_rep.outer_enum.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing EnumTest".to_string()) + "outerEnum" => intermediate_rep.outer_enum.push( + ::from_str(val) + .map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing EnumTest".to_string(), + ) + } } } @@ -2593,7 +2615,11 @@ impl std::str::FromStr for EnumTest { // Use the intermediate representation to return the struct std::result::Result::Ok(EnumTest { enum_string: intermediate_rep.enum_string.into_iter().next(), - enum_string_required: intermediate_rep.enum_string_required.into_iter().next().ok_or_else(|| "enum_string_required missing in EnumTest".to_string())?, + enum_string_required: intermediate_rep + .enum_string_required + .into_iter() + .next() + .ok_or_else(|| "enum_string_required missing in EnumTest".to_string())?, enum_integer: intermediate_rep.enum_integer.into_iter().next(), enum_number: intermediate_rep.enum_number.into_iter().next(), outer_enum: intermediate_rep.outer_enum.into_iter().next(), @@ -2607,13 +2633,16 @@ impl std::str::FromStr for EnumTest { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for EnumTest - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for EnumTest - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -2624,102 +2653,83 @@ impl std::convert::TryFrom for header::IntoHeaderValue { fn try_from(hdr_value: HeaderValue) -> std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into EnumTest - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into EnumTest - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct FormatTest { #[serde(rename = "integer")] - #[validate( - range(min = 10, max = 100), - )] - #[serde(skip_serializing_if="Option::is_none")] + #[validate(range(min = 10, max = 100))] + #[serde(skip_serializing_if = "Option::is_none")] pub integer: Option, #[serde(rename = "int32")] - #[validate( - range(min = 20, max = 200), - )] - #[serde(skip_serializing_if="Option::is_none")] - pub int32: Option, + #[validate(range(min = 20, max = 200))] + #[serde(skip_serializing_if = "Option::is_none")] + pub int32: Option, #[serde(rename = "int64")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub int64: Option, #[serde(rename = "number")] - #[validate( - range(min = 32.1, max = 543.2), - )] + #[validate(range(min = 32.1, max = 543.2))] pub number: f64, #[serde(rename = "float")] - #[validate( - range(min = 54.3, max = 987.6), - )] - #[serde(skip_serializing_if="Option::is_none")] + #[validate(range(min = 54.3, max = 987.6))] + #[serde(skip_serializing_if = "Option::is_none")] pub float: Option, #[serde(rename = "double")] - #[validate( - range(min = 67.8, max = 123.4), - )] - #[serde(skip_serializing_if="Option::is_none")] + #[validate(range(min = 67.8, max = 123.4))] + #[serde(skip_serializing_if = "Option::is_none")] pub double: Option, #[serde(rename = "string")] - #[validate( - regex = "RE_FORMATTEST_STRING", - )] - #[serde(skip_serializing_if="Option::is_none")] + #[validate(regex = "RE_FORMATTEST_STRING")] + #[serde(skip_serializing_if = "Option::is_none")] pub string: Option, #[serde(rename = "byte")] - #[validate( - custom ="validate_byte_formattest_byte" - )] + #[validate(custom = "validate_byte_formattest_byte")] pub byte: ByteArray, #[serde(rename = "binary")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub binary: Option, #[serde(rename = "date")] pub date: chrono::naive::NaiveDate, #[serde(rename = "dateTime")] - #[serde(skip_serializing_if="Option::is_none")] - pub date_time: Option>, + #[serde(skip_serializing_if = "Option::is_none")] + pub date_time: Option>, #[serde(rename = "uuid")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub uuid: Option, #[serde(rename = "password")] - #[validate( - length(min = 10, max = 64), - )] + #[validate(length(min = 10, max = 64))] pub password: String, - } lazy_static::lazy_static! { @@ -2729,7 +2739,7 @@ lazy_static::lazy_static! { static ref RE_FORMATTEST_BYTE: regex::bytes::Regex = regex::bytes::Regex::new(r"^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$").unwrap(); } fn validate_byte_formattest_byte( - b: &ByteArray + b: &ByteArray, ) -> std::result::Result<(), validator::ValidationError> { if !RE_FORMATTEST_BYTE.is_match(&b.0) { return Err(validator::ValidationError::new("Character not allowed")); @@ -2739,7 +2749,12 @@ fn validate_byte_formattest_byte( impl FormatTest { #[allow(clippy::new_without_default, clippy::too_many_arguments)] - pub fn new(number: f64, byte: ByteArray, date: chrono::naive::NaiveDate, password: String, ) -> FormatTest { + pub fn new( + number: f64, + byte: ByteArray, + date: chrono::naive::NaiveDate, + password: String, + ) -> FormatTest { FormatTest { integer: None, int32: None, @@ -2764,58 +2779,26 @@ impl FormatTest { impl std::string::ToString for FormatTest { fn to_string(&self) -> String { let params: Vec> = vec![ - - self.integer.as_ref().map(|integer| { - [ - "integer".to_string(), - integer.to_string(), - ].join(",") - }), - - - self.int32.as_ref().map(|int32| { - [ - "int32".to_string(), - int32.to_string(), - ].join(",") - }), - - - self.int64.as_ref().map(|int64| { - [ - "int64".to_string(), - int64.to_string(), - ].join(",") - }), - - + self.integer + .as_ref() + .map(|integer| ["integer".to_string(), integer.to_string()].join(",")), + self.int32 + .as_ref() + .map(|int32| ["int32".to_string(), int32.to_string()].join(",")), + self.int64 + .as_ref() + .map(|int64| ["int64".to_string(), int64.to_string()].join(",")), Some("number".to_string()), Some(self.number.to_string()), - - - self.float.as_ref().map(|float| { - [ - "float".to_string(), - float.to_string(), - ].join(",") - }), - - - self.double.as_ref().map(|double| { - [ - "double".to_string(), - double.to_string(), - ].join(",") - }), - - - self.string.as_ref().map(|string| { - [ - "string".to_string(), - string.to_string(), - ].join(",") - }), - + self.float + .as_ref() + .map(|float| ["float".to_string(), float.to_string()].join(",")), + self.double + .as_ref() + .map(|double| ["double".to_string(), double.to_string()].join(",")), + self.string + .as_ref() + .map(|string| ["string".to_string(), string.to_string()].join(",")), // Skipping byte in query parameter serialization // Skipping byte in query parameter serialization @@ -2827,11 +2810,8 @@ impl std::string::ToString for FormatTest { // Skipping dateTime in query parameter serialization // Skipping uuid in query parameter serialization - - Some("password".to_string()), Some(self.password.to_string()), - ]; params.into_iter().flatten().collect::>().join(",") @@ -2850,7 +2830,7 @@ impl std::str::FromStr for FormatTest { #[allow(dead_code)] struct IntermediateRep { pub integer: Vec, - pub int32: Vec, + pub int32: Vec, pub int64: Vec, pub number: Vec, pub float: Vec, @@ -2859,7 +2839,7 @@ impl std::str::FromStr for FormatTest { pub byte: Vec, pub binary: Vec, pub date: Vec, - pub date_time: Vec>, + pub date_time: Vec>, pub uuid: Vec, pub password: Vec, } @@ -2873,37 +2853,80 @@ impl std::str::FromStr for FormatTest { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing FormatTest".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing FormatTest".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "integer" => intermediate_rep.integer.push(::from_str(val).map_err(|x| x.to_string())?), + "integer" => intermediate_rep + .integer + .push(::from_str(val).map_err(|x| x.to_string())?), #[allow(clippy::redundant_clone)] - "int32" => intermediate_rep.int32.push(::from_str(val).map_err(|x| x.to_string())?), + "int32" => intermediate_rep + .int32 + .push(::from_str(val).map_err(|x| x.to_string())?), #[allow(clippy::redundant_clone)] - "int64" => intermediate_rep.int64.push(::from_str(val).map_err(|x| x.to_string())?), + "int64" => intermediate_rep.int64.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "number" => intermediate_rep.number.push(::from_str(val).map_err(|x| x.to_string())?), + "number" => intermediate_rep.number.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "float" => intermediate_rep.float.push(::from_str(val).map_err(|x| x.to_string())?), + "float" => intermediate_rep.float.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "double" => intermediate_rep.double.push(::from_str(val).map_err(|x| x.to_string())?), + "double" => intermediate_rep.double.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "string" => intermediate_rep.string.push(::from_str(val).map_err(|x| x.to_string())?), - "byte" => return std::result::Result::Err("Parsing binary data in this style is not supported in FormatTest".to_string()), - "binary" => return std::result::Result::Err("Parsing binary data in this style is not supported in FormatTest".to_string()), + "string" => intermediate_rep.string.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + "byte" => { + return std::result::Result::Err( + "Parsing binary data in this style is not supported in FormatTest" + .to_string(), + ) + } + "binary" => { + return std::result::Result::Err( + "Parsing binary data in this style is not supported in FormatTest" + .to_string(), + ) + } #[allow(clippy::redundant_clone)] - "date" => intermediate_rep.date.push(::from_str(val).map_err(|x| x.to_string())?), + "date" => intermediate_rep.date.push( + ::from_str(val) + .map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "dateTime" => intermediate_rep.date_time.push( as std::str::FromStr>::from_str(val).map_err(|x| x.to_string())?), + "dateTime" => intermediate_rep.date_time.push( + as std::str::FromStr>::from_str(val) + .map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "uuid" => intermediate_rep.uuid.push(::from_str(val).map_err(|x| x.to_string())?), + "uuid" => intermediate_rep.uuid.push( + ::from_str(val) + .map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "password" => intermediate_rep.password.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing FormatTest".to_string()) + "password" => intermediate_rep.password.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing FormatTest".to_string(), + ) + } } } @@ -2916,16 +2939,32 @@ impl std::str::FromStr for FormatTest { integer: intermediate_rep.integer.into_iter().next(), int32: intermediate_rep.int32.into_iter().next(), int64: intermediate_rep.int64.into_iter().next(), - number: intermediate_rep.number.into_iter().next().ok_or_else(|| "number missing in FormatTest".to_string())?, + number: intermediate_rep + .number + .into_iter() + .next() + .ok_or_else(|| "number missing in FormatTest".to_string())?, float: intermediate_rep.float.into_iter().next(), double: intermediate_rep.double.into_iter().next(), string: intermediate_rep.string.into_iter().next(), - byte: intermediate_rep.byte.into_iter().next().ok_or_else(|| "byte missing in FormatTest".to_string())?, + byte: intermediate_rep + .byte + .into_iter() + .next() + .ok_or_else(|| "byte missing in FormatTest".to_string())?, binary: intermediate_rep.binary.into_iter().next(), - date: intermediate_rep.date.into_iter().next().ok_or_else(|| "date missing in FormatTest".to_string())?, + date: intermediate_rep + .date + .into_iter() + .next() + .ok_or_else(|| "date missing in FormatTest".to_string())?, date_time: intermediate_rep.date_time.into_iter().next(), uuid: intermediate_rep.uuid.into_iter().next(), - password: intermediate_rep.password.into_iter().next().ok_or_else(|| "password missing in FormatTest".to_string())?, + password: intermediate_rep + .password + .into_iter() + .next() + .ok_or_else(|| "password missing in FormatTest".to_string())?, }) } } @@ -2936,13 +2975,16 @@ impl std::str::FromStr for FormatTest { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for FormatTest - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for FormatTest - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -2953,41 +2995,37 @@ impl std::convert::TryFrom for header::IntoHeaderValue fn try_from(hdr_value: HeaderValue) -> std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into FormatTest - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into FormatTest - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct HasOnlyReadOnly { #[serde(rename = "bar")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub bar: Option, #[serde(rename = "foo")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub foo: Option, - } - impl HasOnlyReadOnly { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> HasOnlyReadOnly { @@ -3004,22 +3042,12 @@ impl HasOnlyReadOnly { impl std::string::ToString for HasOnlyReadOnly { fn to_string(&self) -> String { let params: Vec> = vec![ - - self.bar.as_ref().map(|bar| { - [ - "bar".to_string(), - bar.to_string(), - ].join(",") - }), - - - self.foo.as_ref().map(|foo| { - [ - "foo".to_string(), - foo.to_string(), - ].join(",") - }), - + self.bar + .as_ref() + .map(|bar| ["bar".to_string(), bar.to_string()].join(",")), + self.foo + .as_ref() + .map(|foo| ["foo".to_string(), foo.to_string()].join(",")), ]; params.into_iter().flatten().collect::>().join(",") @@ -3050,17 +3078,29 @@ impl std::str::FromStr for HasOnlyReadOnly { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing HasOnlyReadOnly".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing HasOnlyReadOnly".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "bar" => intermediate_rep.bar.push(::from_str(val).map_err(|x| x.to_string())?), + "bar" => intermediate_rep.bar.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "foo" => intermediate_rep.foo.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing HasOnlyReadOnly".to_string()) + "foo" => intermediate_rep.foo.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing HasOnlyReadOnly".to_string(), + ) + } } } @@ -3082,13 +3122,16 @@ impl std::str::FromStr for HasOnlyReadOnly { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for HasOnlyReadOnly - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for HasOnlyReadOnly - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -3099,37 +3142,33 @@ impl std::convert::TryFrom for header::IntoHeaderValue std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into HasOnlyReadOnly - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into HasOnlyReadOnly - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct List { #[serde(rename = "123-list")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub param_123_list: Option, - } - impl List { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> List { @@ -3144,16 +3183,10 @@ impl List { /// Should be implemented in a serde serializer impl std::string::ToString for List { fn to_string(&self) -> String { - let params: Vec> = vec![ - - self.param_123_list.as_ref().map(|param_123_list| { - [ - "123-list".to_string(), - param_123_list.to_string(), - ].join(",") - }), - - ]; + let params: Vec> = vec![self + .param_123_list + .as_ref() + .map(|param_123_list| ["123-list".to_string(), param_123_list.to_string()].join(","))]; params.into_iter().flatten().collect::>().join(",") } @@ -3182,15 +3215,23 @@ impl std::str::FromStr for List { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing List".to_string()) + None => { + return std::result::Result::Err("Missing value while parsing List".to_string()) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "123-list" => intermediate_rep.param_123_list.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing List".to_string()) + "123-list" => intermediate_rep.param_123_list.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing List".to_string(), + ) + } } } @@ -3211,13 +3252,16 @@ impl std::str::FromStr for List { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for List - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for List - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -3228,47 +3272,43 @@ impl std::convert::TryFrom for header::IntoHeaderValue { fn try_from(hdr_value: HeaderValue) -> std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into List - {}", - value, err)) - } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Ok(value) => match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) + } + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into List - {}", + value, err + )), + }, + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct MapTest { #[serde(rename = "map_map_of_string")] - #[serde(skip_serializing_if="Option::is_none")] - pub map_map_of_string: Option>>, + #[serde(skip_serializing_if = "Option::is_none")] + pub map_map_of_string: + Option>>, -/// Note: inline enums are not fully supported by openapi-generator + /// Note: inline enums are not fully supported by openapi-generator #[serde(rename = "map_map_of_enum")] - #[serde(skip_serializing_if="Option::is_none")] - pub map_map_of_enum: Option>>, + #[serde(skip_serializing_if = "Option::is_none")] + pub map_map_of_enum: + Option>>, -/// Note: inline enums are not fully supported by openapi-generator + /// Note: inline enums are not fully supported by openapi-generator #[serde(rename = "map_of_enum_string")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub map_of_enum_string: Option>, - } - impl MapTest { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> MapTest { @@ -3311,8 +3351,10 @@ impl std::str::FromStr for MapTest { #[derive(Default)] #[allow(dead_code)] struct IntermediateRep { - pub map_map_of_string: Vec>>, - pub map_map_of_enum: Vec>>, + pub map_map_of_string: + Vec>>, + pub map_map_of_enum: + Vec>>, pub map_of_enum_string: Vec>, } @@ -3325,16 +3367,39 @@ impl std::str::FromStr for MapTest { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing MapTest".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing MapTest".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { - "map_map_of_string" => return std::result::Result::Err("Parsing a container in this style is not supported in MapTest".to_string()), - "map_map_of_enum" => return std::result::Result::Err("Parsing a container in this style is not supported in MapTest".to_string()), - "map_of_enum_string" => return std::result::Result::Err("Parsing a container in this style is not supported in MapTest".to_string()), - _ => return std::result::Result::Err("Unexpected key while parsing MapTest".to_string()) + "map_map_of_string" => { + return std::result::Result::Err( + "Parsing a container in this style is not supported in MapTest" + .to_string(), + ) + } + "map_map_of_enum" => { + return std::result::Result::Err( + "Parsing a container in this style is not supported in MapTest" + .to_string(), + ) + } + "map_of_enum_string" => { + return std::result::Result::Err( + "Parsing a container in this style is not supported in MapTest" + .to_string(), + ) + } + _ => { + return std::result::Result::Err( + "Unexpected key while parsing MapTest".to_string(), + ) + } } } @@ -3357,13 +3422,16 @@ impl std::str::FromStr for MapTest { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for MapTest - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for MapTest - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -3374,45 +3442,41 @@ impl std::convert::TryFrom for header::IntoHeaderValue { fn try_from(hdr_value: HeaderValue) -> std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into MapTest - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into MapTest - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct MixedPropertiesAndAdditionalPropertiesClass { #[serde(rename = "uuid")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub uuid: Option, #[serde(rename = "dateTime")] - #[serde(skip_serializing_if="Option::is_none")] - pub date_time: Option>, + #[serde(skip_serializing_if = "Option::is_none")] + pub date_time: Option>, #[serde(rename = "map")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub map: Option>, - } - impl MixedPropertiesAndAdditionalPropertiesClass { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> MixedPropertiesAndAdditionalPropertiesClass { @@ -3455,7 +3519,7 @@ impl std::str::FromStr for MixedPropertiesAndAdditionalPropertiesClass { #[allow(dead_code)] struct IntermediateRep { pub uuid: Vec, - pub date_time: Vec>, + pub date_time: Vec>, pub map: Vec>, } @@ -3466,10 +3530,14 @@ impl std::str::FromStr for MixedPropertiesAndAdditionalPropertiesClass { let mut key_result = string_iter.next(); while key_result.is_some() { - let val = match string_iter.next() { - Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing MixedPropertiesAndAdditionalPropertiesClass".to_string()) - }; + let val = + match string_iter.next() { + Some(x) => x, + None => return std::result::Result::Err( + "Missing value while parsing MixedPropertiesAndAdditionalPropertiesClass" + .to_string(), + ), + }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] @@ -3499,10 +3567,14 @@ impl std::str::FromStr for MixedPropertiesAndAdditionalPropertiesClass { // Methods for converting between header::IntoHeaderValue and HeaderValue #[cfg(feature = "server")] -impl std::convert::TryFrom> for HeaderValue { +impl std::convert::TryFrom> + for HeaderValue +{ type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), @@ -3514,7 +3586,9 @@ impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom + for header::IntoHeaderValue +{ type Error = String; fn try_from(hdr_value: HeaderValue) -> std::result::Result { @@ -3534,27 +3608,20 @@ impl std::convert::TryFrom for header::IntoHeaderValue, #[serde(rename = "class")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub class: Option, - } - impl Model200Response { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> Model200Response { @@ -3571,22 +3638,12 @@ impl Model200Response { impl std::string::ToString for Model200Response { fn to_string(&self) -> String { let params: Vec> = vec![ - - self.name.as_ref().map(|name| { - [ - "name".to_string(), - name.to_string(), - ].join(",") - }), - - - self.class.as_ref().map(|class| { - [ - "class".to_string(), - class.to_string(), - ].join(",") - }), - + self.name + .as_ref() + .map(|name| ["name".to_string(), name.to_string()].join(",")), + self.class + .as_ref() + .map(|class| ["class".to_string(), class.to_string()].join(",")), ]; params.into_iter().flatten().collect::>().join(",") @@ -3617,17 +3674,29 @@ impl std::str::FromStr for Model200Response { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing Model200Response".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing Model200Response".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "name" => intermediate_rep.name.push(::from_str(val).map_err(|x| x.to_string())?), + "name" => intermediate_rep.name.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "class" => intermediate_rep.class.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing Model200Response".to_string()) + "class" => intermediate_rep.class.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing Model200Response".to_string(), + ) + } } } @@ -3649,13 +3718,16 @@ impl std::str::FromStr for Model200Response { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for Model200Response - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for Model200Response - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -3666,28 +3738,27 @@ impl std::convert::TryFrom for header::IntoHeaderValue std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into Model200Response - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into Model200Response - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - /// Model for testing model name same as property name - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct Name { @@ -3695,23 +3766,21 @@ pub struct Name { pub name: i32, #[serde(rename = "snake_case")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub snake_case: Option, #[serde(rename = "property")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub property: Option, #[serde(rename = "123Number")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub param_123_number: Option, - } - impl Name { #[allow(clippy::new_without_default, clippy::too_many_arguments)] - pub fn new(name: i32, ) -> Name { + pub fn new(name: i32) -> Name { Name { name, snake_case: None, @@ -3727,34 +3796,17 @@ impl Name { impl std::string::ToString for Name { fn to_string(&self) -> String { let params: Vec> = vec![ - Some("name".to_string()), Some(self.name.to_string()), - - - self.snake_case.as_ref().map(|snake_case| { - [ - "snake_case".to_string(), - snake_case.to_string(), - ].join(",") - }), - - - self.property.as_ref().map(|property| { - [ - "property".to_string(), - property.to_string(), - ].join(",") - }), - - + self.snake_case + .as_ref() + .map(|snake_case| ["snake_case".to_string(), snake_case.to_string()].join(",")), + self.property + .as_ref() + .map(|property| ["property".to_string(), property.to_string()].join(",")), self.param_123_number.as_ref().map(|param_123_number| { - [ - "123Number".to_string(), - param_123_number.to_string(), - ].join(",") + ["123Number".to_string(), param_123_number.to_string()].join(",") }), - ]; params.into_iter().flatten().collect::>().join(",") @@ -3787,21 +3839,35 @@ impl std::str::FromStr for Name { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing Name".to_string()) + None => { + return std::result::Result::Err("Missing value while parsing Name".to_string()) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "name" => intermediate_rep.name.push(::from_str(val).map_err(|x| x.to_string())?), + "name" => intermediate_rep.name.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "snake_case" => intermediate_rep.snake_case.push(::from_str(val).map_err(|x| x.to_string())?), + "snake_case" => intermediate_rep.snake_case.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "property" => intermediate_rep.property.push(::from_str(val).map_err(|x| x.to_string())?), + "property" => intermediate_rep.property.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "123Number" => intermediate_rep.param_123_number.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing Name".to_string()) + "123Number" => intermediate_rep.param_123_number.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing Name".to_string(), + ) + } } } @@ -3811,7 +3877,11 @@ impl std::str::FromStr for Name { // Use the intermediate representation to return the struct std::result::Result::Ok(Name { - name: intermediate_rep.name.into_iter().next().ok_or_else(|| "name missing in Name".to_string())?, + name: intermediate_rep + .name + .into_iter() + .next() + .ok_or_else(|| "name missing in Name".to_string())?, snake_case: intermediate_rep.snake_case.into_iter().next(), property: intermediate_rep.property.into_iter().next(), param_123_number: intermediate_rep.param_123_number.into_iter().next(), @@ -3825,13 +3895,16 @@ impl std::str::FromStr for Name { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for Name - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for Name - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -3842,43 +3915,35 @@ impl std::convert::TryFrom for header::IntoHeaderValue { fn try_from(hdr_value: HeaderValue) -> std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into Name - {}", - value, err)) - } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Ok(value) => match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) + } + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into Name - {}", + value, err + )), + }, + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct NumberOnly { #[serde(rename = "JustNumber")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub just_number: Option, - } - impl NumberOnly { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> NumberOnly { - NumberOnly { - just_number: None, - } + NumberOnly { just_number: None } } } @@ -3887,16 +3952,10 @@ impl NumberOnly { /// Should be implemented in a serde serializer impl std::string::ToString for NumberOnly { fn to_string(&self) -> String { - let params: Vec> = vec![ - - self.just_number.as_ref().map(|just_number| { - [ - "JustNumber".to_string(), - just_number.to_string(), - ].join(",") - }), - - ]; + let params: Vec> = vec![self + .just_number + .as_ref() + .map(|just_number| ["JustNumber".to_string(), just_number.to_string()].join(","))]; params.into_iter().flatten().collect::>().join(",") } @@ -3925,15 +3984,25 @@ impl std::str::FromStr for NumberOnly { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing NumberOnly".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing NumberOnly".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "JustNumber" => intermediate_rep.just_number.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing NumberOnly".to_string()) + "JustNumber" => intermediate_rep.just_number.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing NumberOnly".to_string(), + ) + } } } @@ -3954,13 +4023,16 @@ impl std::str::FromStr for NumberOnly { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for NumberOnly - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for NumberOnly - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -3971,43 +4043,37 @@ impl std::convert::TryFrom for header::IntoHeaderValue fn try_from(hdr_value: HeaderValue) -> std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into NumberOnly - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into NumberOnly - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct ObjectContainingObjectWithOnlyAdditionalProperties { #[serde(rename = "inner")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub inner: Option, - } - impl ObjectContainingObjectWithOnlyAdditionalProperties { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> ObjectContainingObjectWithOnlyAdditionalProperties { - ObjectContainingObjectWithOnlyAdditionalProperties { - inner: None, - } + ObjectContainingObjectWithOnlyAdditionalProperties { inner: None } } } @@ -4074,10 +4140,16 @@ impl std::str::FromStr for ObjectContainingObjectWithOnlyAdditionalProperties { // Methods for converting between header::IntoHeaderValue and HeaderValue #[cfg(feature = "server")] -impl std::convert::TryFrom> for HeaderValue { +impl + std::convert::TryFrom< + header::IntoHeaderValue, + > for HeaderValue +{ type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), @@ -4089,7 +4161,9 @@ impl std::convert::TryFrom for header::IntoHeaderValue { +impl std::convert::TryFrom + for header::IntoHeaderValue +{ type Error = String; fn try_from(hdr_value: HeaderValue) -> std::result::Result { @@ -4109,9 +4183,6 @@ impl std::convert::TryFrom for header::IntoHeaderValue); @@ -4122,13 +4193,17 @@ impl validator::Validate for ObjectWithOnlyAdditionalProperties { } } -impl std::convert::From> for ObjectWithOnlyAdditionalProperties { +impl std::convert::From> + for ObjectWithOnlyAdditionalProperties +{ fn from(x: std::collections::HashMap) -> Self { ObjectWithOnlyAdditionalProperties(x) } } -impl std::convert::From for std::collections::HashMap { +impl std::convert::From + for std::collections::HashMap +{ fn from(x: ObjectWithOnlyAdditionalProperties) -> Self { x.0 } @@ -4164,46 +4239,42 @@ impl ::std::str::FromStr for ObjectWithOnlyAdditionalProperties { type Err = &'static str; fn from_str(s: &str) -> std::result::Result { - std::result::Result::Err("Parsing additionalProperties for ObjectWithOnlyAdditionalProperties is not supported") + std::result::Result::Err( + "Parsing additionalProperties for ObjectWithOnlyAdditionalProperties is not supported", + ) } } - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct Order { #[serde(rename = "id")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub id: Option, #[serde(rename = "petId")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub pet_id: Option, #[serde(rename = "quantity")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub quantity: Option, #[serde(rename = "shipDate")] - #[serde(skip_serializing_if="Option::is_none")] - pub ship_date: Option>, + #[serde(skip_serializing_if = "Option::is_none")] + pub ship_date: Option>, -/// Order Status -/// Note: inline enums are not fully supported by openapi-generator + /// Order Status + /// Note: inline enums are not fully supported by openapi-generator #[serde(rename = "status")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub status: Option, #[serde(rename = "complete")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub complete: Option, - } - impl Order { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> Order { @@ -4224,48 +4295,22 @@ impl Order { impl std::string::ToString for Order { fn to_string(&self) -> String { let params: Vec> = vec![ - - self.id.as_ref().map(|id| { - [ - "id".to_string(), - id.to_string(), - ].join(",") - }), - - - self.pet_id.as_ref().map(|pet_id| { - [ - "petId".to_string(), - pet_id.to_string(), - ].join(",") - }), - - - self.quantity.as_ref().map(|quantity| { - [ - "quantity".to_string(), - quantity.to_string(), - ].join(",") - }), - + self.id + .as_ref() + .map(|id| ["id".to_string(), id.to_string()].join(",")), + self.pet_id + .as_ref() + .map(|pet_id| ["petId".to_string(), pet_id.to_string()].join(",")), + self.quantity + .as_ref() + .map(|quantity| ["quantity".to_string(), quantity.to_string()].join(",")), // Skipping shipDate in query parameter serialization - - - self.status.as_ref().map(|status| { - [ - "status".to_string(), - status.to_string(), - ].join(",") - }), - - - self.complete.as_ref().map(|complete| { - [ - "complete".to_string(), - complete.to_string(), - ].join(",") - }), - + self.status + .as_ref() + .map(|status| ["status".to_string(), status.to_string()].join(",")), + self.complete + .as_ref() + .map(|complete| ["complete".to_string(), complete.to_string()].join(",")), ]; params.into_iter().flatten().collect::>().join(",") @@ -4286,7 +4331,7 @@ impl std::str::FromStr for Order { pub id: Vec, pub pet_id: Vec, pub quantity: Vec, - pub ship_date: Vec>, + pub ship_date: Vec>, pub status: Vec, pub complete: Vec, } @@ -4300,25 +4345,46 @@ impl std::str::FromStr for Order { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing Order".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing Order".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "id" => intermediate_rep.id.push(::from_str(val).map_err(|x| x.to_string())?), + "id" => intermediate_rep.id.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "petId" => intermediate_rep.pet_id.push(::from_str(val).map_err(|x| x.to_string())?), + "petId" => intermediate_rep.pet_id.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "quantity" => intermediate_rep.quantity.push(::from_str(val).map_err(|x| x.to_string())?), + "quantity" => intermediate_rep.quantity.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "shipDate" => intermediate_rep.ship_date.push( as std::str::FromStr>::from_str(val).map_err(|x| x.to_string())?), + "shipDate" => intermediate_rep.ship_date.push( + as std::str::FromStr>::from_str(val) + .map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "status" => intermediate_rep.status.push(::from_str(val).map_err(|x| x.to_string())?), + "status" => intermediate_rep.status.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "complete" => intermediate_rep.complete.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing Order".to_string()) + "complete" => intermediate_rep.complete.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing Order".to_string(), + ) + } } } @@ -4344,13 +4410,16 @@ impl std::str::FromStr for Order { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for Order - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for Order - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -4361,24 +4430,23 @@ impl std::convert::TryFrom for header::IntoHeaderValue { fn try_from(hdr_value: HeaderValue) -> std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into Order - {}", - value, err)) - } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Ok(value) => match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) + } + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into Order - {}", + value, err + )), + }, + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - #[derive(Debug, Clone, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct OuterBoolean(bool); @@ -4414,29 +4482,22 @@ impl std::ops::DerefMut for OuterBoolean { } } - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct OuterComposite { #[serde(rename = "my_number")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub my_number: Option, #[serde(rename = "my_string")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub my_string: Option, #[serde(rename = "my_boolean")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub my_boolean: Option, - } - impl OuterComposite { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> OuterComposite { @@ -4454,30 +4515,15 @@ impl OuterComposite { impl std::string::ToString for OuterComposite { fn to_string(&self) -> String { let params: Vec> = vec![ - - self.my_number.as_ref().map(|my_number| { - [ - "my_number".to_string(), - my_number.to_string(), - ].join(",") - }), - - - self.my_string.as_ref().map(|my_string| { - [ - "my_string".to_string(), - my_string.to_string(), - ].join(",") - }), - - - self.my_boolean.as_ref().map(|my_boolean| { - [ - "my_boolean".to_string(), - my_boolean.to_string(), - ].join(",") - }), - + self.my_number + .as_ref() + .map(|my_number| ["my_number".to_string(), my_number.to_string()].join(",")), + self.my_string + .as_ref() + .map(|my_string| ["my_string".to_string(), my_string.to_string()].join(",")), + self.my_boolean + .as_ref() + .map(|my_boolean| ["my_boolean".to_string(), my_boolean.to_string()].join(",")), ]; params.into_iter().flatten().collect::>().join(",") @@ -4509,19 +4555,33 @@ impl std::str::FromStr for OuterComposite { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing OuterComposite".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing OuterComposite".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "my_number" => intermediate_rep.my_number.push(::from_str(val).map_err(|x| x.to_string())?), + "my_number" => intermediate_rep.my_number.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "my_string" => intermediate_rep.my_string.push(::from_str(val).map_err(|x| x.to_string())?), + "my_string" => intermediate_rep.my_string.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "my_boolean" => intermediate_rep.my_boolean.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing OuterComposite".to_string()) + "my_boolean" => intermediate_rep.my_boolean.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing OuterComposite".to_string(), + ) + } } } @@ -4544,13 +4604,16 @@ impl std::str::FromStr for OuterComposite { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for OuterComposite - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for OuterComposite - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -4561,30 +4624,33 @@ impl std::convert::TryFrom for header::IntoHeaderValue std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into OuterComposite - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into OuterComposite - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - /// Enumeration of values. /// Since this enum's variants do not hold data, we can easily define them as `#[repr(C)]` /// which helps with FFI. #[allow(non_camel_case_types)] #[repr(C)] -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize)] +#[derive( + Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize, +)] #[cfg_attr(feature = "conversion", derive(frunk_enum_derive::LabelledGenericEnum))] pub enum OuterEnum { #[serde(rename = "placed")] @@ -4618,7 +4684,6 @@ impl std::str::FromStr for OuterEnum { } } - #[derive(Debug, Clone, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct OuterNumber(f64); @@ -4654,8 +4719,6 @@ impl std::ops::DerefMut for OuterNumber { } } - - #[derive(Debug, Clone, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct OuterString(String); @@ -4674,7 +4737,7 @@ impl std::convert::From for OuterString { impl std::string::ToString for OuterString { fn to_string(&self) -> String { - self.0.to_string() + self.0.to_string() } } @@ -4704,20 +4767,15 @@ impl std::ops::DerefMut for OuterString { } } - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct Pet { #[serde(rename = "id")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub id: Option, #[serde(rename = "category")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub category: Option, #[serde(rename = "name")] @@ -4727,21 +4785,19 @@ pub struct Pet { pub photo_urls: Vec, #[serde(rename = "tags")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub tags: Option>, -/// pet status in the store -/// Note: inline enums are not fully supported by openapi-generator + /// pet status in the store + /// Note: inline enums are not fully supported by openapi-generator #[serde(rename = "status")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub status: Option, - } - impl Pet { #[allow(clippy::new_without_default, clippy::too_many_arguments)] - pub fn new(name: String, photo_urls: Vec, ) -> Pet { + pub fn new(name: String, photo_urls: Vec) -> Pet { Pet { id: None, category: None, @@ -4759,34 +4815,24 @@ impl Pet { impl std::string::ToString for Pet { fn to_string(&self) -> String { let params: Vec> = vec![ - - self.id.as_ref().map(|id| { - [ - "id".to_string(), - id.to_string(), - ].join(",") - }), - + self.id + .as_ref() + .map(|id| ["id".to_string(), id.to_string()].join(",")), // Skipping category in query parameter serialization - - Some("name".to_string()), Some(self.name.to_string()), - - Some("photoUrls".to_string()), - Some(self.photo_urls.iter().map(|x| x.to_string()).collect::>().join(",")), - + Some( + self.photo_urls + .iter() + .map(|x| x.to_string()) + .collect::>() + .join(","), + ), // Skipping tags in query parameter serialization - - - self.status.as_ref().map(|status| { - [ - "status".to_string(), - status.to_string(), - ].join(",") - }), - + self.status + .as_ref() + .map(|status| ["status".to_string(), status.to_string()].join(",")), ]; params.into_iter().flatten().collect::>().join(",") @@ -4821,23 +4867,46 @@ impl std::str::FromStr for Pet { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing Pet".to_string()) + None => { + return std::result::Result::Err("Missing value while parsing Pet".to_string()) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "id" => intermediate_rep.id.push(::from_str(val).map_err(|x| x.to_string())?), + "id" => intermediate_rep.id.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "category" => intermediate_rep.category.push(::from_str(val).map_err(|x| x.to_string())?), + "category" => intermediate_rep.category.push( + ::from_str(val) + .map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "name" => intermediate_rep.name.push(::from_str(val).map_err(|x| x.to_string())?), - "photoUrls" => return std::result::Result::Err("Parsing a container in this style is not supported in Pet".to_string()), - "tags" => return std::result::Result::Err("Parsing a container in this style is not supported in Pet".to_string()), + "name" => intermediate_rep.name.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + "photoUrls" => { + return std::result::Result::Err( + "Parsing a container in this style is not supported in Pet".to_string(), + ) + } + "tags" => { + return std::result::Result::Err( + "Parsing a container in this style is not supported in Pet".to_string(), + ) + } #[allow(clippy::redundant_clone)] - "status" => intermediate_rep.status.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing Pet".to_string()) + "status" => intermediate_rep.status.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing Pet".to_string(), + ) + } } } @@ -4849,8 +4918,16 @@ impl std::str::FromStr for Pet { std::result::Result::Ok(Pet { id: intermediate_rep.id.into_iter().next(), category: intermediate_rep.category.into_iter().next(), - name: intermediate_rep.name.into_iter().next().ok_or_else(|| "name missing in Pet".to_string())?, - photo_urls: intermediate_rep.photo_urls.into_iter().next().ok_or_else(|| "photoUrls missing in Pet".to_string())?, + name: intermediate_rep + .name + .into_iter() + .next() + .ok_or_else(|| "name missing in Pet".to_string())?, + photo_urls: intermediate_rep + .photo_urls + .into_iter() + .next() + .ok_or_else(|| "photoUrls missing in Pet".to_string())?, tags: intermediate_rep.tags.into_iter().next(), status: intermediate_rep.status.into_iter().next(), }) @@ -4866,10 +4943,11 @@ impl std::convert::TryFrom> for HeaderValue { fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for Pet - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for Pet - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -4880,41 +4958,35 @@ impl std::convert::TryFrom for header::IntoHeaderValue { fn try_from(hdr_value: HeaderValue) -> std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into Pet - {}", - value, err)) - } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Ok(value) => match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) + } + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into Pet - {}", + value, err + )), + }, + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct ReadOnlyFirst { #[serde(rename = "bar")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub bar: Option, #[serde(rename = "baz")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub baz: Option, - } - impl ReadOnlyFirst { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> ReadOnlyFirst { @@ -4931,22 +5003,12 @@ impl ReadOnlyFirst { impl std::string::ToString for ReadOnlyFirst { fn to_string(&self) -> String { let params: Vec> = vec![ - - self.bar.as_ref().map(|bar| { - [ - "bar".to_string(), - bar.to_string(), - ].join(",") - }), - - - self.baz.as_ref().map(|baz| { - [ - "baz".to_string(), - baz.to_string(), - ].join(",") - }), - + self.bar + .as_ref() + .map(|bar| ["bar".to_string(), bar.to_string()].join(",")), + self.baz + .as_ref() + .map(|baz| ["baz".to_string(), baz.to_string()].join(",")), ]; params.into_iter().flatten().collect::>().join(",") @@ -4977,17 +5039,29 @@ impl std::str::FromStr for ReadOnlyFirst { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing ReadOnlyFirst".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing ReadOnlyFirst".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "bar" => intermediate_rep.bar.push(::from_str(val).map_err(|x| x.to_string())?), + "bar" => intermediate_rep.bar.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "baz" => intermediate_rep.baz.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing ReadOnlyFirst".to_string()) + "baz" => intermediate_rep.baz.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing ReadOnlyFirst".to_string(), + ) + } } } @@ -5009,13 +5083,16 @@ impl std::str::FromStr for ReadOnlyFirst { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for ReadOnlyFirst - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for ReadOnlyFirst - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -5026,44 +5103,39 @@ impl std::convert::TryFrom for header::IntoHeaderValue std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into ReadOnlyFirst - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into ReadOnlyFirst - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - /// Model for testing reserved words - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct Return { #[serde(rename = "return")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub r#return: Option, - } - impl Return { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> Return { - Return { - r#return: None, - } + Return { r#return: None } } } @@ -5072,16 +5144,10 @@ impl Return { /// Should be implemented in a serde serializer impl std::string::ToString for Return { fn to_string(&self) -> String { - let params: Vec> = vec![ - - self.r#return.as_ref().map(|r#return| { - [ - "return".to_string(), - r#return.to_string(), - ].join(",") - }), - - ]; + let params: Vec> = vec![self + .r#return + .as_ref() + .map(|r#return| ["return".to_string(), r#return.to_string()].join(","))]; params.into_iter().flatten().collect::>().join(",") } @@ -5110,15 +5176,25 @@ impl std::str::FromStr for Return { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing Return".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing Return".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "return" => intermediate_rep.r#return.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing Return".to_string()) + "return" => intermediate_rep.r#return.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing Return".to_string(), + ) + } } } @@ -5139,13 +5215,16 @@ impl std::str::FromStr for Return { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for Return - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for Return - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -5156,41 +5235,37 @@ impl std::convert::TryFrom for header::IntoHeaderValue { fn try_from(hdr_value: HeaderValue) -> std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into Return - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into Return - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct Tag { #[serde(rename = "id")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub id: Option, #[serde(rename = "name")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub name: Option, - } - impl Tag { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> Tag { @@ -5207,22 +5282,12 @@ impl Tag { impl std::string::ToString for Tag { fn to_string(&self) -> String { let params: Vec> = vec![ - - self.id.as_ref().map(|id| { - [ - "id".to_string(), - id.to_string(), - ].join(",") - }), - - - self.name.as_ref().map(|name| { - [ - "name".to_string(), - name.to_string(), - ].join(",") - }), - + self.id + .as_ref() + .map(|id| ["id".to_string(), id.to_string()].join(",")), + self.name + .as_ref() + .map(|name| ["name".to_string(), name.to_string()].join(",")), ]; params.into_iter().flatten().collect::>().join(",") @@ -5253,17 +5318,27 @@ impl std::str::FromStr for Tag { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing Tag".to_string()) + None => { + return std::result::Result::Err("Missing value while parsing Tag".to_string()) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "id" => intermediate_rep.id.push(::from_str(val).map_err(|x| x.to_string())?), + "id" => intermediate_rep.id.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "name" => intermediate_rep.name.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing Tag".to_string()) + "name" => intermediate_rep.name.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing Tag".to_string(), + ) + } } } @@ -5288,10 +5363,11 @@ impl std::convert::TryFrom> for HeaderValue { fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for Tag - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for Tag - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -5302,66 +5378,60 @@ impl std::convert::TryFrom for header::IntoHeaderValue { fn try_from(hdr_value: HeaderValue) -> std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into Tag - {}", - value, err)) - } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Ok(value) => match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) + } + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into Tag - {}", + value, err + )), + }, + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct User { #[serde(rename = "id")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub id: Option, #[serde(rename = "username")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub username: Option, #[serde(rename = "firstName")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub first_name: Option, #[serde(rename = "lastName")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub last_name: Option, #[serde(rename = "email")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub email: Option, #[serde(rename = "password")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub password: Option, #[serde(rename = "phone")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub phone: Option, -/// User Status + /// User Status #[serde(rename = "userStatus")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub user_status: Option, - } - impl User { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> User { @@ -5384,70 +5454,30 @@ impl User { impl std::string::ToString for User { fn to_string(&self) -> String { let params: Vec> = vec![ - - self.id.as_ref().map(|id| { - [ - "id".to_string(), - id.to_string(), - ].join(",") - }), - - - self.username.as_ref().map(|username| { - [ - "username".to_string(), - username.to_string(), - ].join(",") - }), - - - self.first_name.as_ref().map(|first_name| { - [ - "firstName".to_string(), - first_name.to_string(), - ].join(",") - }), - - - self.last_name.as_ref().map(|last_name| { - [ - "lastName".to_string(), - last_name.to_string(), - ].join(",") - }), - - - self.email.as_ref().map(|email| { - [ - "email".to_string(), - email.to_string(), - ].join(",") - }), - - - self.password.as_ref().map(|password| { - [ - "password".to_string(), - password.to_string(), - ].join(",") - }), - - - self.phone.as_ref().map(|phone| { - [ - "phone".to_string(), - phone.to_string(), - ].join(",") - }), - - - self.user_status.as_ref().map(|user_status| { - [ - "userStatus".to_string(), - user_status.to_string(), - ].join(",") - }), - + self.id + .as_ref() + .map(|id| ["id".to_string(), id.to_string()].join(",")), + self.username + .as_ref() + .map(|username| ["username".to_string(), username.to_string()].join(",")), + self.first_name + .as_ref() + .map(|first_name| ["firstName".to_string(), first_name.to_string()].join(",")), + self.last_name + .as_ref() + .map(|last_name| ["lastName".to_string(), last_name.to_string()].join(",")), + self.email + .as_ref() + .map(|email| ["email".to_string(), email.to_string()].join(",")), + self.password + .as_ref() + .map(|password| ["password".to_string(), password.to_string()].join(",")), + self.phone + .as_ref() + .map(|phone| ["phone".to_string(), phone.to_string()].join(",")), + self.user_status + .as_ref() + .map(|user_status| ["userStatus".to_string(), user_status.to_string()].join(",")), ]; params.into_iter().flatten().collect::>().join(",") @@ -5484,29 +5514,51 @@ impl std::str::FromStr for User { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing User".to_string()) + None => { + return std::result::Result::Err("Missing value while parsing User".to_string()) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "id" => intermediate_rep.id.push(::from_str(val).map_err(|x| x.to_string())?), + "id" => intermediate_rep.id.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "username" => intermediate_rep.username.push(::from_str(val).map_err(|x| x.to_string())?), + "username" => intermediate_rep.username.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "firstName" => intermediate_rep.first_name.push(::from_str(val).map_err(|x| x.to_string())?), + "firstName" => intermediate_rep.first_name.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "lastName" => intermediate_rep.last_name.push(::from_str(val).map_err(|x| x.to_string())?), + "lastName" => intermediate_rep.last_name.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "email" => intermediate_rep.email.push(::from_str(val).map_err(|x| x.to_string())?), + "email" => intermediate_rep.email.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "password" => intermediate_rep.password.push(::from_str(val).map_err(|x| x.to_string())?), + "password" => intermediate_rep.password.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "phone" => intermediate_rep.phone.push(::from_str(val).map_err(|x| x.to_string())?), + "phone" => intermediate_rep.phone.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "userStatus" => intermediate_rep.user_status.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing User".to_string()) + "userStatus" => intermediate_rep.user_status.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing User".to_string(), + ) + } } } @@ -5534,13 +5586,16 @@ impl std::str::FromStr for User { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for User - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for User - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -5551,20 +5606,19 @@ impl std::convert::TryFrom for header::IntoHeaderValue { fn try_from(hdr_value: HeaderValue) -> std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into User - {}", - value, err)) - } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Ok(value) => match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) + } + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into User - {}", + value, err + )), + }, + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - diff --git a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/server/mod.rs b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/server/mod.rs index 2657be58908..521d140f42b 100644 --- a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/server/mod.rs +++ b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/server/mod.rs @@ -12,42 +12,18 @@ use crate::{header, types::*}; #[allow(unused_imports)] use crate::models; -use crate::{Api, - TestSpecialTagsResponse, - Call123exampleResponse, - FakeOuterBooleanSerializeResponse, - FakeOuterCompositeSerializeResponse, - FakeOuterNumberSerializeResponse, - FakeOuterStringSerializeResponse, - FakeResponseWithNumericalDescriptionResponse, - HyphenParamResponse, - TestBodyWithQueryParamsResponse, - TestClientModelResponse, - TestEndpointParametersResponse, - TestEnumParametersResponse, - TestInlineAdditionalPropertiesResponse, - TestJsonFormDataResponse, - TestClassnameResponse, - AddPetResponse, - DeletePetResponse, - FindPetsByStatusResponse, - FindPetsByTagsResponse, - GetPetByIdResponse, - UpdatePetResponse, - UpdatePetWithFormResponse, - UploadFileResponse, - DeleteOrderResponse, - GetInventoryResponse, - GetOrderByIdResponse, - PlaceOrderResponse, - CreateUserResponse, - CreateUsersWithArrayInputResponse, - CreateUsersWithListInputResponse, - DeleteUserResponse, - GetUserByNameResponse, - LoginUserResponse, - LogoutUserResponse, - UpdateUserResponse +use crate::{ + AddPetResponse, Api, Call123exampleResponse, CreateUserResponse, + CreateUsersWithArrayInputResponse, CreateUsersWithListInputResponse, DeleteOrderResponse, + DeletePetResponse, DeleteUserResponse, FakeOuterBooleanSerializeResponse, + FakeOuterCompositeSerializeResponse, FakeOuterNumberSerializeResponse, + FakeOuterStringSerializeResponse, FakeResponseWithNumericalDescriptionResponse, + FindPetsByStatusResponse, FindPetsByTagsResponse, GetInventoryResponse, GetOrderByIdResponse, + GetPetByIdResponse, GetUserByNameResponse, HyphenParamResponse, LoginUserResponse, + LogoutUserResponse, PlaceOrderResponse, TestBodyWithQueryParamsResponse, TestClassnameResponse, + TestClientModelResponse, TestEndpointParametersResponse, TestEnumParametersResponse, + TestInlineAdditionalPropertiesResponse, TestJsonFormDataResponse, TestSpecialTagsResponse, + UpdatePetResponse, UpdatePetWithFormResponse, UpdateUserResponse, UploadFileResponse, }; /// Setup API Server. @@ -58,3155 +34,2788 @@ where { // build our application with a route Router::new() - .route("/v2/another-fake/dummy", - patch(test_special_tags::) + .route("/v2/another-fake/dummy", patch(test_special_tags::)) + .route( + "/v2/fake", + get(test_enum_parameters::) + .patch(test_client_model::) + .post(test_endpoint_parameters::), ) - .route("/v2/fake", - get(test_enum_parameters::).patch(test_client_model::).post(test_endpoint_parameters::) + .route( + "/v2/fake/body-with-query-params", + put(test_body_with_query_params::), ) - .route("/v2/fake/body-with-query-params", - put(test_body_with_query_params::) + .route( + "/v2/fake/hyphenParam/:hyphen_param", + get(hyphen_param::), ) - .route("/v2/fake/hyphenParam/:hyphen_param", - get(hyphen_param::) + .route( + "/v2/fake/inline-additionalProperties", + post(test_inline_additional_properties::), ) - .route("/v2/fake/inline-additionalProperties", - post(test_inline_additional_properties::) + .route("/v2/fake/jsonFormData", get(test_json_form_data::)) + .route( + "/v2/fake/operation-with-numeric-id", + get(call123example::), ) - .route("/v2/fake/jsonFormData", - get(test_json_form_data::) + .route( + "/v2/fake/outer/boolean", + post(fake_outer_boolean_serialize::), ) - .route("/v2/fake/operation-with-numeric-id", - get(call123example::) + .route( + "/v2/fake/outer/composite", + post(fake_outer_composite_serialize::), ) - .route("/v2/fake/outer/boolean", - post(fake_outer_boolean_serialize::) + .route( + "/v2/fake/outer/number", + post(fake_outer_number_serialize::), ) - .route("/v2/fake/outer/composite", - post(fake_outer_composite_serialize::) + .route( + "/v2/fake/outer/string", + post(fake_outer_string_serialize::), ) - .route("/v2/fake/outer/number", - post(fake_outer_number_serialize::) + .route( + "/v2/fake/response-with-numerical-description", + get(fake_response_with_numerical_description::), ) - .route("/v2/fake/outer/string", - post(fake_outer_string_serialize::) + .route("/v2/fake_classname_test", patch(test_classname::)) + .route("/v2/pet", post(add_pet::).put(update_pet::)) + .route( + "/v2/pet/:pet_id", + delete(delete_pet::) + .get(get_pet_by_id::) + .post(update_pet_with_form::), ) - .route("/v2/fake/response-with-numerical-description", - get(fake_response_with_numerical_description::) + .route("/v2/pet/:pet_id/uploadImage", post(upload_file::)) + .route("/v2/pet/findByStatus", get(find_pets_by_status::)) + .route("/v2/pet/findByTags", get(find_pets_by_tags::)) + .route("/v2/store/inventory", get(get_inventory::)) + .route("/v2/store/order", post(place_order::)) + .route( + "/v2/store/order/:order_id", + delete(delete_order::).get(get_order_by_id::), ) - .route("/v2/fake_classname_test", - patch(test_classname::) + .route("/v2/user", post(create_user::)) + .route( + "/v2/user/:username", + delete(delete_user::) + .get(get_user_by_name::) + .put(update_user::), ) - .route("/v2/pet", - post(add_pet::).put(update_pet::) + .route( + "/v2/user/createWithArray", + post(create_users_with_array_input::), ) - .route("/v2/pet/:pet_id", - delete(delete_pet::).get(get_pet_by_id::).post(update_pet_with_form::) - ) - .route("/v2/pet/:pet_id/uploadImage", - post(upload_file::) - ) - .route("/v2/pet/findByStatus", - get(find_pets_by_status::) - ) - .route("/v2/pet/findByTags", - get(find_pets_by_tags::) - ) - .route("/v2/store/inventory", - get(get_inventory::) - ) - .route("/v2/store/order", - post(place_order::) - ) - .route("/v2/store/order/:order_id", - delete(delete_order::).get(get_order_by_id::) - ) - .route("/v2/user", - post(create_user::) - ) - .route("/v2/user/:username", - delete(delete_user::).get(get_user_by_name::).put(update_user::) - ) - .route("/v2/user/createWithArray", - post(create_users_with_array_input::) - ) - .route("/v2/user/createWithList", - post(create_users_with_list_input::) - ) - .route("/v2/user/login", - get(login_user::) - ) - .route("/v2/user/logout", - get(logout_user::) + .route( + "/v2/user/createWithList", + post(create_users_with_list_input::), ) + .route("/v2/user/login", get(login_user::)) + .route("/v2/user/logout", get(logout_user::)) .with_state(api_impl) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct TestSpecialTagsBodyValidator<'a> { - #[validate] - body: &'a models::Client, - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct TestSpecialTagsBodyValidator<'a> { + #[validate] + body: &'a models::Client, +} #[tracing::instrument(skip_all)] fn test_special_tags_validation( - body: models::Client, -) -> std::result::Result<( - models::Client, -), ValidationErrors> -{ - let b = TestSpecialTagsBodyValidator { body: &body }; - b.validate()?; + body: models::Client, +) -> std::result::Result<(models::Client,), ValidationErrors> { + let b = TestSpecialTagsBodyValidator { body: &body }; + b.validate()?; -Ok(( - body, -)) + Ok((body,)) } /// TestSpecialTags - PATCH /v2/another-fake/dummy #[tracing::instrument(skip_all)] async fn test_special_tags( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - Json(body): Json, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + Json(body): Json, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || test_special_tags_validation(body)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - test_special_tags_validation( - body, - ) - ).await.unwrap(); - - let Ok(( - body, - )) = validation else { - return Response::builder() + let Ok((body,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().test_special_tags( - method, - host, - cookies, - body, - ).await; + let result = api_impl + .as_ref() + .test_special_tags(method, host, cookies, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - TestSpecialTagsResponse::Status200_SuccessfulOperation - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + TestSpecialTagsResponse::Status200_SuccessfulOperation(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("application/json").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("application/json").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = tokio::task::spawn_blocking(move || { + serde_json::to_vec(&body).map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) + }) + .await + .unwrap()?; + response.body(Body::from(body_content)) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = tokio::task::spawn_blocking(move || - serde_json::to_vec(&body).map_err(|e| { - error!(error = ?e); - StatusCode::INTERNAL_SERVER_ERROR - })).await.unwrap()?; - response.body(Body::from(body_content)) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] -fn call123example_validation( -) -> std::result::Result<( -), ValidationErrors> -{ - -Ok(( -)) +fn call123example_validation() -> std::result::Result<(), ValidationErrors> { + Ok(()) } /// Call123example - GET /v2/fake/operation-with-numeric-id #[tracing::instrument(skip_all)] async fn call123example( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || call123example_validation()) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - call123example_validation( - ) - ).await.unwrap(); - - let Ok(( - )) = validation else { - return Response::builder() + let Ok(()) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().call123example( - method, - host, - cookies, - ).await; + let result = api_impl + .as_ref() + .call123example(method, host, cookies) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - Call123exampleResponse::Status200_Success - => { + let resp = match result { + Ok(rsp) => match rsp { + Call123exampleResponse::Status200_Success => { + let mut response = response.status(200); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(200); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct FakeOuterBooleanSerializeBodyValidator<'a> { - #[validate] - body: &'a models::OuterBoolean, - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct FakeOuterBooleanSerializeBodyValidator<'a> { + #[validate] + body: &'a models::OuterBoolean, +} #[tracing::instrument(skip_all)] fn fake_outer_boolean_serialize_validation( - body: Option, -) -> std::result::Result<( - Option, -), ValidationErrors> -{ - if let Some(body) = &body { - let b = FakeOuterBooleanSerializeBodyValidator { body }; - b.validate()?; - } + body: Option, +) -> std::result::Result<(Option,), ValidationErrors> { + if let Some(body) = &body { + let b = FakeOuterBooleanSerializeBodyValidator { body }; + b.validate()?; + } -Ok(( - body, -)) + Ok((body,)) } /// FakeOuterBooleanSerialize - POST /v2/fake/outer/boolean #[tracing::instrument(skip_all)] async fn fake_outer_boolean_serialize( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - Json(body): Json>, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + Json(body): Json>, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = + tokio::task::spawn_blocking(move || fake_outer_boolean_serialize_validation(body)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - fake_outer_boolean_serialize_validation( - body, - ) - ).await.unwrap(); - - let Ok(( - body, - )) = validation else { - return Response::builder() + let Ok((body,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().fake_outer_boolean_serialize( - method, - host, - cookies, - body, - ).await; + let result = api_impl + .as_ref() + .fake_outer_boolean_serialize(method, host, cookies, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - FakeOuterBooleanSerializeResponse::Status200_OutputBoolean - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + FakeOuterBooleanSerializeResponse::Status200_OutputBoolean(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("*/*").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("*/*").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = tokio::task::spawn_blocking(move || { + serde_json::to_vec(&body).map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) + }) + .await + .unwrap()?; + response.body(Body::from(body_content)) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = tokio::task::spawn_blocking(move || - serde_json::to_vec(&body).map_err(|e| { - error!(error = ?e); - StatusCode::INTERNAL_SERVER_ERROR - })).await.unwrap()?; - response.body(Body::from(body_content)) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct FakeOuterCompositeSerializeBodyValidator<'a> { - #[validate] - body: &'a models::OuterComposite, - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct FakeOuterCompositeSerializeBodyValidator<'a> { + #[validate] + body: &'a models::OuterComposite, +} #[tracing::instrument(skip_all)] fn fake_outer_composite_serialize_validation( - body: Option, -) -> std::result::Result<( - Option, -), ValidationErrors> -{ - if let Some(body) = &body { - let b = FakeOuterCompositeSerializeBodyValidator { body }; - b.validate()?; - } + body: Option, +) -> std::result::Result<(Option,), ValidationErrors> { + if let Some(body) = &body { + let b = FakeOuterCompositeSerializeBodyValidator { body }; + b.validate()?; + } -Ok(( - body, -)) + Ok((body,)) } /// FakeOuterCompositeSerialize - POST /v2/fake/outer/composite #[tracing::instrument(skip_all)] async fn fake_outer_composite_serialize( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - Json(body): Json>, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + Json(body): Json>, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = + tokio::task::spawn_blocking(move || fake_outer_composite_serialize_validation(body)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - fake_outer_composite_serialize_validation( - body, - ) - ).await.unwrap(); - - let Ok(( - body, - )) = validation else { - return Response::builder() + let Ok((body,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().fake_outer_composite_serialize( - method, - host, - cookies, - body, - ).await; + let result = api_impl + .as_ref() + .fake_outer_composite_serialize(method, host, cookies, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - FakeOuterCompositeSerializeResponse::Status200_OutputComposite - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + FakeOuterCompositeSerializeResponse::Status200_OutputComposite(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("*/*").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("*/*").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = tokio::task::spawn_blocking(move || { + serde_json::to_vec(&body).map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) + }) + .await + .unwrap()?; + response.body(Body::from(body_content)) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = tokio::task::spawn_blocking(move || - serde_json::to_vec(&body).map_err(|e| { - error!(error = ?e); - StatusCode::INTERNAL_SERVER_ERROR - })).await.unwrap()?; - response.body(Body::from(body_content)) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct FakeOuterNumberSerializeBodyValidator<'a> { - #[validate] - body: &'a models::OuterNumber, - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct FakeOuterNumberSerializeBodyValidator<'a> { + #[validate] + body: &'a models::OuterNumber, +} #[tracing::instrument(skip_all)] fn fake_outer_number_serialize_validation( - body: Option, -) -> std::result::Result<( - Option, -), ValidationErrors> -{ - if let Some(body) = &body { - let b = FakeOuterNumberSerializeBodyValidator { body }; - b.validate()?; - } + body: Option, +) -> std::result::Result<(Option,), ValidationErrors> { + if let Some(body) = &body { + let b = FakeOuterNumberSerializeBodyValidator { body }; + b.validate()?; + } -Ok(( - body, -)) + Ok((body,)) } /// FakeOuterNumberSerialize - POST /v2/fake/outer/number #[tracing::instrument(skip_all)] async fn fake_outer_number_serialize( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - Json(body): Json>, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + Json(body): Json>, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = + tokio::task::spawn_blocking(move || fake_outer_number_serialize_validation(body)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - fake_outer_number_serialize_validation( - body, - ) - ).await.unwrap(); - - let Ok(( - body, - )) = validation else { - return Response::builder() + let Ok((body,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().fake_outer_number_serialize( - method, - host, - cookies, - body, - ).await; + let result = api_impl + .as_ref() + .fake_outer_number_serialize(method, host, cookies, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - FakeOuterNumberSerializeResponse::Status200_OutputNumber - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + FakeOuterNumberSerializeResponse::Status200_OutputNumber(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("*/*").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("*/*").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = tokio::task::spawn_blocking(move || { + serde_json::to_vec(&body).map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) + }) + .await + .unwrap()?; + response.body(Body::from(body_content)) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = tokio::task::spawn_blocking(move || - serde_json::to_vec(&body).map_err(|e| { - error!(error = ?e); - StatusCode::INTERNAL_SERVER_ERROR - })).await.unwrap()?; - response.body(Body::from(body_content)) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct FakeOuterStringSerializeBodyValidator<'a> { - #[validate] - body: &'a models::OuterString, - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct FakeOuterStringSerializeBodyValidator<'a> { + #[validate] + body: &'a models::OuterString, +} #[tracing::instrument(skip_all)] fn fake_outer_string_serialize_validation( - body: Option, -) -> std::result::Result<( - Option, -), ValidationErrors> -{ - if let Some(body) = &body { - let b = FakeOuterStringSerializeBodyValidator { body }; - b.validate()?; - } + body: Option, +) -> std::result::Result<(Option,), ValidationErrors> { + if let Some(body) = &body { + let b = FakeOuterStringSerializeBodyValidator { body }; + b.validate()?; + } -Ok(( - body, -)) + Ok((body,)) } /// FakeOuterStringSerialize - POST /v2/fake/outer/string #[tracing::instrument(skip_all)] async fn fake_outer_string_serialize( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - Json(body): Json>, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + Json(body): Json>, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = + tokio::task::spawn_blocking(move || fake_outer_string_serialize_validation(body)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - fake_outer_string_serialize_validation( - body, - ) - ).await.unwrap(); - - let Ok(( - body, - )) = validation else { - return Response::builder() + let Ok((body,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().fake_outer_string_serialize( - method, - host, - cookies, - body, - ).await; + let result = api_impl + .as_ref() + .fake_outer_string_serialize(method, host, cookies, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - FakeOuterStringSerializeResponse::Status200_OutputString - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + FakeOuterStringSerializeResponse::Status200_OutputString(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("*/*").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("*/*").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = tokio::task::spawn_blocking(move || { + serde_json::to_vec(&body).map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) + }) + .await + .unwrap()?; + response.body(Body::from(body_content)) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = tokio::task::spawn_blocking(move || - serde_json::to_vec(&body).map_err(|e| { - error!(error = ?e); - StatusCode::INTERNAL_SERVER_ERROR - })).await.unwrap()?; - response.body(Body::from(body_content)) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] -fn fake_response_with_numerical_description_validation( -) -> std::result::Result<( -), ValidationErrors> +fn fake_response_with_numerical_description_validation() -> std::result::Result<(), ValidationErrors> { - -Ok(( -)) + Ok(()) } /// FakeResponseWithNumericalDescription - GET /v2/fake/response-with-numerical-description #[tracing::instrument(skip_all)] async fn fake_response_with_numerical_description( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = + tokio::task::spawn_blocking(move || fake_response_with_numerical_description_validation()) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - fake_response_with_numerical_description_validation( - ) - ).await.unwrap(); - - let Ok(( - )) = validation else { - return Response::builder() + let Ok(()) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().fake_response_with_numerical_description( - method, - host, - cookies, - ).await; + let result = api_impl + .as_ref() + .fake_response_with_numerical_description(method, host, cookies) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - FakeResponseWithNumericalDescriptionResponse::Status200 - => { + let resp = match result { + Ok(rsp) => match rsp { + FakeResponseWithNumericalDescriptionResponse::Status200 => { + let mut response = response.status(200); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(200); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] fn hyphen_param_validation( - path_params: models::HyphenParamPathParams, -) -> std::result::Result<( - models::HyphenParamPathParams, -), ValidationErrors> -{ - path_params.validate()?; + path_params: models::HyphenParamPathParams, +) -> std::result::Result<(models::HyphenParamPathParams,), ValidationErrors> { + path_params.validate()?; -Ok(( - path_params, -)) + Ok((path_params,)) } /// HyphenParam - GET /v2/fake/hyphenParam/{hyphen-param} #[tracing::instrument(skip_all)] async fn hyphen_param( - method: Method, - host: Host, - cookies: CookieJar, - Path(path_params): Path, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + Path(path_params): Path, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || hyphen_param_validation(path_params)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - hyphen_param_validation( - path_params, - ) - ).await.unwrap(); - - let Ok(( - path_params, - )) = validation else { - return Response::builder() + let Ok((path_params,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().hyphen_param( - method, - host, - cookies, - path_params, - ).await; + let result = api_impl + .as_ref() + .hyphen_param(method, host, cookies, path_params) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - HyphenParamResponse::Status200_Success - => { + let resp = match result { + Ok(rsp) => match rsp { + HyphenParamResponse::Status200_Success => { + let mut response = response.status(200); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(200); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct TestBodyWithQueryParamsBodyValidator<'a> { - #[validate] - body: &'a models::User, - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct TestBodyWithQueryParamsBodyValidator<'a> { + #[validate] + body: &'a models::User, +} #[tracing::instrument(skip_all)] fn test_body_with_query_params_validation( - query_params: models::TestBodyWithQueryParamsQueryParams, - body: models::User, -) -> std::result::Result<( - models::TestBodyWithQueryParamsQueryParams, - models::User, -), ValidationErrors> + query_params: models::TestBodyWithQueryParamsQueryParams, + body: models::User, +) -> std::result::Result<(models::TestBodyWithQueryParamsQueryParams, models::User), ValidationErrors> { - query_params.validate()?; - let b = TestBodyWithQueryParamsBodyValidator { body: &body }; - b.validate()?; + query_params.validate()?; + let b = TestBodyWithQueryParamsBodyValidator { body: &body }; + b.validate()?; -Ok(( - query_params, - body, -)) + Ok((query_params, body)) } /// TestBodyWithQueryParams - PUT /v2/fake/body-with-query-params #[tracing::instrument(skip_all)] async fn test_body_with_query_params( - method: Method, - host: Host, - cookies: CookieJar, - Query(query_params): Query, - State(api_impl): State, - Json(body): Json, + method: Method, + host: Host, + cookies: CookieJar, + Query(query_params): Query, + State(api_impl): State, + Json(body): Json, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || { + test_body_with_query_params_validation(query_params, body) + }) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - test_body_with_query_params_validation( - query_params, - body, - ) - ).await.unwrap(); - - let Ok(( - query_params, - body, - )) = validation else { - return Response::builder() + let Ok((query_params, body)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().test_body_with_query_params( - method, - host, - cookies, - query_params, - body, - ).await; + let result = api_impl + .as_ref() + .test_body_with_query_params(method, host, cookies, query_params, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - TestBodyWithQueryParamsResponse::Status200_Success - => { + let resp = match result { + Ok(rsp) => match rsp { + TestBodyWithQueryParamsResponse::Status200_Success => { + let mut response = response.status(200); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(200); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct TestClientModelBodyValidator<'a> { - #[validate] - body: &'a models::Client, - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct TestClientModelBodyValidator<'a> { + #[validate] + body: &'a models::Client, +} #[tracing::instrument(skip_all)] fn test_client_model_validation( - body: models::Client, -) -> std::result::Result<( - models::Client, -), ValidationErrors> -{ - let b = TestClientModelBodyValidator { body: &body }; - b.validate()?; + body: models::Client, +) -> std::result::Result<(models::Client,), ValidationErrors> { + let b = TestClientModelBodyValidator { body: &body }; + b.validate()?; -Ok(( - body, -)) + Ok((body,)) } /// TestClientModel - PATCH /v2/fake #[tracing::instrument(skip_all)] async fn test_client_model( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - Json(body): Json, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + Json(body): Json, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || test_client_model_validation(body)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - test_client_model_validation( - body, - ) - ).await.unwrap(); - - let Ok(( - body, - )) = validation else { - return Response::builder() + let Ok((body,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().test_client_model( - method, - host, - cookies, - body, - ).await; + let result = api_impl + .as_ref() + .test_client_model(method, host, cookies, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - TestClientModelResponse::Status200_SuccessfulOperation - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + TestClientModelResponse::Status200_SuccessfulOperation(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("application/json").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("application/json").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = tokio::task::spawn_blocking(move || { + serde_json::to_vec(&body).map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) + }) + .await + .unwrap()?; + response.body(Body::from(body_content)) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = tokio::task::spawn_blocking(move || - serde_json::to_vec(&body).map_err(|e| { - error!(error = ?e); - StatusCode::INTERNAL_SERVER_ERROR - })).await.unwrap()?; - response.body(Body::from(body_content)) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] -fn test_endpoint_parameters_validation( -) -> std::result::Result<( -), ValidationErrors> -{ - -Ok(( -)) +fn test_endpoint_parameters_validation() -> std::result::Result<(), ValidationErrors> { + Ok(()) } /// TestEndpointParameters - POST /v2/fake #[tracing::instrument(skip_all)] async fn test_endpoint_parameters( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || test_endpoint_parameters_validation()) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - test_endpoint_parameters_validation( - ) - ).await.unwrap(); - - let Ok(( - )) = validation else { - return Response::builder() + let Ok(()) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().test_endpoint_parameters( - method, - host, - cookies, - ).await; + let result = api_impl + .as_ref() + .test_endpoint_parameters(method, host, cookies) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - TestEndpointParametersResponse::Status400_InvalidUsernameSupplied - => { + let resp = match result { + Ok(rsp) => match rsp { + TestEndpointParametersResponse::Status400_InvalidUsernameSupplied => { + let mut response = response.status(400); + response.body(Body::empty()) + } + TestEndpointParametersResponse::Status404_UserNotFound => { + let mut response = response.status(404); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(400); - response.body(Body::empty()) - }, - TestEndpointParametersResponse::Status404_UserNotFound - => { - - let mut response = response.status(404); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] fn test_enum_parameters_validation( - header_params: models::TestEnumParametersHeaderParams, - query_params: models::TestEnumParametersQueryParams, -) -> std::result::Result<( - models::TestEnumParametersHeaderParams, - models::TestEnumParametersQueryParams, -), ValidationErrors> -{ - header_params.validate()?; - query_params.validate()?; + header_params: models::TestEnumParametersHeaderParams, + query_params: models::TestEnumParametersQueryParams, +) -> std::result::Result< + ( + models::TestEnumParametersHeaderParams, + models::TestEnumParametersQueryParams, + ), + ValidationErrors, +> { + header_params.validate()?; + query_params.validate()?; -Ok(( - header_params, - query_params, -)) + Ok((header_params, query_params)) } /// TestEnumParameters - GET /v2/fake #[tracing::instrument(skip_all)] async fn test_enum_parameters( - method: Method, - host: Host, - cookies: CookieJar, - headers: HeaderMap, - Query(query_params): Query, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + headers: HeaderMap, + Query(query_params): Query, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { // Header parameters let header_params = { - let header_enum_header_string_array = headers.get(HeaderName::from_static("enum_header_string_array")); + let header_enum_header_string_array = + headers.get(HeaderName::from_static("enum_header_string_array")); - let header_enum_header_string_array = match header_enum_header_string_array { - Some(v) => match header::IntoHeaderValue::>::try_from((*v).clone()) { - Ok(result) => - Some(result.0), - Err(err) => { - return Response::builder() - .status(StatusCode::BAD_REQUEST) - .body(Body::from(format!("Invalid header enum_header_string_array - {}", err))).map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }); + let header_enum_header_string_array = match header_enum_header_string_array { + Some(v) => match header::IntoHeaderValue::>::try_from((*v).clone()) { + Ok(result) => Some(result.0), + Err(err) => { + return Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!( + "Invalid header enum_header_string_array - {}", + err + ))) + .map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }); + } + }, + None => None, + }; + let header_enum_header_string = headers.get(HeaderName::from_static("enum_header_string")); - }, - }, - None => { - None - } - }; - let header_enum_header_string = headers.get(HeaderName::from_static("enum_header_string")); + let header_enum_header_string = match header_enum_header_string { + Some(v) => match header::IntoHeaderValue::::try_from((*v).clone()) { + Ok(result) => Some(result.0), + Err(err) => { + return Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!( + "Invalid header enum_header_string - {}", + err + ))) + .map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }); + } + }, + None => None, + }; - let header_enum_header_string = match header_enum_header_string { - Some(v) => match header::IntoHeaderValue::::try_from((*v).clone()) { - Ok(result) => - Some(result.0), - Err(err) => { - return Response::builder() - .status(StatusCode::BAD_REQUEST) - .body(Body::from(format!("Invalid header enum_header_string - {}", err))).map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }); + models::TestEnumParametersHeaderParams { + enum_header_string_array: header_enum_header_string_array, + enum_header_string: header_enum_header_string, + } + }; - }, - }, - None => { - None - } - }; + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || { + test_enum_parameters_validation(header_params, query_params) + }) + .await + .unwrap(); - models::TestEnumParametersHeaderParams { - enum_header_string_array: header_enum_header_string_array, - enum_header_string: header_enum_header_string, - } - }; - - - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - test_enum_parameters_validation( - header_params, - query_params, - ) - ).await.unwrap(); - - let Ok(( - header_params, - query_params, - )) = validation else { - return Response::builder() + let Ok((header_params, query_params)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().test_enum_parameters( - method, - host, - cookies, - header_params, - query_params, - ).await; + let result = api_impl + .as_ref() + .test_enum_parameters(method, host, cookies, header_params, query_params) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - TestEnumParametersResponse::Status400_InvalidRequest - => { + let resp = match result { + Ok(rsp) => match rsp { + TestEnumParametersResponse::Status400_InvalidRequest => { + let mut response = response.status(400); + response.body(Body::empty()) + } + TestEnumParametersResponse::Status404_NotFound => { + let mut response = response.status(404); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(400); - response.body(Body::empty()) - }, - TestEnumParametersResponse::Status404_NotFound - => { - - let mut response = response.status(404); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct TestInlineAdditionalPropertiesBodyValidator<'a> { - body: &'a std::collections::HashMap, - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct TestInlineAdditionalPropertiesBodyValidator<'a> { + body: &'a std::collections::HashMap, +} #[tracing::instrument(skip_all)] fn test_inline_additional_properties_validation( - body: std::collections::HashMap, -) -> std::result::Result<( - std::collections::HashMap, -), ValidationErrors> -{ - let b = TestInlineAdditionalPropertiesBodyValidator { body: &body }; - b.validate()?; + body: std::collections::HashMap, +) -> std::result::Result<(std::collections::HashMap,), ValidationErrors> { + let b = TestInlineAdditionalPropertiesBodyValidator { body: &body }; + b.validate()?; -Ok(( - body, -)) + Ok((body,)) } /// TestInlineAdditionalProperties - POST /v2/fake/inline-additionalProperties #[tracing::instrument(skip_all)] async fn test_inline_additional_properties( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - Json(body): Json>, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + Json(body): Json>, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = + tokio::task::spawn_blocking(move || test_inline_additional_properties_validation(body)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - test_inline_additional_properties_validation( - body, - ) - ).await.unwrap(); - - let Ok(( - body, - )) = validation else { - return Response::builder() + let Ok((body,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().test_inline_additional_properties( - method, - host, - cookies, - body, - ).await; + let result = api_impl + .as_ref() + .test_inline_additional_properties(method, host, cookies, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - TestInlineAdditionalPropertiesResponse::Status200_SuccessfulOperation - => { + let resp = match result { + Ok(rsp) => match rsp { + TestInlineAdditionalPropertiesResponse::Status200_SuccessfulOperation => { + let mut response = response.status(200); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(200); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] -fn test_json_form_data_validation( -) -> std::result::Result<( -), ValidationErrors> -{ - -Ok(( -)) +fn test_json_form_data_validation() -> std::result::Result<(), ValidationErrors> { + Ok(()) } /// TestJsonFormData - GET /v2/fake/jsonFormData #[tracing::instrument(skip_all)] async fn test_json_form_data( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || test_json_form_data_validation()) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - test_json_form_data_validation( - ) - ).await.unwrap(); - - let Ok(( - )) = validation else { - return Response::builder() + let Ok(()) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().test_json_form_data( - method, - host, - cookies, - ).await; + let result = api_impl + .as_ref() + .test_json_form_data(method, host, cookies) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - TestJsonFormDataResponse::Status200_SuccessfulOperation - => { + let resp = match result { + Ok(rsp) => match rsp { + TestJsonFormDataResponse::Status200_SuccessfulOperation => { + let mut response = response.status(200); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(200); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct TestClassnameBodyValidator<'a> { - #[validate] - body: &'a models::Client, - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct TestClassnameBodyValidator<'a> { + #[validate] + body: &'a models::Client, +} #[tracing::instrument(skip_all)] fn test_classname_validation( - body: models::Client, -) -> std::result::Result<( - models::Client, -), ValidationErrors> -{ - let b = TestClassnameBodyValidator { body: &body }; - b.validate()?; + body: models::Client, +) -> std::result::Result<(models::Client,), ValidationErrors> { + let b = TestClassnameBodyValidator { body: &body }; + b.validate()?; -Ok(( - body, -)) + Ok((body,)) } /// TestClassname - PATCH /v2/fake_classname_test #[tracing::instrument(skip_all)] async fn test_classname( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - Json(body): Json, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + Json(body): Json, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || test_classname_validation(body)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - test_classname_validation( - body, - ) - ).await.unwrap(); - - let Ok(( - body, - )) = validation else { - return Response::builder() + let Ok((body,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().test_classname( - method, - host, - cookies, - body, - ).await; + let result = api_impl + .as_ref() + .test_classname(method, host, cookies, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - TestClassnameResponse::Status200_SuccessfulOperation - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + TestClassnameResponse::Status200_SuccessfulOperation(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("application/json").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("application/json").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = tokio::task::spawn_blocking(move || { + serde_json::to_vec(&body).map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) + }) + .await + .unwrap()?; + response.body(Body::from(body_content)) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = tokio::task::spawn_blocking(move || - serde_json::to_vec(&body).map_err(|e| { - error!(error = ?e); - StatusCode::INTERNAL_SERVER_ERROR - })).await.unwrap()?; - response.body(Body::from(body_content)) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct AddPetBodyValidator<'a> { - #[validate] - body: &'a models::Pet, - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct AddPetBodyValidator<'a> { + #[validate] + body: &'a models::Pet, +} #[tracing::instrument(skip_all)] -fn add_pet_validation( - body: models::Pet, -) -> std::result::Result<( - models::Pet, -), ValidationErrors> -{ - let b = AddPetBodyValidator { body: &body }; - b.validate()?; +fn add_pet_validation(body: models::Pet) -> std::result::Result<(models::Pet,), ValidationErrors> { + let b = AddPetBodyValidator { body: &body }; + b.validate()?; -Ok(( - body, -)) + Ok((body,)) } /// AddPet - POST /v2/pet #[tracing::instrument(skip_all)] async fn add_pet( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - Json(body): Json, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + Json(body): Json, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || add_pet_validation(body)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - add_pet_validation( - body, - ) - ).await.unwrap(); - - let Ok(( - body, - )) = validation else { - return Response::builder() + let Ok((body,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().add_pet( - method, - host, - cookies, - body, - ).await; + let result = api_impl.as_ref().add_pet(method, host, cookies, body).await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - AddPetResponse::Status405_InvalidInput - => { + let resp = match result { + Ok(rsp) => match rsp { + AddPetResponse::Status405_InvalidInput => { + let mut response = response.status(405); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(405); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] fn delete_pet_validation( - header_params: models::DeletePetHeaderParams, - path_params: models::DeletePetPathParams, -) -> std::result::Result<( - models::DeletePetHeaderParams, - models::DeletePetPathParams, -), ValidationErrors> -{ - header_params.validate()?; - path_params.validate()?; + header_params: models::DeletePetHeaderParams, + path_params: models::DeletePetPathParams, +) -> std::result::Result< + (models::DeletePetHeaderParams, models::DeletePetPathParams), + ValidationErrors, +> { + header_params.validate()?; + path_params.validate()?; -Ok(( - header_params, - path_params, -)) + Ok((header_params, path_params)) } /// DeletePet - DELETE /v2/pet/{petId} #[tracing::instrument(skip_all)] async fn delete_pet( - method: Method, - host: Host, - cookies: CookieJar, - headers: HeaderMap, - Path(path_params): Path, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + headers: HeaderMap, + Path(path_params): Path, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { // Header parameters let header_params = { - let header_api_key = headers.get(HeaderName::from_static("api_key")); + let header_api_key = headers.get(HeaderName::from_static("api_key")); - let header_api_key = match header_api_key { - Some(v) => match header::IntoHeaderValue::::try_from((*v).clone()) { - Ok(result) => - Some(result.0), - Err(err) => { - return Response::builder() - .status(StatusCode::BAD_REQUEST) - .body(Body::from(format!("Invalid header api_key - {}", err))).map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }); + let header_api_key = match header_api_key { + Some(v) => match header::IntoHeaderValue::::try_from((*v).clone()) { + Ok(result) => Some(result.0), + Err(err) => { + return Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Invalid header api_key - {}", err))) + .map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }); + } + }, + None => None, + }; - }, - }, - None => { - None - } - }; + models::DeletePetHeaderParams { + api_key: header_api_key, + } + }; - models::DeletePetHeaderParams { - api_key: header_api_key, - } - }; + #[allow(clippy::redundant_closure)] + let validation = + tokio::task::spawn_blocking(move || delete_pet_validation(header_params, path_params)) + .await + .unwrap(); - - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - delete_pet_validation( - header_params, - path_params, - ) - ).await.unwrap(); - - let Ok(( - header_params, - path_params, - )) = validation else { - return Response::builder() + let Ok((header_params, path_params)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().delete_pet( - method, - host, - cookies, - header_params, - path_params, - ).await; + let result = api_impl + .as_ref() + .delete_pet(method, host, cookies, header_params, path_params) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - DeletePetResponse::Status400_InvalidPetValue - => { + let resp = match result { + Ok(rsp) => match rsp { + DeletePetResponse::Status400_InvalidPetValue => { + let mut response = response.status(400); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(400); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] fn find_pets_by_status_validation( - query_params: models::FindPetsByStatusQueryParams, -) -> std::result::Result<( - models::FindPetsByStatusQueryParams, -), ValidationErrors> -{ - query_params.validate()?; + query_params: models::FindPetsByStatusQueryParams, +) -> std::result::Result<(models::FindPetsByStatusQueryParams,), ValidationErrors> { + query_params.validate()?; -Ok(( - query_params, -)) + Ok((query_params,)) } /// FindPetsByStatus - GET /v2/pet/findByStatus #[tracing::instrument(skip_all)] async fn find_pets_by_status( - method: Method, - host: Host, - cookies: CookieJar, - Query(query_params): Query, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + Query(query_params): Query, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = + tokio::task::spawn_blocking(move || find_pets_by_status_validation(query_params)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - find_pets_by_status_validation( - query_params, - ) - ).await.unwrap(); - - let Ok(( - query_params, - )) = validation else { - return Response::builder() + let Ok((query_params,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().find_pets_by_status( - method, - host, - cookies, - query_params, - ).await; + let result = api_impl + .as_ref() + .find_pets_by_status(method, host, cookies, query_params) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - FindPetsByStatusResponse::Status200_SuccessfulOperation - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + FindPetsByStatusResponse::Status200_SuccessfulOperation(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("text/plain").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("text/plain").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = body; + response.body(Body::from(body_content)) + } + FindPetsByStatusResponse::Status400_InvalidStatusValue => { + let mut response = response.status(400); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = body; - response.body(Body::from(body_content)) - }, - FindPetsByStatusResponse::Status400_InvalidStatusValue - => { - - let mut response = response.status(400); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] fn find_pets_by_tags_validation( - query_params: models::FindPetsByTagsQueryParams, -) -> std::result::Result<( - models::FindPetsByTagsQueryParams, -), ValidationErrors> -{ - query_params.validate()?; + query_params: models::FindPetsByTagsQueryParams, +) -> std::result::Result<(models::FindPetsByTagsQueryParams,), ValidationErrors> { + query_params.validate()?; -Ok(( - query_params, -)) + Ok((query_params,)) } /// FindPetsByTags - GET /v2/pet/findByTags #[tracing::instrument(skip_all)] async fn find_pets_by_tags( - method: Method, - host: Host, - cookies: CookieJar, - Query(query_params): Query, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + Query(query_params): Query, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = + tokio::task::spawn_blocking(move || find_pets_by_tags_validation(query_params)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - find_pets_by_tags_validation( - query_params, - ) - ).await.unwrap(); - - let Ok(( - query_params, - )) = validation else { - return Response::builder() + let Ok((query_params,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().find_pets_by_tags( - method, - host, - cookies, - query_params, - ).await; + let result = api_impl + .as_ref() + .find_pets_by_tags(method, host, cookies, query_params) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - FindPetsByTagsResponse::Status200_SuccessfulOperation - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + FindPetsByTagsResponse::Status200_SuccessfulOperation(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("text/plain").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("text/plain").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = body; + response.body(Body::from(body_content)) + } + FindPetsByTagsResponse::Status400_InvalidTagValue => { + let mut response = response.status(400); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = body; - response.body(Body::from(body_content)) - }, - FindPetsByTagsResponse::Status400_InvalidTagValue - => { - - let mut response = response.status(400); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] fn get_pet_by_id_validation( - path_params: models::GetPetByIdPathParams, -) -> std::result::Result<( - models::GetPetByIdPathParams, -), ValidationErrors> -{ - path_params.validate()?; + path_params: models::GetPetByIdPathParams, +) -> std::result::Result<(models::GetPetByIdPathParams,), ValidationErrors> { + path_params.validate()?; -Ok(( - path_params, -)) + Ok((path_params,)) } /// GetPetById - GET /v2/pet/{petId} #[tracing::instrument(skip_all)] async fn get_pet_by_id( - method: Method, - host: Host, - cookies: CookieJar, - Path(path_params): Path, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + Path(path_params): Path, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || get_pet_by_id_validation(path_params)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - get_pet_by_id_validation( - path_params, - ) - ).await.unwrap(); - - let Ok(( - path_params, - )) = validation else { - return Response::builder() + let Ok((path_params,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().get_pet_by_id( - method, - host, - cookies, - path_params, - ).await; + let result = api_impl + .as_ref() + .get_pet_by_id(method, host, cookies, path_params) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - GetPetByIdResponse::Status200_SuccessfulOperation - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + GetPetByIdResponse::Status200_SuccessfulOperation(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("text/plain").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("text/plain").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = body; + response.body(Body::from(body_content)) + } + GetPetByIdResponse::Status400_InvalidIDSupplied => { + let mut response = response.status(400); + response.body(Body::empty()) + } + GetPetByIdResponse::Status404_PetNotFound => { + let mut response = response.status(404); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = body; - response.body(Body::from(body_content)) - }, - GetPetByIdResponse::Status400_InvalidIDSupplied - => { - - let mut response = response.status(400); - response.body(Body::empty()) - }, - GetPetByIdResponse::Status404_PetNotFound - => { - - let mut response = response.status(404); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct UpdatePetBodyValidator<'a> { - #[validate] - body: &'a models::Pet, - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct UpdatePetBodyValidator<'a> { + #[validate] + body: &'a models::Pet, +} #[tracing::instrument(skip_all)] fn update_pet_validation( - body: models::Pet, -) -> std::result::Result<( - models::Pet, -), ValidationErrors> -{ - let b = UpdatePetBodyValidator { body: &body }; - b.validate()?; + body: models::Pet, +) -> std::result::Result<(models::Pet,), ValidationErrors> { + let b = UpdatePetBodyValidator { body: &body }; + b.validate()?; -Ok(( - body, -)) + Ok((body,)) } /// UpdatePet - PUT /v2/pet #[tracing::instrument(skip_all)] async fn update_pet( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - Json(body): Json, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + Json(body): Json, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || update_pet_validation(body)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - update_pet_validation( - body, - ) - ).await.unwrap(); - - let Ok(( - body, - )) = validation else { - return Response::builder() + let Ok((body,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().update_pet( - method, - host, - cookies, - body, - ).await; + let result = api_impl + .as_ref() + .update_pet(method, host, cookies, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - UpdatePetResponse::Status400_InvalidIDSupplied - => { + let resp = match result { + Ok(rsp) => match rsp { + UpdatePetResponse::Status400_InvalidIDSupplied => { + let mut response = response.status(400); + response.body(Body::empty()) + } + UpdatePetResponse::Status404_PetNotFound => { + let mut response = response.status(404); + response.body(Body::empty()) + } + UpdatePetResponse::Status405_ValidationException => { + let mut response = response.status(405); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(400); - response.body(Body::empty()) - }, - UpdatePetResponse::Status404_PetNotFound - => { - - let mut response = response.status(404); - response.body(Body::empty()) - }, - UpdatePetResponse::Status405_ValidationException - => { - - let mut response = response.status(405); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] fn update_pet_with_form_validation( - path_params: models::UpdatePetWithFormPathParams, -) -> std::result::Result<( - models::UpdatePetWithFormPathParams, -), ValidationErrors> -{ - path_params.validate()?; + path_params: models::UpdatePetWithFormPathParams, +) -> std::result::Result<(models::UpdatePetWithFormPathParams,), ValidationErrors> { + path_params.validate()?; -Ok(( - path_params, -)) + Ok((path_params,)) } /// UpdatePetWithForm - POST /v2/pet/{petId} #[tracing::instrument(skip_all)] async fn update_pet_with_form( - method: Method, - host: Host, - cookies: CookieJar, - Path(path_params): Path, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + Path(path_params): Path, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = + tokio::task::spawn_blocking(move || update_pet_with_form_validation(path_params)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - update_pet_with_form_validation( - path_params, - ) - ).await.unwrap(); - - let Ok(( - path_params, - )) = validation else { - return Response::builder() + let Ok((path_params,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().update_pet_with_form( - method, - host, - cookies, - path_params, - ).await; + let result = api_impl + .as_ref() + .update_pet_with_form(method, host, cookies, path_params) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - UpdatePetWithFormResponse::Status405_InvalidInput - => { + let resp = match result { + Ok(rsp) => match rsp { + UpdatePetWithFormResponse::Status405_InvalidInput => { + let mut response = response.status(405); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(405); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] fn upload_file_validation( - path_params: models::UploadFilePathParams, -) -> std::result::Result<( - models::UploadFilePathParams, -), ValidationErrors> -{ - path_params.validate()?; + path_params: models::UploadFilePathParams, +) -> std::result::Result<(models::UploadFilePathParams,), ValidationErrors> { + path_params.validate()?; -Ok(( - path_params, -)) + Ok((path_params,)) } /// UploadFile - POST /v2/pet/{petId}/uploadImage #[tracing::instrument(skip_all)] async fn upload_file( - method: Method, - host: Host, - cookies: CookieJar, - Path(path_params): Path, - State(api_impl): State, - body: Multipart, + method: Method, + host: Host, + cookies: CookieJar, + Path(path_params): Path, + State(api_impl): State, + body: Multipart, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || upload_file_validation(path_params)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - upload_file_validation( - path_params, - ) - ).await.unwrap(); - - let Ok(( - path_params, - )) = validation else { - return Response::builder() + let Ok((path_params,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().upload_file( - method, - host, - cookies, - path_params, - body, - ).await; + let result = api_impl + .as_ref() + .upload_file(method, host, cookies, path_params, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - UploadFileResponse::Status200_SuccessfulOperation - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + UploadFileResponse::Status200_SuccessfulOperation(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("application/json").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("application/json").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = tokio::task::spawn_blocking(move || { + serde_json::to_vec(&body).map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) + }) + .await + .unwrap()?; + response.body(Body::from(body_content)) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = tokio::task::spawn_blocking(move || - serde_json::to_vec(&body).map_err(|e| { - error!(error = ?e); - StatusCode::INTERNAL_SERVER_ERROR - })).await.unwrap()?; - response.body(Body::from(body_content)) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] fn delete_order_validation( - path_params: models::DeleteOrderPathParams, -) -> std::result::Result<( - models::DeleteOrderPathParams, -), ValidationErrors> -{ - path_params.validate()?; + path_params: models::DeleteOrderPathParams, +) -> std::result::Result<(models::DeleteOrderPathParams,), ValidationErrors> { + path_params.validate()?; -Ok(( - path_params, -)) + Ok((path_params,)) } /// DeleteOrder - DELETE /v2/store/order/{order_id} #[tracing::instrument(skip_all)] async fn delete_order( - method: Method, - host: Host, - cookies: CookieJar, - Path(path_params): Path, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + Path(path_params): Path, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || delete_order_validation(path_params)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - delete_order_validation( - path_params, - ) - ).await.unwrap(); - - let Ok(( - path_params, - )) = validation else { - return Response::builder() + let Ok((path_params,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().delete_order( - method, - host, - cookies, - path_params, - ).await; + let result = api_impl + .as_ref() + .delete_order(method, host, cookies, path_params) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - DeleteOrderResponse::Status400_InvalidIDSupplied - => { + let resp = match result { + Ok(rsp) => match rsp { + DeleteOrderResponse::Status400_InvalidIDSupplied => { + let mut response = response.status(400); + response.body(Body::empty()) + } + DeleteOrderResponse::Status404_OrderNotFound => { + let mut response = response.status(404); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(400); - response.body(Body::empty()) - }, - DeleteOrderResponse::Status404_OrderNotFound - => { - - let mut response = response.status(404); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] -fn get_inventory_validation( -) -> std::result::Result<( -), ValidationErrors> -{ - -Ok(( -)) +fn get_inventory_validation() -> std::result::Result<(), ValidationErrors> { + Ok(()) } /// GetInventory - GET /v2/store/inventory #[tracing::instrument(skip_all)] async fn get_inventory( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || get_inventory_validation()) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - get_inventory_validation( - ) - ).await.unwrap(); - - let Ok(( - )) = validation else { - return Response::builder() + let Ok(()) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().get_inventory( - method, - host, - cookies, - ).await; + let result = api_impl.as_ref().get_inventory(method, host, cookies).await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - GetInventoryResponse::Status200_SuccessfulOperation - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + GetInventoryResponse::Status200_SuccessfulOperation(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("application/json").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("application/json").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = tokio::task::spawn_blocking(move || { + serde_json::to_vec(&body).map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) + }) + .await + .unwrap()?; + response.body(Body::from(body_content)) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = tokio::task::spawn_blocking(move || - serde_json::to_vec(&body).map_err(|e| { - error!(error = ?e); - StatusCode::INTERNAL_SERVER_ERROR - })).await.unwrap()?; - response.body(Body::from(body_content)) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] fn get_order_by_id_validation( - path_params: models::GetOrderByIdPathParams, -) -> std::result::Result<( - models::GetOrderByIdPathParams, -), ValidationErrors> -{ - path_params.validate()?; + path_params: models::GetOrderByIdPathParams, +) -> std::result::Result<(models::GetOrderByIdPathParams,), ValidationErrors> { + path_params.validate()?; -Ok(( - path_params, -)) + Ok((path_params,)) } /// GetOrderById - GET /v2/store/order/{order_id} #[tracing::instrument(skip_all)] async fn get_order_by_id( - method: Method, - host: Host, - cookies: CookieJar, - Path(path_params): Path, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + Path(path_params): Path, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || get_order_by_id_validation(path_params)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - get_order_by_id_validation( - path_params, - ) - ).await.unwrap(); - - let Ok(( - path_params, - )) = validation else { - return Response::builder() + let Ok((path_params,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().get_order_by_id( - method, - host, - cookies, - path_params, - ).await; + let result = api_impl + .as_ref() + .get_order_by_id(method, host, cookies, path_params) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - GetOrderByIdResponse::Status200_SuccessfulOperation - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + GetOrderByIdResponse::Status200_SuccessfulOperation(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("text/plain").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("text/plain").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = body; + response.body(Body::from(body_content)) + } + GetOrderByIdResponse::Status400_InvalidIDSupplied => { + let mut response = response.status(400); + response.body(Body::empty()) + } + GetOrderByIdResponse::Status404_OrderNotFound => { + let mut response = response.status(404); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = body; - response.body(Body::from(body_content)) - }, - GetOrderByIdResponse::Status400_InvalidIDSupplied - => { - - let mut response = response.status(400); - response.body(Body::empty()) - }, - GetOrderByIdResponse::Status404_OrderNotFound - => { - - let mut response = response.status(404); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct PlaceOrderBodyValidator<'a> { - #[validate] - body: &'a models::Order, - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct PlaceOrderBodyValidator<'a> { + #[validate] + body: &'a models::Order, +} #[tracing::instrument(skip_all)] fn place_order_validation( - body: models::Order, -) -> std::result::Result<( - models::Order, -), ValidationErrors> -{ - let b = PlaceOrderBodyValidator { body: &body }; - b.validate()?; + body: models::Order, +) -> std::result::Result<(models::Order,), ValidationErrors> { + let b = PlaceOrderBodyValidator { body: &body }; + b.validate()?; -Ok(( - body, -)) + Ok((body,)) } /// PlaceOrder - POST /v2/store/order #[tracing::instrument(skip_all)] async fn place_order( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - Json(body): Json, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + Json(body): Json, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || place_order_validation(body)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - place_order_validation( - body, - ) - ).await.unwrap(); - - let Ok(( - body, - )) = validation else { - return Response::builder() + let Ok((body,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().place_order( - method, - host, - cookies, - body, - ).await; + let result = api_impl + .as_ref() + .place_order(method, host, cookies, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - PlaceOrderResponse::Status200_SuccessfulOperation - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + PlaceOrderResponse::Status200_SuccessfulOperation(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("text/plain").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("text/plain").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = body; + response.body(Body::from(body_content)) + } + PlaceOrderResponse::Status400_InvalidOrder => { + let mut response = response.status(400); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = body; - response.body(Body::from(body_content)) - }, - PlaceOrderResponse::Status400_InvalidOrder - => { - - let mut response = response.status(400); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct CreateUserBodyValidator<'a> { - #[validate] - body: &'a models::User, - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct CreateUserBodyValidator<'a> { + #[validate] + body: &'a models::User, +} #[tracing::instrument(skip_all)] fn create_user_validation( - body: models::User, -) -> std::result::Result<( - models::User, -), ValidationErrors> -{ - let b = CreateUserBodyValidator { body: &body }; - b.validate()?; + body: models::User, +) -> std::result::Result<(models::User,), ValidationErrors> { + let b = CreateUserBodyValidator { body: &body }; + b.validate()?; -Ok(( - body, -)) + Ok((body,)) } /// CreateUser - POST /v2/user #[tracing::instrument(skip_all)] async fn create_user( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - Json(body): Json, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + Json(body): Json, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || create_user_validation(body)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - create_user_validation( - body, - ) - ).await.unwrap(); - - let Ok(( - body, - )) = validation else { - return Response::builder() + let Ok((body,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().create_user( - method, - host, - cookies, - body, - ).await; + let result = api_impl + .as_ref() + .create_user(method, host, cookies, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - CreateUserResponse::Status0_SuccessfulOperation - => { + let resp = match result { + Ok(rsp) => match rsp { + CreateUserResponse::Status0_SuccessfulOperation => { + let mut response = response.status(0); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(0); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct CreateUsersWithArrayInputBodyValidator<'a> { - #[validate] - body: &'a Vec, - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct CreateUsersWithArrayInputBodyValidator<'a> { + #[validate] + body: &'a Vec, +} #[tracing::instrument(skip_all)] fn create_users_with_array_input_validation( - body: Vec, -) -> std::result::Result<( - Vec, -), ValidationErrors> -{ - let b = CreateUsersWithArrayInputBodyValidator { body: &body }; - b.validate()?; + body: Vec, +) -> std::result::Result<(Vec,), ValidationErrors> { + let b = CreateUsersWithArrayInputBodyValidator { body: &body }; + b.validate()?; -Ok(( - body, -)) + Ok((body,)) } /// CreateUsersWithArrayInput - POST /v2/user/createWithArray #[tracing::instrument(skip_all)] async fn create_users_with_array_input( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - Json(body): Json>, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + Json(body): Json>, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = + tokio::task::spawn_blocking(move || create_users_with_array_input_validation(body)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - create_users_with_array_input_validation( - body, - ) - ).await.unwrap(); - - let Ok(( - body, - )) = validation else { - return Response::builder() + let Ok((body,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().create_users_with_array_input( - method, - host, - cookies, - body, - ).await; + let result = api_impl + .as_ref() + .create_users_with_array_input(method, host, cookies, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - CreateUsersWithArrayInputResponse::Status0_SuccessfulOperation - => { + let resp = match result { + Ok(rsp) => match rsp { + CreateUsersWithArrayInputResponse::Status0_SuccessfulOperation => { + let mut response = response.status(0); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(0); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct CreateUsersWithListInputBodyValidator<'a> { - #[validate] - body: &'a Vec, - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct CreateUsersWithListInputBodyValidator<'a> { + #[validate] + body: &'a Vec, +} #[tracing::instrument(skip_all)] fn create_users_with_list_input_validation( - body: Vec, -) -> std::result::Result<( - Vec, -), ValidationErrors> -{ - let b = CreateUsersWithListInputBodyValidator { body: &body }; - b.validate()?; + body: Vec, +) -> std::result::Result<(Vec,), ValidationErrors> { + let b = CreateUsersWithListInputBodyValidator { body: &body }; + b.validate()?; -Ok(( - body, -)) + Ok((body,)) } /// CreateUsersWithListInput - POST /v2/user/createWithList #[tracing::instrument(skip_all)] async fn create_users_with_list_input( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - Json(body): Json>, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + Json(body): Json>, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = + tokio::task::spawn_blocking(move || create_users_with_list_input_validation(body)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - create_users_with_list_input_validation( - body, - ) - ).await.unwrap(); - - let Ok(( - body, - )) = validation else { - return Response::builder() + let Ok((body,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().create_users_with_list_input( - method, - host, - cookies, - body, - ).await; + let result = api_impl + .as_ref() + .create_users_with_list_input(method, host, cookies, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - CreateUsersWithListInputResponse::Status0_SuccessfulOperation - => { + let resp = match result { + Ok(rsp) => match rsp { + CreateUsersWithListInputResponse::Status0_SuccessfulOperation => { + let mut response = response.status(0); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(0); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] fn delete_user_validation( - path_params: models::DeleteUserPathParams, -) -> std::result::Result<( - models::DeleteUserPathParams, -), ValidationErrors> -{ - path_params.validate()?; + path_params: models::DeleteUserPathParams, +) -> std::result::Result<(models::DeleteUserPathParams,), ValidationErrors> { + path_params.validate()?; -Ok(( - path_params, -)) + Ok((path_params,)) } /// DeleteUser - DELETE /v2/user/{username} #[tracing::instrument(skip_all)] async fn delete_user( - method: Method, - host: Host, - cookies: CookieJar, - Path(path_params): Path, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + Path(path_params): Path, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || delete_user_validation(path_params)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - delete_user_validation( - path_params, - ) - ).await.unwrap(); - - let Ok(( - path_params, - )) = validation else { - return Response::builder() + let Ok((path_params,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().delete_user( - method, - host, - cookies, - path_params, - ).await; + let result = api_impl + .as_ref() + .delete_user(method, host, cookies, path_params) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - DeleteUserResponse::Status400_InvalidUsernameSupplied - => { + let resp = match result { + Ok(rsp) => match rsp { + DeleteUserResponse::Status400_InvalidUsernameSupplied => { + let mut response = response.status(400); + response.body(Body::empty()) + } + DeleteUserResponse::Status404_UserNotFound => { + let mut response = response.status(404); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(400); - response.body(Body::empty()) - }, - DeleteUserResponse::Status404_UserNotFound - => { - - let mut response = response.status(404); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] fn get_user_by_name_validation( - path_params: models::GetUserByNamePathParams, -) -> std::result::Result<( - models::GetUserByNamePathParams, -), ValidationErrors> -{ - path_params.validate()?; + path_params: models::GetUserByNamePathParams, +) -> std::result::Result<(models::GetUserByNamePathParams,), ValidationErrors> { + path_params.validate()?; -Ok(( - path_params, -)) + Ok((path_params,)) } /// GetUserByName - GET /v2/user/{username} #[tracing::instrument(skip_all)] async fn get_user_by_name( - method: Method, - host: Host, - cookies: CookieJar, - Path(path_params): Path, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + Path(path_params): Path, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || get_user_by_name_validation(path_params)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - get_user_by_name_validation( - path_params, - ) - ).await.unwrap(); - - let Ok(( - path_params, - )) = validation else { - return Response::builder() + let Ok((path_params,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().get_user_by_name( - method, - host, - cookies, - path_params, - ).await; + let result = api_impl + .as_ref() + .get_user_by_name(method, host, cookies, path_params) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - GetUserByNameResponse::Status200_SuccessfulOperation - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + GetUserByNameResponse::Status200_SuccessfulOperation(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("text/plain").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("text/plain").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = body; + response.body(Body::from(body_content)) + } + GetUserByNameResponse::Status400_InvalidUsernameSupplied => { + let mut response = response.status(400); + response.body(Body::empty()) + } + GetUserByNameResponse::Status404_UserNotFound => { + let mut response = response.status(404); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = body; - response.body(Body::from(body_content)) - }, - GetUserByNameResponse::Status400_InvalidUsernameSupplied - => { - - let mut response = response.status(400); - response.body(Body::empty()) - }, - GetUserByNameResponse::Status404_UserNotFound - => { - - let mut response = response.status(404); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] fn login_user_validation( - query_params: models::LoginUserQueryParams, -) -> std::result::Result<( - models::LoginUserQueryParams, -), ValidationErrors> -{ - query_params.validate()?; + query_params: models::LoginUserQueryParams, +) -> std::result::Result<(models::LoginUserQueryParams,), ValidationErrors> { + query_params.validate()?; -Ok(( - query_params, -)) + Ok((query_params,)) } /// LoginUser - GET /v2/user/login #[tracing::instrument(skip_all)] async fn login_user( - method: Method, - host: Host, - cookies: CookieJar, - Query(query_params): Query, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + Query(query_params): Query, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || login_user_validation(query_params)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - login_user_validation( - query_params, - ) - ).await.unwrap(); - - let Ok(( - query_params, - )) = validation else { - return Response::builder() + let Ok((query_params,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().login_user( - method, - host, - cookies, - query_params, - ).await; + let result = api_impl + .as_ref() + .login_user(method, host, cookies, query_params) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - LoginUserResponse::Status200_SuccessfulOperation - { - body, - x_rate_limit, - x_expires_after - } - => { - if let Some(x_rate_limit) = x_rate_limit { - let x_rate_limit = match header::IntoHeaderValue(x_rate_limit).try_into() { - Ok(val) => val, - Err(e) => { - return Response::builder() + let resp = match result { + Ok(rsp) => match rsp { + LoginUserResponse::Status200_SuccessfulOperation { + body, + x_rate_limit, + x_expires_after, + } => { + if let Some(x_rate_limit) = x_rate_limit { + let x_rate_limit = match header::IntoHeaderValue(x_rate_limit).try_into() { + Ok(val) => val, + Err(e) => { + return Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling x_rate_limit header - {}", e))).map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }); - } - }; + } + }; - - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - HeaderName::from_static("x-rate-limit"), - x_rate_limit - ); - } - } - if let Some(x_expires_after) = x_expires_after { - let x_expires_after = match header::IntoHeaderValue(x_expires_after).try_into() { - Ok(val) => val, - Err(e) => { - return Response::builder() + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers + .insert(HeaderName::from_static("x-rate-limit"), x_rate_limit); + } + } + if let Some(x_expires_after) = x_expires_after { + let x_expires_after = match header::IntoHeaderValue(x_expires_after).try_into() + { + Ok(val) => val, + Err(e) => { + return Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling x_expires_after header - {}", e))).map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }); - } - }; + } + }; - - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - HeaderName::from_static("x-expires-after"), - x_expires_after - ); - } - } + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers + .insert(HeaderName::from_static("x-expires-after"), x_expires_after); + } + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("text/plain").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("text/plain").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let body_content = body; - response.body(Body::from(body_content)) - }, - LoginUserResponse::Status400_InvalidUsername - => { + let body_content = body; + response.body(Body::from(body_content)) + } + LoginUserResponse::Status400_InvalidUsername => { + let mut response = response.status(400); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(400); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] -fn logout_user_validation( -) -> std::result::Result<( -), ValidationErrors> -{ - -Ok(( -)) +fn logout_user_validation() -> std::result::Result<(), ValidationErrors> { + Ok(()) } /// LogoutUser - GET /v2/user/logout #[tracing::instrument(skip_all)] async fn logout_user( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || logout_user_validation()) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - logout_user_validation( - ) - ).await.unwrap(); - - let Ok(( - )) = validation else { - return Response::builder() + let Ok(()) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().logout_user( - method, - host, - cookies, - ).await; + let result = api_impl.as_ref().logout_user(method, host, cookies).await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - LogoutUserResponse::Status0_SuccessfulOperation - => { + let resp = match result { + Ok(rsp) => match rsp { + LogoutUserResponse::Status0_SuccessfulOperation => { + let mut response = response.status(0); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(0); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct UpdateUserBodyValidator<'a> { - #[validate] - body: &'a models::User, - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct UpdateUserBodyValidator<'a> { + #[validate] + body: &'a models::User, +} #[tracing::instrument(skip_all)] fn update_user_validation( - path_params: models::UpdateUserPathParams, - body: models::User, -) -> std::result::Result<( - models::UpdateUserPathParams, - models::User, -), ValidationErrors> -{ - path_params.validate()?; - let b = UpdateUserBodyValidator { body: &body }; - b.validate()?; + path_params: models::UpdateUserPathParams, + body: models::User, +) -> std::result::Result<(models::UpdateUserPathParams, models::User), ValidationErrors> { + path_params.validate()?; + let b = UpdateUserBodyValidator { body: &body }; + b.validate()?; -Ok(( - path_params, - body, -)) + Ok((path_params, body)) } /// UpdateUser - PUT /v2/user/{username} #[tracing::instrument(skip_all)] async fn update_user( - method: Method, - host: Host, - cookies: CookieJar, - Path(path_params): Path, - State(api_impl): State, - Json(body): Json, + method: Method, + host: Host, + cookies: CookieJar, + Path(path_params): Path, + State(api_impl): State, + Json(body): Json, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || update_user_validation(path_params, body)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - update_user_validation( - path_params, - body, - ) - ).await.unwrap(); - - let Ok(( - path_params, - body, - )) = validation else { - return Response::builder() + let Ok((path_params, body)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().update_user( - method, - host, - cookies, - path_params, - body, - ).await; + let result = api_impl + .as_ref() + .update_user(method, host, cookies, path_params, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - UpdateUserResponse::Status400_InvalidUserSupplied - => { + let resp = match result { + Ok(rsp) => match rsp { + UpdateUserResponse::Status400_InvalidUserSupplied => { + let mut response = response.status(400); + response.body(Body::empty()) + } + UpdateUserResponse::Status404_UserNotFound => { + let mut response = response.status(404); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(400); - response.body(Body::empty()) - }, - UpdateUserResponse::Status404_UserNotFound - => { - - let mut response = response.status(404); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - diff --git a/samples/server/petstore/rust-axum/output/petstore/src/header.rs b/samples/server/petstore/rust-axum/output/petstore/src/header.rs index 4d1cc4c6dcc..7c530892fbf 100644 --- a/samples/server/petstore/rust-axum/output/petstore/src/header.rs +++ b/samples/server/petstore/rust-axum/output/petstore/src/header.rs @@ -30,11 +30,16 @@ macro_rules! ihv_generate { match hdr_value.to_str() { Ok(hdr_value) => match hdr_value.parse::<$t>() { Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value)), - Err(e) => Err(format!("Unable to parse {} as a string: {}", - stringify!($t), e)), + Err(e) => Err(format!( + "Unable to parse {} as a string: {}", + stringify!($t), + e + )), }, - Err(e) => Err(format!("Unable to parse header {:?} as a string - {}", - hdr_value, e)), + Err(e) => Err(format!( + "Unable to parse header {:?} as a string - {}", + hdr_value, e + )), } } } @@ -69,14 +74,17 @@ impl TryFrom for IntoHeaderValue> { match hdr_value.to_str() { Ok(hdr_value) => Ok(IntoHeaderValue( hdr_value - .split(',') - .filter_map(|x| match x.trim() { - "" => None, - y => Some(y.to_string()), - }) - .collect())), - Err(e) => Err(format!("Unable to parse header: {:?} as a string - {}", - hdr_value, e)), + .split(',') + .filter_map(|x| match x.trim() { + "" => None, + y => Some(y.to_string()), + }) + .collect(), + )), + Err(e) => Err(format!( + "Unable to parse header: {:?} as a string - {}", + hdr_value, e + )), } } } @@ -85,11 +93,13 @@ impl TryFrom>> for HeaderValue { type Error = String; fn try_from(hdr_value: IntoHeaderValue>) -> Result { - match HeaderValue::from_str(&hdr_value.0.join(", ")) { - Ok(hdr_value) => Ok(hdr_value), - Err(e) => Err(format!("Unable to convert {:?} into a header - {}", - hdr_value, e)) - } + match HeaderValue::from_str(&hdr_value.0.join(", ")) { + Ok(hdr_value) => Ok(hdr_value), + Err(e) => Err(format!( + "Unable to convert {:?} into a header - {}", + hdr_value, e + )), + } } } @@ -101,8 +111,7 @@ impl TryFrom for IntoHeaderValue { fn try_from(hdr_value: HeaderValue) -> Result { match hdr_value.to_str() { Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value.to_string())), - Err(e) => Err(format!("Unable to convert header {:?} to {}", - hdr_value, e)), + Err(e) => Err(format!("Unable to convert header {:?} to {}", hdr_value, e)), } } } @@ -113,8 +122,10 @@ impl TryFrom> for HeaderValue { fn try_from(hdr_value: IntoHeaderValue) -> Result { match HeaderValue::from_str(&hdr_value.0) { Ok(hdr_value) => Ok(hdr_value), - Err(e) => Err(format!("Unable to convert {:?} from a header {}", - hdr_value, e)) + Err(e) => Err(format!( + "Unable to convert {:?} from a header {}", + hdr_value, e + )), } } } @@ -128,11 +139,12 @@ impl TryFrom for IntoHeaderValue { match hdr_value.to_str() { Ok(hdr_value) => match hdr_value.parse() { Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value)), - Err(e) => Err(format!("Unable to parse bool from {} - {}", - hdr_value, e)), + Err(e) => Err(format!("Unable to parse bool from {} - {}", hdr_value, e)), }, - Err(e) => Err(format!("Unable to convert {:?} from a header {}", - hdr_value, e)), + Err(e) => Err(format!( + "Unable to convert {:?} from a header {}", + hdr_value, e + )), } } } @@ -143,8 +155,10 @@ impl TryFrom> for HeaderValue { fn try_from(hdr_value: IntoHeaderValue) -> Result { match HeaderValue::from_str(&hdr_value.0.to_string()) { Ok(hdr_value) => Ok(hdr_value), - Err(e) => Err(format!("Unable to convert: {:?} into a header: {}", - hdr_value, e)) + Err(e) => Err(format!( + "Unable to convert: {:?} into a header: {}", + hdr_value, e + )), } } } @@ -158,11 +172,12 @@ impl TryFrom for IntoHeaderValue> { match hdr_value.to_str() { Ok(hdr_value) => match DateTime::parse_from_rfc3339(hdr_value) { Ok(date) => Ok(IntoHeaderValue(date.with_timezone(&Utc))), - Err(e) => Err(format!("Unable to parse: {} as date - {}", - hdr_value, e)), + Err(e) => Err(format!("Unable to parse: {} as date - {}", hdr_value, e)), }, - Err(e) => Err(format!("Unable to convert header {:?} to string {}", - hdr_value, e)), + Err(e) => Err(format!( + "Unable to convert header {:?} to string {}", + hdr_value, e + )), } } } @@ -173,8 +188,10 @@ impl TryFrom>> for HeaderValue { fn try_from(hdr_value: IntoHeaderValue>) -> Result { match HeaderValue::from_str(hdr_value.0.to_rfc3339().as_str()) { Ok(hdr_value) => Ok(hdr_value), - Err(e) => Err(format!("Unable to convert {:?} to a header: {}", - hdr_value, e)), + Err(e) => Err(format!( + "Unable to convert {:?} to a header: {}", + hdr_value, e + )), } } } diff --git a/samples/server/petstore/rust-axum/output/petstore/src/lib.rs b/samples/server/petstore/rust-axum/output/petstore/src/lib.rs index 287ff425af9..eef1a4fbdc1 100644 --- a/samples/server/petstore/rust-axum/output/petstore/src/lib.rs +++ b/samples/server/petstore/rust-axum/output/petstore/src/lib.rs @@ -1,4 +1,12 @@ -#![allow(missing_docs, trivial_casts, unused_variables, unused_mut, unused_imports, unused_extern_crates, non_camel_case_types)] +#![allow( + missing_docs, + trivial_casts, + unused_variables, + unused_mut, + unused_imports, + unused_extern_crates, + non_camel_case_types +)] #![allow(unused_imports, unused_attributes)] #![allow(clippy::derive_partial_eq_without_eq, clippy::disallowed_names)] @@ -14,490 +22,429 @@ use types::*; pub const BASE_PATH: &str = "/v2"; pub const API_VERSION: &str = "1.0.0"; - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum AddPetResponse { /// successful operation - Status200_SuccessfulOperation - (String) - , + Status200_SuccessfulOperation(String), /// Invalid input - Status405_InvalidInput + Status405_InvalidInput, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum DeletePetResponse { /// Invalid pet value - Status400_InvalidPetValue + Status400_InvalidPetValue, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum FindPetsByStatusResponse { /// successful operation - Status200_SuccessfulOperation - (String) - , + Status200_SuccessfulOperation(String), /// Invalid status value - Status400_InvalidStatusValue + Status400_InvalidStatusValue, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum FindPetsByTagsResponse { /// successful operation - Status200_SuccessfulOperation - (String) - , + Status200_SuccessfulOperation(String), /// Invalid tag value - Status400_InvalidTagValue + Status400_InvalidTagValue, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum GetPetByIdResponse { /// successful operation - Status200_SuccessfulOperation - (String) - , + Status200_SuccessfulOperation(String), /// Invalid ID supplied - Status400_InvalidIDSupplied - , + Status400_InvalidIDSupplied, /// Pet not found - Status404_PetNotFound + Status404_PetNotFound, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum UpdatePetResponse { /// successful operation - Status200_SuccessfulOperation - (String) - , + Status200_SuccessfulOperation(String), /// Invalid ID supplied - Status400_InvalidIDSupplied - , + Status400_InvalidIDSupplied, /// Pet not found - Status404_PetNotFound - , + Status404_PetNotFound, /// Validation exception - Status405_ValidationException + Status405_ValidationException, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum UpdatePetWithFormResponse { /// Invalid input - Status405_InvalidInput + Status405_InvalidInput, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum UploadFileResponse { /// successful operation - Status200_SuccessfulOperation - (models::ApiResponse) + Status200_SuccessfulOperation(models::ApiResponse), } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum DeleteOrderResponse { /// Invalid ID supplied - Status400_InvalidIDSupplied - , + Status400_InvalidIDSupplied, /// Order not found - Status404_OrderNotFound + Status404_OrderNotFound, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum GetInventoryResponse { /// successful operation - Status200_SuccessfulOperation - (std::collections::HashMap) + Status200_SuccessfulOperation(std::collections::HashMap), } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum GetOrderByIdResponse { /// successful operation - Status200_SuccessfulOperation - (String) - , + Status200_SuccessfulOperation(String), /// Invalid ID supplied - Status400_InvalidIDSupplied - , + Status400_InvalidIDSupplied, /// Order not found - Status404_OrderNotFound + Status404_OrderNotFound, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum PlaceOrderResponse { /// successful operation - Status200_SuccessfulOperation - (String) - , + Status200_SuccessfulOperation(String), /// Invalid Order - Status400_InvalidOrder + Status400_InvalidOrder, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum CreateUserResponse { /// successful operation - Status0_SuccessfulOperation + Status0_SuccessfulOperation, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum CreateUsersWithArrayInputResponse { /// successful operation - Status0_SuccessfulOperation + Status0_SuccessfulOperation, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum CreateUsersWithListInputResponse { /// successful operation - Status0_SuccessfulOperation + Status0_SuccessfulOperation, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum DeleteUserResponse { /// Invalid username supplied - Status400_InvalidUsernameSupplied - , + Status400_InvalidUsernameSupplied, /// User not found - Status404_UserNotFound + Status404_UserNotFound, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum GetUserByNameResponse { /// successful operation - Status200_SuccessfulOperation - (String) - , + Status200_SuccessfulOperation(String), /// Invalid username supplied - Status400_InvalidUsernameSupplied - , + Status400_InvalidUsernameSupplied, /// User not found - Status404_UserNotFound + Status404_UserNotFound, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum LoginUserResponse { /// successful operation - Status200_SuccessfulOperation - { + Status200_SuccessfulOperation { body: String, - set_cookie: - Option< - String - > - , - x_rate_limit: - Option< - i32 - > - , - x_expires_after: - Option< - chrono::DateTime:: - > - } - , + set_cookie: Option, + x_rate_limit: Option, + x_expires_after: Option>, + }, /// Invalid username/password supplied - Status400_InvalidUsername + Status400_InvalidUsername, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum LogoutUserResponse { /// successful operation - Status0_SuccessfulOperation + Status0_SuccessfulOperation, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum UpdateUserResponse { /// Invalid user supplied - Status400_InvalidUserSupplied - , + Status400_InvalidUserSupplied, /// User not found - Status404_UserNotFound + Status404_UserNotFound, } - /// API #[async_trait] #[allow(clippy::ptr_arg)] pub trait Api { + /// Add a new pet to the store. + /// + /// AddPet - POST /v2/pet + async fn add_pet( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: models::Pet, + ) -> Result; - /// Add a new pet to the store. - /// - /// AddPet - POST /v2/pet - async fn add_pet( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::Pet, - ) -> Result; + /// Deletes a pet. + /// + /// DeletePet - DELETE /v2/pet/{petId} + async fn delete_pet( + &self, + method: Method, + host: Host, + cookies: CookieJar, + header_params: models::DeletePetHeaderParams, + path_params: models::DeletePetPathParams, + ) -> Result; + /// Finds Pets by status. + /// + /// FindPetsByStatus - GET /v2/pet/findByStatus + async fn find_pets_by_status( + &self, + method: Method, + host: Host, + cookies: CookieJar, + query_params: models::FindPetsByStatusQueryParams, + ) -> Result; - /// Deletes a pet. - /// - /// DeletePet - DELETE /v2/pet/{petId} - async fn delete_pet( - &self, - method: Method, - host: Host, - cookies: CookieJar, - header_params: models::DeletePetHeaderParams, - path_params: models::DeletePetPathParams, - ) -> Result; + /// Finds Pets by tags. + /// + /// FindPetsByTags - GET /v2/pet/findByTags + async fn find_pets_by_tags( + &self, + method: Method, + host: Host, + cookies: CookieJar, + query_params: models::FindPetsByTagsQueryParams, + ) -> Result; + /// Find pet by ID. + /// + /// GetPetById - GET /v2/pet/{petId} + async fn get_pet_by_id( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::GetPetByIdPathParams, + ) -> Result; - /// Finds Pets by status. - /// - /// FindPetsByStatus - GET /v2/pet/findByStatus - async fn find_pets_by_status( - &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::FindPetsByStatusQueryParams, - ) -> Result; + /// Update an existing pet. + /// + /// UpdatePet - PUT /v2/pet + async fn update_pet( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: models::Pet, + ) -> Result; + /// Updates a pet in the store with form data. + /// + /// UpdatePetWithForm - POST /v2/pet/{petId} + async fn update_pet_with_form( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::UpdatePetWithFormPathParams, + ) -> Result; - /// Finds Pets by tags. - /// - /// FindPetsByTags - GET /v2/pet/findByTags - async fn find_pets_by_tags( - &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::FindPetsByTagsQueryParams, - ) -> Result; + /// uploads an image. + /// + /// UploadFile - POST /v2/pet/{petId}/uploadImage + async fn upload_file( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::UploadFilePathParams, + body: Multipart, + ) -> Result; + /// Delete purchase order by ID. + /// + /// DeleteOrder - DELETE /v2/store/order/{orderId} + async fn delete_order( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::DeleteOrderPathParams, + ) -> Result; - /// Find pet by ID. - /// - /// GetPetById - GET /v2/pet/{petId} - async fn get_pet_by_id( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::GetPetByIdPathParams, - ) -> Result; + /// Returns pet inventories by status. + /// + /// GetInventory - GET /v2/store/inventory + async fn get_inventory( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Find purchase order by ID. + /// + /// GetOrderById - GET /v2/store/order/{orderId} + async fn get_order_by_id( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::GetOrderByIdPathParams, + ) -> Result; - /// Update an existing pet. - /// - /// UpdatePet - PUT /v2/pet - async fn update_pet( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::Pet, - ) -> Result; + /// Place an order for a pet. + /// + /// PlaceOrder - POST /v2/store/order + async fn place_order( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: models::Order, + ) -> Result; + /// Create user. + /// + /// CreateUser - POST /v2/user + async fn create_user( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: models::User, + ) -> Result; - /// Updates a pet in the store with form data. - /// - /// UpdatePetWithForm - POST /v2/pet/{petId} - async fn update_pet_with_form( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::UpdatePetWithFormPathParams, - ) -> Result; + /// Creates list of users with given input array. + /// + /// CreateUsersWithArrayInput - POST /v2/user/createWithArray + async fn create_users_with_array_input( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: Vec, + ) -> Result; + /// Creates list of users with given input array. + /// + /// CreateUsersWithListInput - POST /v2/user/createWithList + async fn create_users_with_list_input( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: Vec, + ) -> Result; - /// uploads an image. - /// - /// UploadFile - POST /v2/pet/{petId}/uploadImage - async fn upload_file( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::UploadFilePathParams, - body: Multipart, - ) -> Result; + /// Delete user. + /// + /// DeleteUser - DELETE /v2/user/{username} + async fn delete_user( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::DeleteUserPathParams, + ) -> Result; + /// Get user by user name. + /// + /// GetUserByName - GET /v2/user/{username} + async fn get_user_by_name( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::GetUserByNamePathParams, + ) -> Result; - /// Delete purchase order by ID. - /// - /// DeleteOrder - DELETE /v2/store/order/{orderId} - async fn delete_order( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::DeleteOrderPathParams, - ) -> Result; + /// Logs user into the system. + /// + /// LoginUser - GET /v2/user/login + async fn login_user( + &self, + method: Method, + host: Host, + cookies: CookieJar, + query_params: models::LoginUserQueryParams, + ) -> Result; + /// Logs out current logged in user session. + /// + /// LogoutUser - GET /v2/user/logout + async fn logout_user( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; - /// Returns pet inventories by status. - /// - /// GetInventory - GET /v2/store/inventory - async fn get_inventory( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - - /// Find purchase order by ID. - /// - /// GetOrderById - GET /v2/store/order/{orderId} - async fn get_order_by_id( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::GetOrderByIdPathParams, - ) -> Result; - - - /// Place an order for a pet. - /// - /// PlaceOrder - POST /v2/store/order - async fn place_order( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::Order, - ) -> Result; - - - /// Create user. - /// - /// CreateUser - POST /v2/user - async fn create_user( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::User, - ) -> Result; - - - /// Creates list of users with given input array. - /// - /// CreateUsersWithArrayInput - POST /v2/user/createWithArray - async fn create_users_with_array_input( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Vec, - ) -> Result; - - - /// Creates list of users with given input array. - /// - /// CreateUsersWithListInput - POST /v2/user/createWithList - async fn create_users_with_list_input( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Vec, - ) -> Result; - - - /// Delete user. - /// - /// DeleteUser - DELETE /v2/user/{username} - async fn delete_user( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::DeleteUserPathParams, - ) -> Result; - - - /// Get user by user name. - /// - /// GetUserByName - GET /v2/user/{username} - async fn get_user_by_name( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::GetUserByNamePathParams, - ) -> Result; - - - /// Logs user into the system. - /// - /// LoginUser - GET /v2/user/login - async fn login_user( - &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::LoginUserQueryParams, - ) -> Result; - - - /// Logs out current logged in user session. - /// - /// LogoutUser - GET /v2/user/logout - async fn logout_user( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - - /// Updated user. - /// - /// UpdateUser - PUT /v2/user/{username} - async fn update_user( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::UpdateUserPathParams, - body: models::User, - ) -> Result; - + /// Updated user. + /// + /// UpdateUser - PUT /v2/user/{username} + async fn update_user( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::UpdateUserPathParams, + body: models::User, + ) -> Result; } #[cfg(feature = "server")] diff --git a/samples/server/petstore/rust-axum/output/petstore/src/models.rs b/samples/server/petstore/rust-axum/output/petstore/src/models.rs index 1199eeb54f0..2ad59347109 100644 --- a/samples/server/petstore/rust-axum/output/petstore/src/models.rs +++ b/samples/server/petstore/rust-axum/output/petstore/src/models.rs @@ -7,166 +7,127 @@ use validator::Validate; use crate::header; use crate::{models, types::*}; - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct DeletePetHeaderParams { - pub api_key: Option, - } +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct DeletePetHeaderParams { + pub api_key: Option, +} - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct DeletePetPathParams { - /// Pet id to delete - pub pet_id: i64, - } +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct DeletePetPathParams { + /// Pet id to delete + pub pet_id: i64, +} +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct FindPetsByStatusQueryParams { + /// Status values that need to be considered for filter + /// Note: inline enums are not fully supported by openapi-generator + #[serde(rename = "status")] + pub status: Vec, +} - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct FindPetsByStatusQueryParams { - /// Status values that need to be considered for filter - /// Note: inline enums are not fully supported by openapi-generator - #[serde(rename = "status")] - pub status: Vec, - } +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct FindPetsByTagsQueryParams { + /// Tags to filter by + #[serde(rename = "tags")] + pub tags: Vec, +} - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct FindPetsByTagsQueryParams { - /// Tags to filter by - #[serde(rename = "tags")] - pub tags: Vec, - } +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct GetPetByIdPathParams { + /// ID of pet to return + pub pet_id: i64, +} - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct GetPetByIdPathParams { - /// ID of pet to return - pub pet_id: i64, - } +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct UpdatePetWithFormPathParams { + /// ID of pet that needs to be updated + pub pet_id: i64, +} +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct UploadFilePathParams { + /// ID of pet to update + pub pet_id: i64, +} - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct UpdatePetWithFormPathParams { - /// ID of pet that needs to be updated - pub pet_id: i64, - } +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct DeleteOrderPathParams { + /// ID of the order that needs to be deleted + pub order_id: String, +} +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct GetOrderByIdPathParams { + /// ID of pet that needs to be fetched + #[validate(range(min = 1, max = 5))] + pub order_id: i64, +} - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct UploadFilePathParams { - /// ID of pet to update - pub pet_id: i64, - } +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct DeleteUserPathParams { + /// The name that needs to be deleted + pub username: String, +} +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct GetUserByNamePathParams { + /// The name that needs to be fetched. Use user1 for testing. + pub username: String, +} - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct DeleteOrderPathParams { - /// ID of the order that needs to be deleted - pub order_id: String, - } - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct GetOrderByIdPathParams { - /// ID of pet that needs to be fetched - #[validate( - range(min = 1, max = 5), - )] - pub order_id: i64, - } - - - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct DeleteUserPathParams { - /// The name that needs to be deleted - pub username: String, - } - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct GetUserByNamePathParams { - /// The name that needs to be fetched. Use user1 for testing. - pub username: String, - } - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct LoginUserQueryParams { - /// The user name for login - #[serde(rename = "username")] - #[validate( - regex = "RE_LOGINUSERQUERYPARAMS_USERNAME", - )] - pub username: String, - /// The password for login in clear text - #[serde(rename = "password")] - pub password: String, - } - - lazy_static::lazy_static! { - static ref RE_LOGINUSERQUERYPARAMS_USERNAME: regex::Regex = regex::Regex::new(r"^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$").unwrap(); - } - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] - #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] - pub struct UpdateUserPathParams { - /// name that need to be deleted - pub username: String, - } - +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct LoginUserQueryParams { + /// The user name for login + #[serde(rename = "username")] + #[validate(regex = "RE_LOGINUSERQUERYPARAMS_USERNAME")] + pub username: String, + /// The password for login in clear text + #[serde(rename = "password")] + pub password: String, +} +lazy_static::lazy_static! { + static ref RE_LOGINUSERQUERYPARAMS_USERNAME: regex::Regex = regex::Regex::new(r"^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$").unwrap(); +} +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct UpdateUserPathParams { + /// name that need to be deleted + pub username: String, +} /// Describes the result of uploading an image resource - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct ApiResponse { #[serde(rename = "code")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub code: Option, #[serde(rename = "type")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub r#type: Option, #[serde(rename = "message")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub message: Option, - } - impl ApiResponse { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> ApiResponse { @@ -184,30 +145,15 @@ impl ApiResponse { impl std::string::ToString for ApiResponse { fn to_string(&self) -> String { let params: Vec> = vec![ - - self.code.as_ref().map(|code| { - [ - "code".to_string(), - code.to_string(), - ].join(",") - }), - - - self.r#type.as_ref().map(|r#type| { - [ - "type".to_string(), - r#type.to_string(), - ].join(",") - }), - - - self.message.as_ref().map(|message| { - [ - "message".to_string(), - message.to_string(), - ].join(",") - }), - + self.code + .as_ref() + .map(|code| ["code".to_string(), code.to_string()].join(",")), + self.r#type + .as_ref() + .map(|r#type| ["type".to_string(), r#type.to_string()].join(",")), + self.message + .as_ref() + .map(|message| ["message".to_string(), message.to_string()].join(",")), ]; params.into_iter().flatten().collect::>().join(",") @@ -239,19 +185,33 @@ impl std::str::FromStr for ApiResponse { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing ApiResponse".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing ApiResponse".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "code" => intermediate_rep.code.push(::from_str(val).map_err(|x| x.to_string())?), + "code" => intermediate_rep.code.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "type" => intermediate_rep.r#type.push(::from_str(val).map_err(|x| x.to_string())?), + "type" => intermediate_rep.r#type.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "message" => intermediate_rep.message.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing ApiResponse".to_string()) + "message" => intermediate_rep.message.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing ApiResponse".to_string(), + ) + } } } @@ -274,13 +234,16 @@ impl std::str::FromStr for ApiResponse { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for ApiResponse - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for ApiResponse - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -291,42 +254,38 @@ impl std::convert::TryFrom for header::IntoHeaderValue fn try_from(hdr_value: HeaderValue) -> std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into ApiResponse - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into ApiResponse - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - /// A category for a pet - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct Category { #[serde(rename = "id")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub id: Option, #[serde(rename = "name")] - #[validate( - regex = "RE_CATEGORY_NAME", - )] - #[serde(skip_serializing_if="Option::is_none")] + #[validate(regex = "RE_CATEGORY_NAME")] + #[serde(skip_serializing_if = "Option::is_none")] pub name: Option, - } lazy_static::lazy_static! { @@ -349,22 +308,12 @@ impl Category { impl std::string::ToString for Category { fn to_string(&self) -> String { let params: Vec> = vec![ - - self.id.as_ref().map(|id| { - [ - "id".to_string(), - id.to_string(), - ].join(",") - }), - - - self.name.as_ref().map(|name| { - [ - "name".to_string(), - name.to_string(), - ].join(",") - }), - + self.id + .as_ref() + .map(|id| ["id".to_string(), id.to_string()].join(",")), + self.name + .as_ref() + .map(|name| ["name".to_string(), name.to_string()].join(",")), ]; params.into_iter().flatten().collect::>().join(",") @@ -395,17 +344,29 @@ impl std::str::FromStr for Category { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing Category".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing Category".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "id" => intermediate_rep.id.push(::from_str(val).map_err(|x| x.to_string())?), + "id" => intermediate_rep.id.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "name" => intermediate_rep.name.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing Category".to_string()) + "name" => intermediate_rep.name.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing Category".to_string(), + ) + } } } @@ -427,13 +388,16 @@ impl std::str::FromStr for Category { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for Category - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for Category - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -444,60 +408,57 @@ impl std::convert::TryFrom for header::IntoHeaderValue { fn try_from(hdr_value: HeaderValue) -> std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into Category - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into Category - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - /// An order for a pets from the pet store - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct Order { #[serde(rename = "id")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub id: Option, #[serde(rename = "petId")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub pet_id: Option, #[serde(rename = "quantity")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub quantity: Option, #[serde(rename = "shipDate")] - #[serde(skip_serializing_if="Option::is_none")] - pub ship_date: Option>, + #[serde(skip_serializing_if = "Option::is_none")] + pub ship_date: Option>, -/// Order Status -/// Note: inline enums are not fully supported by openapi-generator + /// Order Status + /// Note: inline enums are not fully supported by openapi-generator #[serde(rename = "status")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub status: Option, #[serde(rename = "complete")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub complete: Option, - } - impl Order { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> Order { @@ -518,48 +479,22 @@ impl Order { impl std::string::ToString for Order { fn to_string(&self) -> String { let params: Vec> = vec![ - - self.id.as_ref().map(|id| { - [ - "id".to_string(), - id.to_string(), - ].join(",") - }), - - - self.pet_id.as_ref().map(|pet_id| { - [ - "petId".to_string(), - pet_id.to_string(), - ].join(",") - }), - - - self.quantity.as_ref().map(|quantity| { - [ - "quantity".to_string(), - quantity.to_string(), - ].join(",") - }), - + self.id + .as_ref() + .map(|id| ["id".to_string(), id.to_string()].join(",")), + self.pet_id + .as_ref() + .map(|pet_id| ["petId".to_string(), pet_id.to_string()].join(",")), + self.quantity + .as_ref() + .map(|quantity| ["quantity".to_string(), quantity.to_string()].join(",")), // Skipping shipDate in query parameter serialization - - - self.status.as_ref().map(|status| { - [ - "status".to_string(), - status.to_string(), - ].join(",") - }), - - - self.complete.as_ref().map(|complete| { - [ - "complete".to_string(), - complete.to_string(), - ].join(",") - }), - + self.status + .as_ref() + .map(|status| ["status".to_string(), status.to_string()].join(",")), + self.complete + .as_ref() + .map(|complete| ["complete".to_string(), complete.to_string()].join(",")), ]; params.into_iter().flatten().collect::>().join(",") @@ -580,7 +515,7 @@ impl std::str::FromStr for Order { pub id: Vec, pub pet_id: Vec, pub quantity: Vec, - pub ship_date: Vec>, + pub ship_date: Vec>, pub status: Vec, pub complete: Vec, } @@ -594,25 +529,46 @@ impl std::str::FromStr for Order { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing Order".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing Order".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "id" => intermediate_rep.id.push(::from_str(val).map_err(|x| x.to_string())?), + "id" => intermediate_rep.id.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "petId" => intermediate_rep.pet_id.push(::from_str(val).map_err(|x| x.to_string())?), + "petId" => intermediate_rep.pet_id.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "quantity" => intermediate_rep.quantity.push(::from_str(val).map_err(|x| x.to_string())?), + "quantity" => intermediate_rep.quantity.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "shipDate" => intermediate_rep.ship_date.push( as std::str::FromStr>::from_str(val).map_err(|x| x.to_string())?), + "shipDate" => intermediate_rep.ship_date.push( + as std::str::FromStr>::from_str(val) + .map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "status" => intermediate_rep.status.push(::from_str(val).map_err(|x| x.to_string())?), + "status" => intermediate_rep.status.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "complete" => intermediate_rep.complete.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing Order".to_string()) + "complete" => intermediate_rep.complete.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing Order".to_string(), + ) + } } } @@ -638,13 +594,16 @@ impl std::str::FromStr for Order { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for Order - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for Order - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -655,37 +614,34 @@ impl std::convert::TryFrom for header::IntoHeaderValue { fn try_from(hdr_value: HeaderValue) -> std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into Order - {}", - value, err)) - } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Ok(value) => match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) + } + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into Order - {}", + value, err + )), + }, + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - /// A pet for sale in the pet store - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct Pet { #[serde(rename = "id")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub id: Option, #[serde(rename = "category")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub category: Option, #[serde(rename = "name")] @@ -695,21 +651,19 @@ pub struct Pet { pub photo_urls: Vec, #[serde(rename = "tags")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub tags: Option>, -/// pet status in the store -/// Note: inline enums are not fully supported by openapi-generator + /// pet status in the store + /// Note: inline enums are not fully supported by openapi-generator #[serde(rename = "status")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub status: Option, - } - impl Pet { #[allow(clippy::new_without_default, clippy::too_many_arguments)] - pub fn new(name: String, photo_urls: Vec, ) -> Pet { + pub fn new(name: String, photo_urls: Vec) -> Pet { Pet { id: None, category: None, @@ -727,34 +681,24 @@ impl Pet { impl std::string::ToString for Pet { fn to_string(&self) -> String { let params: Vec> = vec![ - - self.id.as_ref().map(|id| { - [ - "id".to_string(), - id.to_string(), - ].join(",") - }), - + self.id + .as_ref() + .map(|id| ["id".to_string(), id.to_string()].join(",")), // Skipping category in query parameter serialization - - Some("name".to_string()), Some(self.name.to_string()), - - Some("photoUrls".to_string()), - Some(self.photo_urls.iter().map(|x| x.to_string()).collect::>().join(",")), - + Some( + self.photo_urls + .iter() + .map(|x| x.to_string()) + .collect::>() + .join(","), + ), // Skipping tags in query parameter serialization - - - self.status.as_ref().map(|status| { - [ - "status".to_string(), - status.to_string(), - ].join(",") - }), - + self.status + .as_ref() + .map(|status| ["status".to_string(), status.to_string()].join(",")), ]; params.into_iter().flatten().collect::>().join(",") @@ -789,23 +733,46 @@ impl std::str::FromStr for Pet { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing Pet".to_string()) + None => { + return std::result::Result::Err("Missing value while parsing Pet".to_string()) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "id" => intermediate_rep.id.push(::from_str(val).map_err(|x| x.to_string())?), + "id" => intermediate_rep.id.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "category" => intermediate_rep.category.push(::from_str(val).map_err(|x| x.to_string())?), + "category" => intermediate_rep.category.push( + ::from_str(val) + .map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "name" => intermediate_rep.name.push(::from_str(val).map_err(|x| x.to_string())?), - "photoUrls" => return std::result::Result::Err("Parsing a container in this style is not supported in Pet".to_string()), - "tags" => return std::result::Result::Err("Parsing a container in this style is not supported in Pet".to_string()), + "name" => intermediate_rep.name.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + "photoUrls" => { + return std::result::Result::Err( + "Parsing a container in this style is not supported in Pet".to_string(), + ) + } + "tags" => { + return std::result::Result::Err( + "Parsing a container in this style is not supported in Pet".to_string(), + ) + } #[allow(clippy::redundant_clone)] - "status" => intermediate_rep.status.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing Pet".to_string()) + "status" => intermediate_rep.status.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing Pet".to_string(), + ) + } } } @@ -817,8 +784,16 @@ impl std::str::FromStr for Pet { std::result::Result::Ok(Pet { id: intermediate_rep.id.into_iter().next(), category: intermediate_rep.category.into_iter().next(), - name: intermediate_rep.name.into_iter().next().ok_or_else(|| "name missing in Pet".to_string())?, - photo_urls: intermediate_rep.photo_urls.into_iter().next().ok_or_else(|| "photoUrls missing in Pet".to_string())?, + name: intermediate_rep + .name + .into_iter() + .next() + .ok_or_else(|| "name missing in Pet".to_string())?, + photo_urls: intermediate_rep + .photo_urls + .into_iter() + .next() + .ok_or_else(|| "photoUrls missing in Pet".to_string())?, tags: intermediate_rep.tags.into_iter().next(), status: intermediate_rep.status.into_iter().next(), }) @@ -834,10 +809,11 @@ impl std::convert::TryFrom> for HeaderValue { fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for Pet - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for Pet - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -848,42 +824,37 @@ impl std::convert::TryFrom for header::IntoHeaderValue { fn try_from(hdr_value: HeaderValue) -> std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into Pet - {}", - value, err)) - } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Ok(value) => match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) + } + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into Pet - {}", + value, err + )), + }, + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - /// A tag for a pet - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct Tag { #[serde(rename = "id")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub id: Option, #[serde(rename = "name")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub name: Option, - } - impl Tag { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> Tag { @@ -900,22 +871,12 @@ impl Tag { impl std::string::ToString for Tag { fn to_string(&self) -> String { let params: Vec> = vec![ - - self.id.as_ref().map(|id| { - [ - "id".to_string(), - id.to_string(), - ].join(",") - }), - - - self.name.as_ref().map(|name| { - [ - "name".to_string(), - name.to_string(), - ].join(",") - }), - + self.id + .as_ref() + .map(|id| ["id".to_string(), id.to_string()].join(",")), + self.name + .as_ref() + .map(|name| ["name".to_string(), name.to_string()].join(",")), ]; params.into_iter().flatten().collect::>().join(",") @@ -946,17 +907,27 @@ impl std::str::FromStr for Tag { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing Tag".to_string()) + None => { + return std::result::Result::Err("Missing value while parsing Tag".to_string()) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "id" => intermediate_rep.id.push(::from_str(val).map_err(|x| x.to_string())?), + "id" => intermediate_rep.id.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "name" => intermediate_rep.name.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing Tag".to_string()) + "name" => intermediate_rep.name.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing Tag".to_string(), + ) + } } } @@ -981,10 +952,11 @@ impl std::convert::TryFrom> for HeaderValue { fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for Tag - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for Tag - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -995,67 +967,62 @@ impl std::convert::TryFrom for header::IntoHeaderValue { fn try_from(hdr_value: HeaderValue) -> std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into Tag - {}", - value, err)) - } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Ok(value) => match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) + } + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into Tag - {}", + value, err + )), + }, + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - /// A User who is purchasing from the pet store - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct User { #[serde(rename = "id")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub id: Option, #[serde(rename = "username")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub username: Option, #[serde(rename = "firstName")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub first_name: Option, #[serde(rename = "lastName")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub last_name: Option, #[serde(rename = "email")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub email: Option, #[serde(rename = "password")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub password: Option, #[serde(rename = "phone")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub phone: Option, -/// User Status + /// User Status #[serde(rename = "userStatus")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub user_status: Option, - } - impl User { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> User { @@ -1078,70 +1045,30 @@ impl User { impl std::string::ToString for User { fn to_string(&self) -> String { let params: Vec> = vec![ - - self.id.as_ref().map(|id| { - [ - "id".to_string(), - id.to_string(), - ].join(",") - }), - - - self.username.as_ref().map(|username| { - [ - "username".to_string(), - username.to_string(), - ].join(",") - }), - - - self.first_name.as_ref().map(|first_name| { - [ - "firstName".to_string(), - first_name.to_string(), - ].join(",") - }), - - - self.last_name.as_ref().map(|last_name| { - [ - "lastName".to_string(), - last_name.to_string(), - ].join(",") - }), - - - self.email.as_ref().map(|email| { - [ - "email".to_string(), - email.to_string(), - ].join(",") - }), - - - self.password.as_ref().map(|password| { - [ - "password".to_string(), - password.to_string(), - ].join(",") - }), - - - self.phone.as_ref().map(|phone| { - [ - "phone".to_string(), - phone.to_string(), - ].join(",") - }), - - - self.user_status.as_ref().map(|user_status| { - [ - "userStatus".to_string(), - user_status.to_string(), - ].join(",") - }), - + self.id + .as_ref() + .map(|id| ["id".to_string(), id.to_string()].join(",")), + self.username + .as_ref() + .map(|username| ["username".to_string(), username.to_string()].join(",")), + self.first_name + .as_ref() + .map(|first_name| ["firstName".to_string(), first_name.to_string()].join(",")), + self.last_name + .as_ref() + .map(|last_name| ["lastName".to_string(), last_name.to_string()].join(",")), + self.email + .as_ref() + .map(|email| ["email".to_string(), email.to_string()].join(",")), + self.password + .as_ref() + .map(|password| ["password".to_string(), password.to_string()].join(",")), + self.phone + .as_ref() + .map(|phone| ["phone".to_string(), phone.to_string()].join(",")), + self.user_status + .as_ref() + .map(|user_status| ["userStatus".to_string(), user_status.to_string()].join(",")), ]; params.into_iter().flatten().collect::>().join(",") @@ -1178,29 +1105,51 @@ impl std::str::FromStr for User { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing User".to_string()) + None => { + return std::result::Result::Err("Missing value while parsing User".to_string()) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "id" => intermediate_rep.id.push(::from_str(val).map_err(|x| x.to_string())?), + "id" => intermediate_rep.id.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "username" => intermediate_rep.username.push(::from_str(val).map_err(|x| x.to_string())?), + "username" => intermediate_rep.username.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "firstName" => intermediate_rep.first_name.push(::from_str(val).map_err(|x| x.to_string())?), + "firstName" => intermediate_rep.first_name.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "lastName" => intermediate_rep.last_name.push(::from_str(val).map_err(|x| x.to_string())?), + "lastName" => intermediate_rep.last_name.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "email" => intermediate_rep.email.push(::from_str(val).map_err(|x| x.to_string())?), + "email" => intermediate_rep.email.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "password" => intermediate_rep.password.push(::from_str(val).map_err(|x| x.to_string())?), + "password" => intermediate_rep.password.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "phone" => intermediate_rep.phone.push(::from_str(val).map_err(|x| x.to_string())?), + "phone" => intermediate_rep.phone.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "userStatus" => intermediate_rep.user_status.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing User".to_string()) + "userStatus" => intermediate_rep.user_status.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing User".to_string(), + ) + } } } @@ -1228,13 +1177,16 @@ impl std::str::FromStr for User { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for User - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for User - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -1245,20 +1197,19 @@ impl std::convert::TryFrom for header::IntoHeaderValue { fn try_from(hdr_value: HeaderValue) -> std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into User - {}", - value, err)) - } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Ok(value) => match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) + } + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into User - {}", + value, err + )), + }, + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - diff --git a/samples/server/petstore/rust-axum/output/petstore/src/server/mod.rs b/samples/server/petstore/rust-axum/output/petstore/src/server/mod.rs index 89007f8055b..87e0b820afb 100644 --- a/samples/server/petstore/rust-axum/output/petstore/src/server/mod.rs +++ b/samples/server/petstore/rust-axum/output/petstore/src/server/mod.rs @@ -12,27 +12,13 @@ use crate::{header, types::*}; #[allow(unused_imports)] use crate::models; -use crate::{Api, - AddPetResponse, - DeletePetResponse, - FindPetsByStatusResponse, - FindPetsByTagsResponse, - GetPetByIdResponse, - UpdatePetResponse, - UpdatePetWithFormResponse, - UploadFileResponse, - DeleteOrderResponse, - GetInventoryResponse, - GetOrderByIdResponse, - PlaceOrderResponse, - CreateUserResponse, - CreateUsersWithArrayInputResponse, - CreateUsersWithListInputResponse, - DeleteUserResponse, - GetUserByNameResponse, - LoginUserResponse, - LogoutUserResponse, - UpdateUserResponse +use crate::{ + AddPetResponse, Api, CreateUserResponse, CreateUsersWithArrayInputResponse, + CreateUsersWithListInputResponse, DeleteOrderResponse, DeletePetResponse, DeleteUserResponse, + FindPetsByStatusResponse, FindPetsByTagsResponse, GetInventoryResponse, GetOrderByIdResponse, + GetPetByIdResponse, GetUserByNameResponse, LoginUserResponse, LogoutUserResponse, + PlaceOrderResponse, UpdatePetResponse, UpdatePetWithFormResponse, UpdateUserResponse, + UploadFileResponse, }; /// Setup API Server. @@ -43,1862 +29,1602 @@ where { // build our application with a route Router::new() - .route("/v2/pet", - post(add_pet::).put(update_pet::) + .route("/v2/pet", post(add_pet::).put(update_pet::)) + .route( + "/v2/pet/:pet_id", + delete(delete_pet::) + .get(get_pet_by_id::) + .post(update_pet_with_form::), ) - .route("/v2/pet/:pet_id", - delete(delete_pet::).get(get_pet_by_id::).post(update_pet_with_form::) + .route("/v2/pet/:pet_id/uploadImage", post(upload_file::)) + .route("/v2/pet/findByStatus", get(find_pets_by_status::)) + .route("/v2/pet/findByTags", get(find_pets_by_tags::)) + .route("/v2/store/inventory", get(get_inventory::)) + .route("/v2/store/order", post(place_order::)) + .route( + "/v2/store/order/:order_id", + delete(delete_order::).get(get_order_by_id::), ) - .route("/v2/pet/:pet_id/uploadImage", - post(upload_file::) + .route("/v2/user", post(create_user::)) + .route( + "/v2/user/:username", + delete(delete_user::) + .get(get_user_by_name::) + .put(update_user::), ) - .route("/v2/pet/findByStatus", - get(find_pets_by_status::) + .route( + "/v2/user/createWithArray", + post(create_users_with_array_input::), ) - .route("/v2/pet/findByTags", - get(find_pets_by_tags::) - ) - .route("/v2/store/inventory", - get(get_inventory::) - ) - .route("/v2/store/order", - post(place_order::) - ) - .route("/v2/store/order/:order_id", - delete(delete_order::).get(get_order_by_id::) - ) - .route("/v2/user", - post(create_user::) - ) - .route("/v2/user/:username", - delete(delete_user::).get(get_user_by_name::).put(update_user::) - ) - .route("/v2/user/createWithArray", - post(create_users_with_array_input::) - ) - .route("/v2/user/createWithList", - post(create_users_with_list_input::) - ) - .route("/v2/user/login", - get(login_user::) - ) - .route("/v2/user/logout", - get(logout_user::) + .route( + "/v2/user/createWithList", + post(create_users_with_list_input::), ) + .route("/v2/user/login", get(login_user::)) + .route("/v2/user/logout", get(logout_user::)) .with_state(api_impl) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct AddPetBodyValidator<'a> { - #[validate] - body: &'a models::Pet, - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct AddPetBodyValidator<'a> { + #[validate] + body: &'a models::Pet, +} #[tracing::instrument(skip_all)] -fn add_pet_validation( - body: models::Pet, -) -> std::result::Result<( - models::Pet, -), ValidationErrors> -{ - let b = AddPetBodyValidator { body: &body }; - b.validate()?; +fn add_pet_validation(body: models::Pet) -> std::result::Result<(models::Pet,), ValidationErrors> { + let b = AddPetBodyValidator { body: &body }; + b.validate()?; -Ok(( - body, -)) + Ok((body,)) } /// AddPet - POST /v2/pet #[tracing::instrument(skip_all)] async fn add_pet( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - Json(body): Json, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + Json(body): Json, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || add_pet_validation(body)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - add_pet_validation( - body, - ) - ).await.unwrap(); - - let Ok(( - body, - )) = validation else { - return Response::builder() + let Ok((body,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().add_pet( - method, - host, - cookies, - body, - ).await; + let result = api_impl.as_ref().add_pet(method, host, cookies, body).await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - AddPetResponse::Status200_SuccessfulOperation - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + AddPetResponse::Status200_SuccessfulOperation(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("text/plain").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("text/plain").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = body; + response.body(Body::from(body_content)) + } + AddPetResponse::Status405_InvalidInput => { + let mut response = response.status(405); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = body; - response.body(Body::from(body_content)) - }, - AddPetResponse::Status405_InvalidInput - => { - - let mut response = response.status(405); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] fn delete_pet_validation( - header_params: models::DeletePetHeaderParams, - path_params: models::DeletePetPathParams, -) -> std::result::Result<( - models::DeletePetHeaderParams, - models::DeletePetPathParams, -), ValidationErrors> -{ - header_params.validate()?; - path_params.validate()?; + header_params: models::DeletePetHeaderParams, + path_params: models::DeletePetPathParams, +) -> std::result::Result< + (models::DeletePetHeaderParams, models::DeletePetPathParams), + ValidationErrors, +> { + header_params.validate()?; + path_params.validate()?; -Ok(( - header_params, - path_params, -)) + Ok((header_params, path_params)) } /// DeletePet - DELETE /v2/pet/{petId} #[tracing::instrument(skip_all)] async fn delete_pet( - method: Method, - host: Host, - cookies: CookieJar, - headers: HeaderMap, - Path(path_params): Path, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + headers: HeaderMap, + Path(path_params): Path, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { // Header parameters let header_params = { - let header_api_key = headers.get(HeaderName::from_static("api_key")); + let header_api_key = headers.get(HeaderName::from_static("api_key")); - let header_api_key = match header_api_key { - Some(v) => match header::IntoHeaderValue::::try_from((*v).clone()) { - Ok(result) => - Some(result.0), - Err(err) => { - return Response::builder() - .status(StatusCode::BAD_REQUEST) - .body(Body::from(format!("Invalid header api_key - {}", err))).map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }); + let header_api_key = match header_api_key { + Some(v) => match header::IntoHeaderValue::::try_from((*v).clone()) { + Ok(result) => Some(result.0), + Err(err) => { + return Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Invalid header api_key - {}", err))) + .map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }); + } + }, + None => None, + }; - }, - }, - None => { - None - } - }; + models::DeletePetHeaderParams { + api_key: header_api_key, + } + }; - models::DeletePetHeaderParams { - api_key: header_api_key, - } - }; + #[allow(clippy::redundant_closure)] + let validation = + tokio::task::spawn_blocking(move || delete_pet_validation(header_params, path_params)) + .await + .unwrap(); - - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - delete_pet_validation( - header_params, - path_params, - ) - ).await.unwrap(); - - let Ok(( - header_params, - path_params, - )) = validation else { - return Response::builder() + let Ok((header_params, path_params)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().delete_pet( - method, - host, - cookies, - header_params, - path_params, - ).await; + let result = api_impl + .as_ref() + .delete_pet(method, host, cookies, header_params, path_params) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - DeletePetResponse::Status400_InvalidPetValue - => { + let resp = match result { + Ok(rsp) => match rsp { + DeletePetResponse::Status400_InvalidPetValue => { + let mut response = response.status(400); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(400); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] fn find_pets_by_status_validation( - query_params: models::FindPetsByStatusQueryParams, -) -> std::result::Result<( - models::FindPetsByStatusQueryParams, -), ValidationErrors> -{ - query_params.validate()?; + query_params: models::FindPetsByStatusQueryParams, +) -> std::result::Result<(models::FindPetsByStatusQueryParams,), ValidationErrors> { + query_params.validate()?; -Ok(( - query_params, -)) + Ok((query_params,)) } /// FindPetsByStatus - GET /v2/pet/findByStatus #[tracing::instrument(skip_all)] async fn find_pets_by_status( - method: Method, - host: Host, - cookies: CookieJar, - Query(query_params): Query, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + Query(query_params): Query, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = + tokio::task::spawn_blocking(move || find_pets_by_status_validation(query_params)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - find_pets_by_status_validation( - query_params, - ) - ).await.unwrap(); - - let Ok(( - query_params, - )) = validation else { - return Response::builder() + let Ok((query_params,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().find_pets_by_status( - method, - host, - cookies, - query_params, - ).await; + let result = api_impl + .as_ref() + .find_pets_by_status(method, host, cookies, query_params) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - FindPetsByStatusResponse::Status200_SuccessfulOperation - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + FindPetsByStatusResponse::Status200_SuccessfulOperation(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("text/plain").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("text/plain").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = body; + response.body(Body::from(body_content)) + } + FindPetsByStatusResponse::Status400_InvalidStatusValue => { + let mut response = response.status(400); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = body; - response.body(Body::from(body_content)) - }, - FindPetsByStatusResponse::Status400_InvalidStatusValue - => { - - let mut response = response.status(400); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] fn find_pets_by_tags_validation( - query_params: models::FindPetsByTagsQueryParams, -) -> std::result::Result<( - models::FindPetsByTagsQueryParams, -), ValidationErrors> -{ - query_params.validate()?; + query_params: models::FindPetsByTagsQueryParams, +) -> std::result::Result<(models::FindPetsByTagsQueryParams,), ValidationErrors> { + query_params.validate()?; -Ok(( - query_params, -)) + Ok((query_params,)) } /// FindPetsByTags - GET /v2/pet/findByTags #[tracing::instrument(skip_all)] async fn find_pets_by_tags( - method: Method, - host: Host, - cookies: CookieJar, - Query(query_params): Query, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + Query(query_params): Query, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = + tokio::task::spawn_blocking(move || find_pets_by_tags_validation(query_params)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - find_pets_by_tags_validation( - query_params, - ) - ).await.unwrap(); - - let Ok(( - query_params, - )) = validation else { - return Response::builder() + let Ok((query_params,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().find_pets_by_tags( - method, - host, - cookies, - query_params, - ).await; + let result = api_impl + .as_ref() + .find_pets_by_tags(method, host, cookies, query_params) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - FindPetsByTagsResponse::Status200_SuccessfulOperation - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + FindPetsByTagsResponse::Status200_SuccessfulOperation(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("text/plain").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("text/plain").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = body; + response.body(Body::from(body_content)) + } + FindPetsByTagsResponse::Status400_InvalidTagValue => { + let mut response = response.status(400); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = body; - response.body(Body::from(body_content)) - }, - FindPetsByTagsResponse::Status400_InvalidTagValue - => { - - let mut response = response.status(400); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] fn get_pet_by_id_validation( - path_params: models::GetPetByIdPathParams, -) -> std::result::Result<( - models::GetPetByIdPathParams, -), ValidationErrors> -{ - path_params.validate()?; + path_params: models::GetPetByIdPathParams, +) -> std::result::Result<(models::GetPetByIdPathParams,), ValidationErrors> { + path_params.validate()?; -Ok(( - path_params, -)) + Ok((path_params,)) } /// GetPetById - GET /v2/pet/{petId} #[tracing::instrument(skip_all)] async fn get_pet_by_id( - method: Method, - host: Host, - cookies: CookieJar, - Path(path_params): Path, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + Path(path_params): Path, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || get_pet_by_id_validation(path_params)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - get_pet_by_id_validation( - path_params, - ) - ).await.unwrap(); - - let Ok(( - path_params, - )) = validation else { - return Response::builder() + let Ok((path_params,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().get_pet_by_id( - method, - host, - cookies, - path_params, - ).await; + let result = api_impl + .as_ref() + .get_pet_by_id(method, host, cookies, path_params) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - GetPetByIdResponse::Status200_SuccessfulOperation - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + GetPetByIdResponse::Status200_SuccessfulOperation(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("text/plain").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("text/plain").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = body; + response.body(Body::from(body_content)) + } + GetPetByIdResponse::Status400_InvalidIDSupplied => { + let mut response = response.status(400); + response.body(Body::empty()) + } + GetPetByIdResponse::Status404_PetNotFound => { + let mut response = response.status(404); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = body; - response.body(Body::from(body_content)) - }, - GetPetByIdResponse::Status400_InvalidIDSupplied - => { - - let mut response = response.status(400); - response.body(Body::empty()) - }, - GetPetByIdResponse::Status404_PetNotFound - => { - - let mut response = response.status(404); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct UpdatePetBodyValidator<'a> { - #[validate] - body: &'a models::Pet, - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct UpdatePetBodyValidator<'a> { + #[validate] + body: &'a models::Pet, +} #[tracing::instrument(skip_all)] fn update_pet_validation( - body: models::Pet, -) -> std::result::Result<( - models::Pet, -), ValidationErrors> -{ - let b = UpdatePetBodyValidator { body: &body }; - b.validate()?; + body: models::Pet, +) -> std::result::Result<(models::Pet,), ValidationErrors> { + let b = UpdatePetBodyValidator { body: &body }; + b.validate()?; -Ok(( - body, -)) + Ok((body,)) } /// UpdatePet - PUT /v2/pet #[tracing::instrument(skip_all)] async fn update_pet( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - Json(body): Json, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + Json(body): Json, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || update_pet_validation(body)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - update_pet_validation( - body, - ) - ).await.unwrap(); - - let Ok(( - body, - )) = validation else { - return Response::builder() + let Ok((body,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().update_pet( - method, - host, - cookies, - body, - ).await; + let result = api_impl + .as_ref() + .update_pet(method, host, cookies, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - UpdatePetResponse::Status200_SuccessfulOperation - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + UpdatePetResponse::Status200_SuccessfulOperation(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("text/plain").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("text/plain").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = body; + response.body(Body::from(body_content)) + } + UpdatePetResponse::Status400_InvalidIDSupplied => { + let mut response = response.status(400); + response.body(Body::empty()) + } + UpdatePetResponse::Status404_PetNotFound => { + let mut response = response.status(404); + response.body(Body::empty()) + } + UpdatePetResponse::Status405_ValidationException => { + let mut response = response.status(405); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = body; - response.body(Body::from(body_content)) - }, - UpdatePetResponse::Status400_InvalidIDSupplied - => { - - let mut response = response.status(400); - response.body(Body::empty()) - }, - UpdatePetResponse::Status404_PetNotFound - => { - - let mut response = response.status(404); - response.body(Body::empty()) - }, - UpdatePetResponse::Status405_ValidationException - => { - - let mut response = response.status(405); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] fn update_pet_with_form_validation( - path_params: models::UpdatePetWithFormPathParams, -) -> std::result::Result<( - models::UpdatePetWithFormPathParams, -), ValidationErrors> -{ - path_params.validate()?; + path_params: models::UpdatePetWithFormPathParams, +) -> std::result::Result<(models::UpdatePetWithFormPathParams,), ValidationErrors> { + path_params.validate()?; -Ok(( - path_params, -)) + Ok((path_params,)) } /// UpdatePetWithForm - POST /v2/pet/{petId} #[tracing::instrument(skip_all)] async fn update_pet_with_form( - method: Method, - host: Host, - cookies: CookieJar, - Path(path_params): Path, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + Path(path_params): Path, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = + tokio::task::spawn_blocking(move || update_pet_with_form_validation(path_params)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - update_pet_with_form_validation( - path_params, - ) - ).await.unwrap(); - - let Ok(( - path_params, - )) = validation else { - return Response::builder() + let Ok((path_params,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().update_pet_with_form( - method, - host, - cookies, - path_params, - ).await; + let result = api_impl + .as_ref() + .update_pet_with_form(method, host, cookies, path_params) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - UpdatePetWithFormResponse::Status405_InvalidInput - => { + let resp = match result { + Ok(rsp) => match rsp { + UpdatePetWithFormResponse::Status405_InvalidInput => { + let mut response = response.status(405); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(405); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] fn upload_file_validation( - path_params: models::UploadFilePathParams, -) -> std::result::Result<( - models::UploadFilePathParams, -), ValidationErrors> -{ - path_params.validate()?; + path_params: models::UploadFilePathParams, +) -> std::result::Result<(models::UploadFilePathParams,), ValidationErrors> { + path_params.validate()?; -Ok(( - path_params, -)) + Ok((path_params,)) } /// UploadFile - POST /v2/pet/{petId}/uploadImage #[tracing::instrument(skip_all)] async fn upload_file( - method: Method, - host: Host, - cookies: CookieJar, - Path(path_params): Path, - State(api_impl): State, - body: Multipart, + method: Method, + host: Host, + cookies: CookieJar, + Path(path_params): Path, + State(api_impl): State, + body: Multipart, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || upload_file_validation(path_params)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - upload_file_validation( - path_params, - ) - ).await.unwrap(); - - let Ok(( - path_params, - )) = validation else { - return Response::builder() + let Ok((path_params,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().upload_file( - method, - host, - cookies, - path_params, - body, - ).await; + let result = api_impl + .as_ref() + .upload_file(method, host, cookies, path_params, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - UploadFileResponse::Status200_SuccessfulOperation - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + UploadFileResponse::Status200_SuccessfulOperation(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("application/json").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("application/json").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = tokio::task::spawn_blocking(move || { + serde_json::to_vec(&body).map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) + }) + .await + .unwrap()?; + response.body(Body::from(body_content)) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = tokio::task::spawn_blocking(move || - serde_json::to_vec(&body).map_err(|e| { - error!(error = ?e); - StatusCode::INTERNAL_SERVER_ERROR - })).await.unwrap()?; - response.body(Body::from(body_content)) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] fn delete_order_validation( - path_params: models::DeleteOrderPathParams, -) -> std::result::Result<( - models::DeleteOrderPathParams, -), ValidationErrors> -{ - path_params.validate()?; + path_params: models::DeleteOrderPathParams, +) -> std::result::Result<(models::DeleteOrderPathParams,), ValidationErrors> { + path_params.validate()?; -Ok(( - path_params, -)) + Ok((path_params,)) } /// DeleteOrder - DELETE /v2/store/order/{orderId} #[tracing::instrument(skip_all)] async fn delete_order( - method: Method, - host: Host, - cookies: CookieJar, - Path(path_params): Path, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + Path(path_params): Path, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || delete_order_validation(path_params)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - delete_order_validation( - path_params, - ) - ).await.unwrap(); - - let Ok(( - path_params, - )) = validation else { - return Response::builder() + let Ok((path_params,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().delete_order( - method, - host, - cookies, - path_params, - ).await; + let result = api_impl + .as_ref() + .delete_order(method, host, cookies, path_params) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - DeleteOrderResponse::Status400_InvalidIDSupplied - => { + let resp = match result { + Ok(rsp) => match rsp { + DeleteOrderResponse::Status400_InvalidIDSupplied => { + let mut response = response.status(400); + response.body(Body::empty()) + } + DeleteOrderResponse::Status404_OrderNotFound => { + let mut response = response.status(404); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(400); - response.body(Body::empty()) - }, - DeleteOrderResponse::Status404_OrderNotFound - => { - - let mut response = response.status(404); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] -fn get_inventory_validation( -) -> std::result::Result<( -), ValidationErrors> -{ - -Ok(( -)) +fn get_inventory_validation() -> std::result::Result<(), ValidationErrors> { + Ok(()) } /// GetInventory - GET /v2/store/inventory #[tracing::instrument(skip_all)] async fn get_inventory( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || get_inventory_validation()) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - get_inventory_validation( - ) - ).await.unwrap(); - - let Ok(( - )) = validation else { - return Response::builder() + let Ok(()) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().get_inventory( - method, - host, - cookies, - ).await; + let result = api_impl.as_ref().get_inventory(method, host, cookies).await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - GetInventoryResponse::Status200_SuccessfulOperation - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + GetInventoryResponse::Status200_SuccessfulOperation(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("application/json").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("application/json").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = tokio::task::spawn_blocking(move || { + serde_json::to_vec(&body).map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) + }) + .await + .unwrap()?; + response.body(Body::from(body_content)) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = tokio::task::spawn_blocking(move || - serde_json::to_vec(&body).map_err(|e| { - error!(error = ?e); - StatusCode::INTERNAL_SERVER_ERROR - })).await.unwrap()?; - response.body(Body::from(body_content)) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] fn get_order_by_id_validation( - path_params: models::GetOrderByIdPathParams, -) -> std::result::Result<( - models::GetOrderByIdPathParams, -), ValidationErrors> -{ - path_params.validate()?; + path_params: models::GetOrderByIdPathParams, +) -> std::result::Result<(models::GetOrderByIdPathParams,), ValidationErrors> { + path_params.validate()?; -Ok(( - path_params, -)) + Ok((path_params,)) } /// GetOrderById - GET /v2/store/order/{orderId} #[tracing::instrument(skip_all)] async fn get_order_by_id( - method: Method, - host: Host, - cookies: CookieJar, - Path(path_params): Path, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + Path(path_params): Path, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || get_order_by_id_validation(path_params)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - get_order_by_id_validation( - path_params, - ) - ).await.unwrap(); - - let Ok(( - path_params, - )) = validation else { - return Response::builder() + let Ok((path_params,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().get_order_by_id( - method, - host, - cookies, - path_params, - ).await; + let result = api_impl + .as_ref() + .get_order_by_id(method, host, cookies, path_params) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - GetOrderByIdResponse::Status200_SuccessfulOperation - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + GetOrderByIdResponse::Status200_SuccessfulOperation(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("text/plain").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("text/plain").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = body; + response.body(Body::from(body_content)) + } + GetOrderByIdResponse::Status400_InvalidIDSupplied => { + let mut response = response.status(400); + response.body(Body::empty()) + } + GetOrderByIdResponse::Status404_OrderNotFound => { + let mut response = response.status(404); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = body; - response.body(Body::from(body_content)) - }, - GetOrderByIdResponse::Status400_InvalidIDSupplied - => { - - let mut response = response.status(400); - response.body(Body::empty()) - }, - GetOrderByIdResponse::Status404_OrderNotFound - => { - - let mut response = response.status(404); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct PlaceOrderBodyValidator<'a> { - #[validate] - body: &'a models::Order, - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct PlaceOrderBodyValidator<'a> { + #[validate] + body: &'a models::Order, +} #[tracing::instrument(skip_all)] fn place_order_validation( - body: models::Order, -) -> std::result::Result<( - models::Order, -), ValidationErrors> -{ - let b = PlaceOrderBodyValidator { body: &body }; - b.validate()?; + body: models::Order, +) -> std::result::Result<(models::Order,), ValidationErrors> { + let b = PlaceOrderBodyValidator { body: &body }; + b.validate()?; -Ok(( - body, -)) + Ok((body,)) } /// PlaceOrder - POST /v2/store/order #[tracing::instrument(skip_all)] async fn place_order( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - Json(body): Json, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + Json(body): Json, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || place_order_validation(body)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - place_order_validation( - body, - ) - ).await.unwrap(); - - let Ok(( - body, - )) = validation else { - return Response::builder() + let Ok((body,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().place_order( - method, - host, - cookies, - body, - ).await; + let result = api_impl + .as_ref() + .place_order(method, host, cookies, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - PlaceOrderResponse::Status200_SuccessfulOperation - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + PlaceOrderResponse::Status200_SuccessfulOperation(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("text/plain").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("text/plain").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = body; + response.body(Body::from(body_content)) + } + PlaceOrderResponse::Status400_InvalidOrder => { + let mut response = response.status(400); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = body; - response.body(Body::from(body_content)) - }, - PlaceOrderResponse::Status400_InvalidOrder - => { - - let mut response = response.status(400); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct CreateUserBodyValidator<'a> { - #[validate] - body: &'a models::User, - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct CreateUserBodyValidator<'a> { + #[validate] + body: &'a models::User, +} #[tracing::instrument(skip_all)] fn create_user_validation( - body: models::User, -) -> std::result::Result<( - models::User, -), ValidationErrors> -{ - let b = CreateUserBodyValidator { body: &body }; - b.validate()?; + body: models::User, +) -> std::result::Result<(models::User,), ValidationErrors> { + let b = CreateUserBodyValidator { body: &body }; + b.validate()?; -Ok(( - body, -)) + Ok((body,)) } /// CreateUser - POST /v2/user #[tracing::instrument(skip_all)] async fn create_user( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - Json(body): Json, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + Json(body): Json, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || create_user_validation(body)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - create_user_validation( - body, - ) - ).await.unwrap(); - - let Ok(( - body, - )) = validation else { - return Response::builder() + let Ok((body,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().create_user( - method, - host, - cookies, - body, - ).await; + let result = api_impl + .as_ref() + .create_user(method, host, cookies, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - CreateUserResponse::Status0_SuccessfulOperation - => { + let resp = match result { + Ok(rsp) => match rsp { + CreateUserResponse::Status0_SuccessfulOperation => { + let mut response = response.status(0); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(0); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct CreateUsersWithArrayInputBodyValidator<'a> { - #[validate] - body: &'a Vec, - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct CreateUsersWithArrayInputBodyValidator<'a> { + #[validate] + body: &'a Vec, +} #[tracing::instrument(skip_all)] fn create_users_with_array_input_validation( - body: Vec, -) -> std::result::Result<( - Vec, -), ValidationErrors> -{ - let b = CreateUsersWithArrayInputBodyValidator { body: &body }; - b.validate()?; + body: Vec, +) -> std::result::Result<(Vec,), ValidationErrors> { + let b = CreateUsersWithArrayInputBodyValidator { body: &body }; + b.validate()?; -Ok(( - body, -)) + Ok((body,)) } /// CreateUsersWithArrayInput - POST /v2/user/createWithArray #[tracing::instrument(skip_all)] async fn create_users_with_array_input( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - Json(body): Json>, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + Json(body): Json>, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = + tokio::task::spawn_blocking(move || create_users_with_array_input_validation(body)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - create_users_with_array_input_validation( - body, - ) - ).await.unwrap(); - - let Ok(( - body, - )) = validation else { - return Response::builder() + let Ok((body,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().create_users_with_array_input( - method, - host, - cookies, - body, - ).await; + let result = api_impl + .as_ref() + .create_users_with_array_input(method, host, cookies, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - CreateUsersWithArrayInputResponse::Status0_SuccessfulOperation - => { + let resp = match result { + Ok(rsp) => match rsp { + CreateUsersWithArrayInputResponse::Status0_SuccessfulOperation => { + let mut response = response.status(0); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(0); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct CreateUsersWithListInputBodyValidator<'a> { - #[validate] - body: &'a Vec, - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct CreateUsersWithListInputBodyValidator<'a> { + #[validate] + body: &'a Vec, +} #[tracing::instrument(skip_all)] fn create_users_with_list_input_validation( - body: Vec, -) -> std::result::Result<( - Vec, -), ValidationErrors> -{ - let b = CreateUsersWithListInputBodyValidator { body: &body }; - b.validate()?; + body: Vec, +) -> std::result::Result<(Vec,), ValidationErrors> { + let b = CreateUsersWithListInputBodyValidator { body: &body }; + b.validate()?; -Ok(( - body, -)) + Ok((body,)) } /// CreateUsersWithListInput - POST /v2/user/createWithList #[tracing::instrument(skip_all)] async fn create_users_with_list_input( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - Json(body): Json>, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + Json(body): Json>, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = + tokio::task::spawn_blocking(move || create_users_with_list_input_validation(body)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - create_users_with_list_input_validation( - body, - ) - ).await.unwrap(); - - let Ok(( - body, - )) = validation else { - return Response::builder() + let Ok((body,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().create_users_with_list_input( - method, - host, - cookies, - body, - ).await; + let result = api_impl + .as_ref() + .create_users_with_list_input(method, host, cookies, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - CreateUsersWithListInputResponse::Status0_SuccessfulOperation - => { + let resp = match result { + Ok(rsp) => match rsp { + CreateUsersWithListInputResponse::Status0_SuccessfulOperation => { + let mut response = response.status(0); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(0); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] fn delete_user_validation( - path_params: models::DeleteUserPathParams, -) -> std::result::Result<( - models::DeleteUserPathParams, -), ValidationErrors> -{ - path_params.validate()?; + path_params: models::DeleteUserPathParams, +) -> std::result::Result<(models::DeleteUserPathParams,), ValidationErrors> { + path_params.validate()?; -Ok(( - path_params, -)) + Ok((path_params,)) } /// DeleteUser - DELETE /v2/user/{username} #[tracing::instrument(skip_all)] async fn delete_user( - method: Method, - host: Host, - cookies: CookieJar, - Path(path_params): Path, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + Path(path_params): Path, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || delete_user_validation(path_params)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - delete_user_validation( - path_params, - ) - ).await.unwrap(); - - let Ok(( - path_params, - )) = validation else { - return Response::builder() + let Ok((path_params,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().delete_user( - method, - host, - cookies, - path_params, - ).await; + let result = api_impl + .as_ref() + .delete_user(method, host, cookies, path_params) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - DeleteUserResponse::Status400_InvalidUsernameSupplied - => { + let resp = match result { + Ok(rsp) => match rsp { + DeleteUserResponse::Status400_InvalidUsernameSupplied => { + let mut response = response.status(400); + response.body(Body::empty()) + } + DeleteUserResponse::Status404_UserNotFound => { + let mut response = response.status(404); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(400); - response.body(Body::empty()) - }, - DeleteUserResponse::Status404_UserNotFound - => { - - let mut response = response.status(404); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] fn get_user_by_name_validation( - path_params: models::GetUserByNamePathParams, -) -> std::result::Result<( - models::GetUserByNamePathParams, -), ValidationErrors> -{ - path_params.validate()?; + path_params: models::GetUserByNamePathParams, +) -> std::result::Result<(models::GetUserByNamePathParams,), ValidationErrors> { + path_params.validate()?; -Ok(( - path_params, -)) + Ok((path_params,)) } /// GetUserByName - GET /v2/user/{username} #[tracing::instrument(skip_all)] async fn get_user_by_name( - method: Method, - host: Host, - cookies: CookieJar, - Path(path_params): Path, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + Path(path_params): Path, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || get_user_by_name_validation(path_params)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - get_user_by_name_validation( - path_params, - ) - ).await.unwrap(); - - let Ok(( - path_params, - )) = validation else { - return Response::builder() + let Ok((path_params,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().get_user_by_name( - method, - host, - cookies, - path_params, - ).await; + let result = api_impl + .as_ref() + .get_user_by_name(method, host, cookies, path_params) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - GetUserByNameResponse::Status200_SuccessfulOperation - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + GetUserByNameResponse::Status200_SuccessfulOperation(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("text/plain").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("text/plain").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = body; + response.body(Body::from(body_content)) + } + GetUserByNameResponse::Status400_InvalidUsernameSupplied => { + let mut response = response.status(400); + response.body(Body::empty()) + } + GetUserByNameResponse::Status404_UserNotFound => { + let mut response = response.status(404); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = body; - response.body(Body::from(body_content)) - }, - GetUserByNameResponse::Status400_InvalidUsernameSupplied - => { - - let mut response = response.status(400); - response.body(Body::empty()) - }, - GetUserByNameResponse::Status404_UserNotFound - => { - - let mut response = response.status(404); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] fn login_user_validation( - query_params: models::LoginUserQueryParams, -) -> std::result::Result<( - models::LoginUserQueryParams, -), ValidationErrors> -{ - query_params.validate()?; + query_params: models::LoginUserQueryParams, +) -> std::result::Result<(models::LoginUserQueryParams,), ValidationErrors> { + query_params.validate()?; -Ok(( - query_params, -)) + Ok((query_params,)) } /// LoginUser - GET /v2/user/login #[tracing::instrument(skip_all)] async fn login_user( - method: Method, - host: Host, - cookies: CookieJar, - Query(query_params): Query, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + Query(query_params): Query, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || login_user_validation(query_params)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - login_user_validation( - query_params, - ) - ).await.unwrap(); - - let Ok(( - query_params, - )) = validation else { - return Response::builder() + let Ok((query_params,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().login_user( - method, - host, - cookies, - query_params, - ).await; + let result = api_impl + .as_ref() + .login_user(method, host, cookies, query_params) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - LoginUserResponse::Status200_SuccessfulOperation - { - body, - set_cookie, - x_rate_limit, - x_expires_after - } - => { - if let Some(set_cookie) = set_cookie { - let set_cookie = match header::IntoHeaderValue(set_cookie).try_into() { - Ok(val) => val, - Err(e) => { - return Response::builder() + let resp = match result { + Ok(rsp) => match rsp { + LoginUserResponse::Status200_SuccessfulOperation { + body, + set_cookie, + x_rate_limit, + x_expires_after, + } => { + if let Some(set_cookie) = set_cookie { + let set_cookie = match header::IntoHeaderValue(set_cookie).try_into() { + Ok(val) => val, + Err(e) => { + return Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling set_cookie header - {}", e))).map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }); - } - }; + } + }; - - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - HeaderName::from_static("set-cookie"), - set_cookie - ); - } - } - if let Some(x_rate_limit) = x_rate_limit { - let x_rate_limit = match header::IntoHeaderValue(x_rate_limit).try_into() { - Ok(val) => val, - Err(e) => { - return Response::builder() + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert(HeaderName::from_static("set-cookie"), set_cookie); + } + } + if let Some(x_rate_limit) = x_rate_limit { + let x_rate_limit = match header::IntoHeaderValue(x_rate_limit).try_into() { + Ok(val) => val, + Err(e) => { + return Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling x_rate_limit header - {}", e))).map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }); - } - }; + } + }; - - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - HeaderName::from_static("x-rate-limit"), - x_rate_limit - ); - } - } - if let Some(x_expires_after) = x_expires_after { - let x_expires_after = match header::IntoHeaderValue(x_expires_after).try_into() { - Ok(val) => val, - Err(e) => { - return Response::builder() + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers + .insert(HeaderName::from_static("x-rate-limit"), x_rate_limit); + } + } + if let Some(x_expires_after) = x_expires_after { + let x_expires_after = match header::IntoHeaderValue(x_expires_after).try_into() + { + Ok(val) => val, + Err(e) => { + return Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling x_expires_after header - {}", e))).map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }); - } - }; + } + }; - - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - HeaderName::from_static("x-expires-after"), - x_expires_after - ); - } - } + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers + .insert(HeaderName::from_static("x-expires-after"), x_expires_after); + } + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("text/plain").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("text/plain").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let body_content = body; - response.body(Body::from(body_content)) - }, - LoginUserResponse::Status400_InvalidUsername - => { + let body_content = body; + response.body(Body::from(body_content)) + } + LoginUserResponse::Status400_InvalidUsername => { + let mut response = response.status(400); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(400); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] -fn logout_user_validation( -) -> std::result::Result<( -), ValidationErrors> -{ - -Ok(( -)) +fn logout_user_validation() -> std::result::Result<(), ValidationErrors> { + Ok(()) } /// LogoutUser - GET /v2/user/logout #[tracing::instrument(skip_all)] async fn logout_user( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || logout_user_validation()) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - logout_user_validation( - ) - ).await.unwrap(); - - let Ok(( - )) = validation else { - return Response::builder() + let Ok(()) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().logout_user( - method, - host, - cookies, - ).await; + let result = api_impl.as_ref().logout_user(method, host, cookies).await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - LogoutUserResponse::Status0_SuccessfulOperation - => { + let resp = match result { + Ok(rsp) => match rsp { + LogoutUserResponse::Status0_SuccessfulOperation => { + let mut response = response.status(0); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(0); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct UpdateUserBodyValidator<'a> { - #[validate] - body: &'a models::User, - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct UpdateUserBodyValidator<'a> { + #[validate] + body: &'a models::User, +} #[tracing::instrument(skip_all)] fn update_user_validation( - path_params: models::UpdateUserPathParams, - body: models::User, -) -> std::result::Result<( - models::UpdateUserPathParams, - models::User, -), ValidationErrors> -{ - path_params.validate()?; - let b = UpdateUserBodyValidator { body: &body }; - b.validate()?; + path_params: models::UpdateUserPathParams, + body: models::User, +) -> std::result::Result<(models::UpdateUserPathParams, models::User), ValidationErrors> { + path_params.validate()?; + let b = UpdateUserBodyValidator { body: &body }; + b.validate()?; -Ok(( - path_params, - body, -)) + Ok((path_params, body)) } /// UpdateUser - PUT /v2/user/{username} #[tracing::instrument(skip_all)] async fn update_user( - method: Method, - host: Host, - cookies: CookieJar, - Path(path_params): Path, - State(api_impl): State, - Json(body): Json, + method: Method, + host: Host, + cookies: CookieJar, + Path(path_params): Path, + State(api_impl): State, + Json(body): Json, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || update_user_validation(path_params, body)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - update_user_validation( - path_params, - body, - ) - ).await.unwrap(); - - let Ok(( - path_params, - body, - )) = validation else { - return Response::builder() + let Ok((path_params, body)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().update_user( - method, - host, - cookies, - path_params, - body, - ).await; + let result = api_impl + .as_ref() + .update_user(method, host, cookies, path_params, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - UpdateUserResponse::Status400_InvalidUserSupplied - => { + let resp = match result { + Ok(rsp) => match rsp { + UpdateUserResponse::Status400_InvalidUserSupplied => { + let mut response = response.status(400); + response.body(Body::empty()) + } + UpdateUserResponse::Status404_UserNotFound => { + let mut response = response.status(404); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(400); - response.body(Body::empty()) - }, - UpdateUserResponse::Status404_UserNotFound - => { - - let mut response = response.status(404); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - diff --git a/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/header.rs b/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/header.rs index 4d1cc4c6dcc..7c530892fbf 100644 --- a/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/header.rs +++ b/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/header.rs @@ -30,11 +30,16 @@ macro_rules! ihv_generate { match hdr_value.to_str() { Ok(hdr_value) => match hdr_value.parse::<$t>() { Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value)), - Err(e) => Err(format!("Unable to parse {} as a string: {}", - stringify!($t), e)), + Err(e) => Err(format!( + "Unable to parse {} as a string: {}", + stringify!($t), + e + )), }, - Err(e) => Err(format!("Unable to parse header {:?} as a string - {}", - hdr_value, e)), + Err(e) => Err(format!( + "Unable to parse header {:?} as a string - {}", + hdr_value, e + )), } } } @@ -69,14 +74,17 @@ impl TryFrom for IntoHeaderValue> { match hdr_value.to_str() { Ok(hdr_value) => Ok(IntoHeaderValue( hdr_value - .split(',') - .filter_map(|x| match x.trim() { - "" => None, - y => Some(y.to_string()), - }) - .collect())), - Err(e) => Err(format!("Unable to parse header: {:?} as a string - {}", - hdr_value, e)), + .split(',') + .filter_map(|x| match x.trim() { + "" => None, + y => Some(y.to_string()), + }) + .collect(), + )), + Err(e) => Err(format!( + "Unable to parse header: {:?} as a string - {}", + hdr_value, e + )), } } } @@ -85,11 +93,13 @@ impl TryFrom>> for HeaderValue { type Error = String; fn try_from(hdr_value: IntoHeaderValue>) -> Result { - match HeaderValue::from_str(&hdr_value.0.join(", ")) { - Ok(hdr_value) => Ok(hdr_value), - Err(e) => Err(format!("Unable to convert {:?} into a header - {}", - hdr_value, e)) - } + match HeaderValue::from_str(&hdr_value.0.join(", ")) { + Ok(hdr_value) => Ok(hdr_value), + Err(e) => Err(format!( + "Unable to convert {:?} into a header - {}", + hdr_value, e + )), + } } } @@ -101,8 +111,7 @@ impl TryFrom for IntoHeaderValue { fn try_from(hdr_value: HeaderValue) -> Result { match hdr_value.to_str() { Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value.to_string())), - Err(e) => Err(format!("Unable to convert header {:?} to {}", - hdr_value, e)), + Err(e) => Err(format!("Unable to convert header {:?} to {}", hdr_value, e)), } } } @@ -113,8 +122,10 @@ impl TryFrom> for HeaderValue { fn try_from(hdr_value: IntoHeaderValue) -> Result { match HeaderValue::from_str(&hdr_value.0) { Ok(hdr_value) => Ok(hdr_value), - Err(e) => Err(format!("Unable to convert {:?} from a header {}", - hdr_value, e)) + Err(e) => Err(format!( + "Unable to convert {:?} from a header {}", + hdr_value, e + )), } } } @@ -128,11 +139,12 @@ impl TryFrom for IntoHeaderValue { match hdr_value.to_str() { Ok(hdr_value) => match hdr_value.parse() { Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value)), - Err(e) => Err(format!("Unable to parse bool from {} - {}", - hdr_value, e)), + Err(e) => Err(format!("Unable to parse bool from {} - {}", hdr_value, e)), }, - Err(e) => Err(format!("Unable to convert {:?} from a header {}", - hdr_value, e)), + Err(e) => Err(format!( + "Unable to convert {:?} from a header {}", + hdr_value, e + )), } } } @@ -143,8 +155,10 @@ impl TryFrom> for HeaderValue { fn try_from(hdr_value: IntoHeaderValue) -> Result { match HeaderValue::from_str(&hdr_value.0.to_string()) { Ok(hdr_value) => Ok(hdr_value), - Err(e) => Err(format!("Unable to convert: {:?} into a header: {}", - hdr_value, e)) + Err(e) => Err(format!( + "Unable to convert: {:?} into a header: {}", + hdr_value, e + )), } } } @@ -158,11 +172,12 @@ impl TryFrom for IntoHeaderValue> { match hdr_value.to_str() { Ok(hdr_value) => match DateTime::parse_from_rfc3339(hdr_value) { Ok(date) => Ok(IntoHeaderValue(date.with_timezone(&Utc))), - Err(e) => Err(format!("Unable to parse: {} as date - {}", - hdr_value, e)), + Err(e) => Err(format!("Unable to parse: {} as date - {}", hdr_value, e)), }, - Err(e) => Err(format!("Unable to convert header {:?} to string {}", - hdr_value, e)), + Err(e) => Err(format!( + "Unable to convert header {:?} to string {}", + hdr_value, e + )), } } } @@ -173,8 +188,10 @@ impl TryFrom>> for HeaderValue { fn try_from(hdr_value: IntoHeaderValue>) -> Result { match HeaderValue::from_str(hdr_value.0.to_rfc3339().as_str()) { Ok(hdr_value) => Ok(hdr_value), - Err(e) => Err(format!("Unable to convert {:?} to a header: {}", - hdr_value, e)), + Err(e) => Err(format!( + "Unable to convert {:?} to a header: {}", + hdr_value, e + )), } } } diff --git a/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/lib.rs b/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/lib.rs index f99c0799ecf..5b44cc42895 100644 --- a/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/lib.rs +++ b/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/lib.rs @@ -1,4 +1,12 @@ -#![allow(missing_docs, trivial_casts, unused_variables, unused_mut, unused_imports, unused_extern_crates, non_camel_case_types)] +#![allow( + missing_docs, + trivial_casts, + unused_variables, + unused_mut, + unused_imports, + unused_extern_crates, + non_camel_case_types +)] #![allow(unused_imports, unused_attributes)] #![allow(clippy::derive_partial_eq_without_eq, clippy::disallowed_names)] @@ -14,28 +22,25 @@ use types::*; pub const BASE_PATH: &str = ""; pub const API_VERSION: &str = "1.0"; - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum PingGetResponse { /// OK - Status201_OK + Status201_OK, } - /// API #[async_trait] #[allow(clippy::ptr_arg)] pub trait Api { - - /// PingGet - GET /ping - async fn ping_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - + /// PingGet - GET /ping + async fn ping_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; } #[cfg(feature = "server")] diff --git a/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/models.rs b/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/models.rs index 34696c0ab8a..58fc026395c 100644 --- a/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/models.rs +++ b/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/models.rs @@ -6,6 +6,3 @@ use validator::Validate; #[cfg(feature = "server")] use crate::header; use crate::{models, types::*}; - - - diff --git a/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/server/mod.rs b/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/server/mod.rs index 76578d0a4ec..5ec08d2d341 100644 --- a/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/server/mod.rs +++ b/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/server/mod.rs @@ -12,9 +12,7 @@ use crate::{header, types::*}; #[allow(unused_imports)] use crate::models; -use crate::{Api, - PingGetResponse -}; +use crate::{Api, PingGetResponse}; /// Setup API Server. pub fn new(api_impl: I) -> Router @@ -24,74 +22,59 @@ where { // build our application with a route Router::new() - .route("/ping", - get(ping_get::) - ) + .route("/ping", get(ping_get::)) .with_state(api_impl) } - #[tracing::instrument(skip_all)] -fn ping_get_validation( -) -> std::result::Result<( -), ValidationErrors> -{ - -Ok(( -)) +fn ping_get_validation() -> std::result::Result<(), ValidationErrors> { + Ok(()) } /// PingGet - GET /ping #[tracing::instrument(skip_all)] async fn ping_get( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || ping_get_validation()) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - ping_get_validation( - ) - ).await.unwrap(); - - let Ok(( - )) = validation else { - return Response::builder() + let Ok(()) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().ping_get( - method, - host, - cookies, - ).await; + let result = api_impl.as_ref().ping_get(method, host, cookies).await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - PingGetResponse::Status201_OK - => { + let resp = match result { + Ok(rsp) => match rsp { + PingGetResponse::Status201_OK => { + let mut response = response.status(201); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(201); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - diff --git a/samples/server/petstore/rust-axum/output/rust-axum-test/src/header.rs b/samples/server/petstore/rust-axum/output/rust-axum-test/src/header.rs index 4d1cc4c6dcc..7c530892fbf 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-test/src/header.rs +++ b/samples/server/petstore/rust-axum/output/rust-axum-test/src/header.rs @@ -30,11 +30,16 @@ macro_rules! ihv_generate { match hdr_value.to_str() { Ok(hdr_value) => match hdr_value.parse::<$t>() { Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value)), - Err(e) => Err(format!("Unable to parse {} as a string: {}", - stringify!($t), e)), + Err(e) => Err(format!( + "Unable to parse {} as a string: {}", + stringify!($t), + e + )), }, - Err(e) => Err(format!("Unable to parse header {:?} as a string - {}", - hdr_value, e)), + Err(e) => Err(format!( + "Unable to parse header {:?} as a string - {}", + hdr_value, e + )), } } } @@ -69,14 +74,17 @@ impl TryFrom for IntoHeaderValue> { match hdr_value.to_str() { Ok(hdr_value) => Ok(IntoHeaderValue( hdr_value - .split(',') - .filter_map(|x| match x.trim() { - "" => None, - y => Some(y.to_string()), - }) - .collect())), - Err(e) => Err(format!("Unable to parse header: {:?} as a string - {}", - hdr_value, e)), + .split(',') + .filter_map(|x| match x.trim() { + "" => None, + y => Some(y.to_string()), + }) + .collect(), + )), + Err(e) => Err(format!( + "Unable to parse header: {:?} as a string - {}", + hdr_value, e + )), } } } @@ -85,11 +93,13 @@ impl TryFrom>> for HeaderValue { type Error = String; fn try_from(hdr_value: IntoHeaderValue>) -> Result { - match HeaderValue::from_str(&hdr_value.0.join(", ")) { - Ok(hdr_value) => Ok(hdr_value), - Err(e) => Err(format!("Unable to convert {:?} into a header - {}", - hdr_value, e)) - } + match HeaderValue::from_str(&hdr_value.0.join(", ")) { + Ok(hdr_value) => Ok(hdr_value), + Err(e) => Err(format!( + "Unable to convert {:?} into a header - {}", + hdr_value, e + )), + } } } @@ -101,8 +111,7 @@ impl TryFrom for IntoHeaderValue { fn try_from(hdr_value: HeaderValue) -> Result { match hdr_value.to_str() { Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value.to_string())), - Err(e) => Err(format!("Unable to convert header {:?} to {}", - hdr_value, e)), + Err(e) => Err(format!("Unable to convert header {:?} to {}", hdr_value, e)), } } } @@ -113,8 +122,10 @@ impl TryFrom> for HeaderValue { fn try_from(hdr_value: IntoHeaderValue) -> Result { match HeaderValue::from_str(&hdr_value.0) { Ok(hdr_value) => Ok(hdr_value), - Err(e) => Err(format!("Unable to convert {:?} from a header {}", - hdr_value, e)) + Err(e) => Err(format!( + "Unable to convert {:?} from a header {}", + hdr_value, e + )), } } } @@ -128,11 +139,12 @@ impl TryFrom for IntoHeaderValue { match hdr_value.to_str() { Ok(hdr_value) => match hdr_value.parse() { Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value)), - Err(e) => Err(format!("Unable to parse bool from {} - {}", - hdr_value, e)), + Err(e) => Err(format!("Unable to parse bool from {} - {}", hdr_value, e)), }, - Err(e) => Err(format!("Unable to convert {:?} from a header {}", - hdr_value, e)), + Err(e) => Err(format!( + "Unable to convert {:?} from a header {}", + hdr_value, e + )), } } } @@ -143,8 +155,10 @@ impl TryFrom> for HeaderValue { fn try_from(hdr_value: IntoHeaderValue) -> Result { match HeaderValue::from_str(&hdr_value.0.to_string()) { Ok(hdr_value) => Ok(hdr_value), - Err(e) => Err(format!("Unable to convert: {:?} into a header: {}", - hdr_value, e)) + Err(e) => Err(format!( + "Unable to convert: {:?} into a header: {}", + hdr_value, e + )), } } } @@ -158,11 +172,12 @@ impl TryFrom for IntoHeaderValue> { match hdr_value.to_str() { Ok(hdr_value) => match DateTime::parse_from_rfc3339(hdr_value) { Ok(date) => Ok(IntoHeaderValue(date.with_timezone(&Utc))), - Err(e) => Err(format!("Unable to parse: {} as date - {}", - hdr_value, e)), + Err(e) => Err(format!("Unable to parse: {} as date - {}", hdr_value, e)), }, - Err(e) => Err(format!("Unable to convert header {:?} to string {}", - hdr_value, e)), + Err(e) => Err(format!( + "Unable to convert header {:?} to string {}", + hdr_value, e + )), } } } @@ -173,8 +188,10 @@ impl TryFrom>> for HeaderValue { fn try_from(hdr_value: IntoHeaderValue>) -> Result { match HeaderValue::from_str(hdr_value.0.to_rfc3339().as_str()) { Ok(hdr_value) => Ok(hdr_value), - Err(e) => Err(format!("Unable to convert {:?} to a header: {}", - hdr_value, e)), + Err(e) => Err(format!( + "Unable to convert {:?} to a header: {}", + hdr_value, e + )), } } } diff --git a/samples/server/petstore/rust-axum/output/rust-axum-test/src/lib.rs b/samples/server/petstore/rust-axum/output/rust-axum-test/src/lib.rs index 41f3a2ace3f..4024a01566d 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-test/src/lib.rs +++ b/samples/server/petstore/rust-axum/output/rust-axum-test/src/lib.rs @@ -1,4 +1,12 @@ -#![allow(missing_docs, trivial_casts, unused_variables, unused_mut, unused_imports, unused_extern_crates, non_camel_case_types)] +#![allow( + missing_docs, + trivial_casts, + unused_variables, + unused_mut, + unused_imports, + unused_extern_crates, + non_camel_case_types +)] #![allow(unused_imports, unused_attributes)] #![allow(clippy::derive_partial_eq_without_eq, clippy::disallowed_names)] @@ -14,183 +22,167 @@ use types::*; pub const BASE_PATH: &str = ""; pub const API_VERSION: &str = "2.3.4"; - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum AllOfGetResponse { /// OK - Status200_OK - (models::AllOfObject) + Status200_OK(models::AllOfObject), } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum DummyGetResponse { /// Success - Status200_Success + Status200_Success, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum DummyPutResponse { /// Success - Status200_Success + Status200_Success, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum FileResponseGetResponse { /// Success - Status200_Success - (ByteArray) + Status200_Success(ByteArray), } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum GetStructuredYamlResponse { /// OK - Status200_OK - (String) + Status200_OK(String), } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum HtmlPostResponse { /// Success - Status200_Success - (String) + Status200_Success(String), } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum PostYamlResponse { /// OK - Status204_OK + Status204_OK, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum RawJsonGetResponse { /// Success - Status200_Success - (crate::types::Object) + Status200_Success(crate::types::Object), } - #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[must_use] #[allow(clippy::large_enum_variant)] pub enum SoloObjectPostResponse { /// OK - Status204_OK + Status204_OK, } - /// API #[async_trait] #[allow(clippy::ptr_arg)] pub trait Api { + /// AllOfGet - GET /allOf + async fn all_of_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; - /// AllOfGet - GET /allOf - async fn all_of_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + /// A dummy endpoint to make the spec valid.. + /// + /// DummyGet - GET /dummy + async fn dummy_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// DummyPut - PUT /dummy + async fn dummy_put( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: models::DummyPutRequest, + ) -> Result; - /// A dummy endpoint to make the spec valid.. - /// - /// DummyGet - GET /dummy - async fn dummy_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + /// Get a file. + /// + /// FileResponseGet - GET /file_response + async fn file_response_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// GetStructuredYaml - GET /get-structured-yaml + async fn get_structured_yaml( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; - /// DummyPut - PUT /dummy - async fn dummy_put( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::DummyPutRequest, - ) -> Result; + /// Test HTML handling. + /// + /// HtmlPost - POST /html + async fn html_post( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: String, + ) -> Result; + /// PostYaml - POST /post-yaml + async fn post_yaml( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: String, + ) -> Result; - /// Get a file. - /// - /// FileResponseGet - GET /file_response - async fn file_response_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - - /// GetStructuredYaml - GET /get-structured-yaml - async fn get_structured_yaml( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - - /// Test HTML handling. - /// - /// HtmlPost - POST /html - async fn html_post( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: String, - ) -> Result; - - - /// PostYaml - POST /post-yaml - async fn post_yaml( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: String, - ) -> Result; - - - /// Get an arbitrary JSON blob.. - /// - /// RawJsonGet - GET /raw_json - async fn raw_json_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - - /// Send an arbitrary JSON blob. - /// - /// SoloObjectPost - POST /solo-object - async fn solo_object_post( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: crate::types::Object, - ) -> Result; + /// Get an arbitrary JSON blob.. + /// + /// RawJsonGet - GET /raw_json + async fn raw_json_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Send an arbitrary JSON blob. + /// + /// SoloObjectPost - POST /solo-object + async fn solo_object_post( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: crate::types::Object, + ) -> Result; } #[cfg(feature = "server")] diff --git a/samples/server/petstore/rust-axum/output/rust-axum-test/src/models.rs b/samples/server/petstore/rust-axum/output/rust-axum-test/src/models.rs index e8afc229ad8..edd388bdec1 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-test/src/models.rs +++ b/samples/server/petstore/rust-axum/output/rust-axum-test/src/models.rs @@ -7,38 +7,22 @@ use validator::Validate; use crate::header; use crate::{models, types::*}; - - - - - - - - - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct ANullableContainer { #[serde(rename = "NullableThing")] #[serde(deserialize_with = "deserialize_optional_nullable")] #[serde(default = "default_optional_nullable")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub nullable_thing: Option>, #[serde(rename = "RequiredNullableThing")] pub required_nullable_thing: Nullable, - } - impl ANullableContainer { #[allow(clippy::new_without_default, clippy::too_many_arguments)] - pub fn new(required_nullable_thing: Nullable, ) -> ANullableContainer { + pub fn new(required_nullable_thing: Nullable) -> ANullableContainer { ANullableContainer { nullable_thing: None, required_nullable_thing, @@ -52,18 +36,21 @@ impl ANullableContainer { impl std::string::ToString for ANullableContainer { fn to_string(&self) -> String { let params: Vec> = vec![ - self.nullable_thing.as_ref().map(|nullable_thing| { [ "NullableThing".to_string(), - nullable_thing.as_ref().map_or("null".to_string(), |x| x.to_string()), - ].join(",") + nullable_thing + .as_ref() + .map_or("null".to_string(), |x| x.to_string()), + ] + .join(",") }), - - Some("RequiredNullableThing".to_string()), - Some(self.required_nullable_thing.as_ref().map_or("null".to_string(), |x| x.to_string())), - + Some( + self.required_nullable_thing + .as_ref() + .map_or("null".to_string(), |x| x.to_string()), + ), ]; params.into_iter().flatten().collect::>().join(",") @@ -94,7 +81,11 @@ impl std::str::FromStr for ANullableContainer { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing ANullableContainer".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing ANullableContainer".to_string(), + ) + } }; if let Some(key) = key_result { @@ -112,8 +103,12 @@ impl std::str::FromStr for ANullableContainer { // Use the intermediate representation to return the struct std::result::Result::Ok(ANullableContainer { - nullable_thing: std::result::Result::Err("Nullable types not supported in ANullableContainer".to_string())?, - required_nullable_thing: std::result::Result::Err("Nullable types not supported in ANullableContainer".to_string())?, + nullable_thing: std::result::Result::Err( + "Nullable types not supported in ANullableContainer".to_string(), + )?, + required_nullable_thing: std::result::Result::Err( + "Nullable types not supported in ANullableContainer".to_string(), + )?, }) } } @@ -124,13 +119,16 @@ impl std::str::FromStr for ANullableContainer { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for ANullableContainer - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for ANullableContainer - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -141,24 +139,25 @@ impl std::convert::TryFrom for header::IntoHeaderValue std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into ANullableContainer - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into ANullableContainer - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - /// An additionalPropertiesObject #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] @@ -212,28 +211,24 @@ impl ::std::str::FromStr for AdditionalPropertiesObject { type Err = &'static str; fn from_str(s: &str) -> std::result::Result { - std::result::Result::Err("Parsing additionalProperties for AdditionalPropertiesObject is not supported") + std::result::Result::Err( + "Parsing additionalProperties for AdditionalPropertiesObject is not supported", + ) } } - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct AllOfObject { #[serde(rename = "sampleProperty")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub sample_property: Option, #[serde(rename = "sampleBaseProperty")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub sample_base_property: Option, - } - impl AllOfObject { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> AllOfObject { @@ -250,22 +245,18 @@ impl AllOfObject { impl std::string::ToString for AllOfObject { fn to_string(&self) -> String { let params: Vec> = vec![ - self.sample_property.as_ref().map(|sample_property| { - [ - "sampleProperty".to_string(), - sample_property.to_string(), - ].join(",") + ["sampleProperty".to_string(), sample_property.to_string()].join(",") }), - - - self.sample_base_property.as_ref().map(|sample_base_property| { - [ - "sampleBaseProperty".to_string(), - sample_base_property.to_string(), - ].join(",") - }), - + self.sample_base_property + .as_ref() + .map(|sample_base_property| { + [ + "sampleBaseProperty".to_string(), + sample_base_property.to_string(), + ] + .join(",") + }), ]; params.into_iter().flatten().collect::>().join(",") @@ -296,17 +287,29 @@ impl std::str::FromStr for AllOfObject { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing AllOfObject".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing AllOfObject".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "sampleProperty" => intermediate_rep.sample_property.push(::from_str(val).map_err(|x| x.to_string())?), + "sampleProperty" => intermediate_rep.sample_property.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "sampleBaseProperty" => intermediate_rep.sample_base_property.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing AllOfObject".to_string()) + "sampleBaseProperty" => intermediate_rep.sample_base_property.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing AllOfObject".to_string(), + ) + } } } @@ -328,13 +331,16 @@ impl std::str::FromStr for AllOfObject { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for AllOfObject - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for AllOfObject - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -345,37 +351,33 @@ impl std::convert::TryFrom for header::IntoHeaderValue fn try_from(hdr_value: HeaderValue) -> std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into AllOfObject - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into AllOfObject - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct BaseAllOf { #[serde(rename = "sampleBaseProperty")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub sample_base_property: Option, - } - impl BaseAllOf { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> BaseAllOf { @@ -390,16 +392,17 @@ impl BaseAllOf { /// Should be implemented in a serde serializer impl std::string::ToString for BaseAllOf { fn to_string(&self) -> String { - let params: Vec> = vec![ - - self.sample_base_property.as_ref().map(|sample_base_property| { - [ - "sampleBaseProperty".to_string(), - sample_base_property.to_string(), - ].join(",") - }), - - ]; + let params: Vec> = + vec![self + .sample_base_property + .as_ref() + .map(|sample_base_property| { + [ + "sampleBaseProperty".to_string(), + sample_base_property.to_string(), + ] + .join(",") + })]; params.into_iter().flatten().collect::>().join(",") } @@ -428,15 +431,25 @@ impl std::str::FromStr for BaseAllOf { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing BaseAllOf".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing BaseAllOf".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "sampleBaseProperty" => intermediate_rep.sample_base_property.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing BaseAllOf".to_string()) + "sampleBaseProperty" => intermediate_rep.sample_base_property.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing BaseAllOf".to_string(), + ) + } } } @@ -457,13 +470,16 @@ impl std::str::FromStr for BaseAllOf { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for BaseAllOf - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for BaseAllOf - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -474,27 +490,25 @@ impl std::convert::TryFrom for header::IntoHeaderValue { fn try_from(hdr_value: HeaderValue) -> std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into BaseAllOf - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into BaseAllOf - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct DummyPutRequest { @@ -502,19 +516,14 @@ pub struct DummyPutRequest { pub id: String, #[serde(rename = "password")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub password: Option, - } - impl DummyPutRequest { #[allow(clippy::new_without_default, clippy::too_many_arguments)] - pub fn new(id: String, ) -> DummyPutRequest { - DummyPutRequest { - id, - password: None, - } + pub fn new(id: String) -> DummyPutRequest { + DummyPutRequest { id, password: None } } } @@ -524,18 +533,11 @@ impl DummyPutRequest { impl std::string::ToString for DummyPutRequest { fn to_string(&self) -> String { let params: Vec> = vec![ - Some("id".to_string()), Some(self.id.to_string()), - - - self.password.as_ref().map(|password| { - [ - "password".to_string(), - password.to_string(), - ].join(",") - }), - + self.password + .as_ref() + .map(|password| ["password".to_string(), password.to_string()].join(",")), ]; params.into_iter().flatten().collect::>().join(",") @@ -566,17 +568,29 @@ impl std::str::FromStr for DummyPutRequest { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing DummyPutRequest".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing DummyPutRequest".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "id" => intermediate_rep.id.push(::from_str(val).map_err(|x| x.to_string())?), + "id" => intermediate_rep.id.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "password" => intermediate_rep.password.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing DummyPutRequest".to_string()) + "password" => intermediate_rep.password.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing DummyPutRequest".to_string(), + ) + } } } @@ -586,7 +600,11 @@ impl std::str::FromStr for DummyPutRequest { // Use the intermediate representation to return the struct std::result::Result::Ok(DummyPutRequest { - id: intermediate_rep.id.into_iter().next().ok_or_else(|| "id missing in DummyPutRequest".to_string())?, + id: intermediate_rep + .id + .into_iter() + .next() + .ok_or_else(|| "id missing in DummyPutRequest".to_string())?, password: intermediate_rep.password.into_iter().next(), }) } @@ -598,13 +616,16 @@ impl std::str::FromStr for DummyPutRequest { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for DummyPutRequest - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for DummyPutRequest - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -615,45 +636,40 @@ impl std::convert::TryFrom for header::IntoHeaderValue std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into DummyPutRequest - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into DummyPutRequest - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - /// structured response - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct GetYamlResponse { -/// Inner string + /// Inner string #[serde(rename = "value")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub value: Option, - } - impl GetYamlResponse { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> GetYamlResponse { - GetYamlResponse { - value: None, - } + GetYamlResponse { value: None } } } @@ -662,16 +678,10 @@ impl GetYamlResponse { /// Should be implemented in a serde serializer impl std::string::ToString for GetYamlResponse { fn to_string(&self) -> String { - let params: Vec> = vec![ - - self.value.as_ref().map(|value| { - [ - "value".to_string(), - value.to_string(), - ].join(",") - }), - - ]; + let params: Vec> = vec![self + .value + .as_ref() + .map(|value| ["value".to_string(), value.to_string()].join(","))]; params.into_iter().flatten().collect::>().join(",") } @@ -700,15 +710,25 @@ impl std::str::FromStr for GetYamlResponse { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing GetYamlResponse".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing GetYamlResponse".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "value" => intermediate_rep.value.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing GetYamlResponse".to_string()) + "value" => intermediate_rep.value.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing GetYamlResponse".to_string(), + ) + } } } @@ -729,13 +749,16 @@ impl std::str::FromStr for GetYamlResponse { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for GetYamlResponse - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for GetYamlResponse - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -746,44 +769,39 @@ impl std::convert::TryFrom for header::IntoHeaderValue std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into GetYamlResponse - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into GetYamlResponse - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - /// An object of objects - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct ObjectOfObjects { #[serde(rename = "inner")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub inner: Option, - } - impl ObjectOfObjects { #[allow(clippy::new_without_default, clippy::too_many_arguments)] pub fn new() -> ObjectOfObjects { - ObjectOfObjects { - inner: None, - } + ObjectOfObjects { inner: None } } } @@ -824,15 +842,26 @@ impl std::str::FromStr for ObjectOfObjects { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing ObjectOfObjects".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing ObjectOfObjects".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "inner" => intermediate_rep.inner.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing ObjectOfObjects".to_string()) + "inner" => intermediate_rep.inner.push( + ::from_str(val) + .map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing ObjectOfObjects".to_string(), + ) + } } } @@ -853,13 +882,16 @@ impl std::str::FromStr for ObjectOfObjects { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for ObjectOfObjects - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for ObjectOfObjects - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -870,27 +902,25 @@ impl std::convert::TryFrom for header::IntoHeaderValue std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into ObjectOfObjects - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into ObjectOfObjects - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - - - - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct ObjectOfObjectsInner { @@ -898,15 +928,13 @@ pub struct ObjectOfObjectsInner { pub required_thing: String, #[serde(rename = "optional_thing")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub optional_thing: Option, - } - impl ObjectOfObjectsInner { #[allow(clippy::new_without_default, clippy::too_many_arguments)] - pub fn new(required_thing: String, ) -> ObjectOfObjectsInner { + pub fn new(required_thing: String) -> ObjectOfObjectsInner { ObjectOfObjectsInner { required_thing, optional_thing: None, @@ -920,18 +948,11 @@ impl ObjectOfObjectsInner { impl std::string::ToString for ObjectOfObjectsInner { fn to_string(&self) -> String { let params: Vec> = vec![ - Some("required_thing".to_string()), Some(self.required_thing.to_string()), - - self.optional_thing.as_ref().map(|optional_thing| { - [ - "optional_thing".to_string(), - optional_thing.to_string(), - ].join(",") + ["optional_thing".to_string(), optional_thing.to_string()].join(",") }), - ]; params.into_iter().flatten().collect::>().join(",") @@ -962,17 +983,29 @@ impl std::str::FromStr for ObjectOfObjectsInner { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing ObjectOfObjectsInner".to_string()) + None => { + return std::result::Result::Err( + "Missing value while parsing ObjectOfObjectsInner".to_string(), + ) + } }; if let Some(key) = key_result { #[allow(clippy::match_single_binding)] match key { #[allow(clippy::redundant_clone)] - "required_thing" => intermediate_rep.required_thing.push(::from_str(val).map_err(|x| x.to_string())?), + "required_thing" => intermediate_rep.required_thing.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), #[allow(clippy::redundant_clone)] - "optional_thing" => intermediate_rep.optional_thing.push(::from_str(val).map_err(|x| x.to_string())?), - _ => return std::result::Result::Err("Unexpected key while parsing ObjectOfObjectsInner".to_string()) + "optional_thing" => intermediate_rep.optional_thing.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), + _ => { + return std::result::Result::Err( + "Unexpected key while parsing ObjectOfObjectsInner".to_string(), + ) + } } } @@ -982,7 +1015,11 @@ impl std::str::FromStr for ObjectOfObjectsInner { // Use the intermediate representation to return the struct std::result::Result::Ok(ObjectOfObjectsInner { - required_thing: intermediate_rep.required_thing.into_iter().next().ok_or_else(|| "required_thing missing in ObjectOfObjectsInner".to_string())?, + required_thing: intermediate_rep + .required_thing + .into_iter() + .next() + .ok_or_else(|| "required_thing missing in ObjectOfObjectsInner".to_string())?, optional_thing: intermediate_rep.optional_thing.into_iter().next(), }) } @@ -994,13 +1031,16 @@ impl std::str::FromStr for ObjectOfObjectsInner { impl std::convert::TryFrom> for HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue) -> std::result::Result { + fn try_from( + hdr_value: header::IntoHeaderValue, + ) -> std::result::Result { let hdr_value = hdr_value.to_string(); match HeaderValue::from_str(&hdr_value) { - std::result::Result::Ok(value) => std::result::Result::Ok(value), - std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for ObjectOfObjectsInner - value: {} is invalid {}", - hdr_value, e)) + std::result::Result::Ok(value) => std::result::Result::Ok(value), + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Invalid header value for ObjectOfObjectsInner - value: {} is invalid {}", + hdr_value, e + )), } } } @@ -1011,20 +1051,21 @@ impl std::convert::TryFrom for header::IntoHeaderValue std::result::Result { match hdr_value.to_str() { - std::result::Result::Ok(value) => { - match ::from_str(value) { - std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), - std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into ObjectOfObjectsInner - {}", - value, err)) + std::result::Result::Ok(value) => { + match ::from_str(value) { + std::result::Result::Ok(value) => { + std::result::Result::Ok(header::IntoHeaderValue(value)) } - }, - std::result::Result::Err(e) => std::result::Result::Err( - format!("Unable to convert header: {:?} to string: {}", - hdr_value, e)) + std::result::Result::Err(err) => std::result::Result::Err(format!( + "Unable to convert header value '{}' into ObjectOfObjectsInner - {}", + value, err + )), + } + } + std::result::Result::Err(e) => std::result::Result::Err(format!( + "Unable to convert header: {:?} to string: {}", + hdr_value, e + )), } } } - - - diff --git a/samples/server/petstore/rust-axum/output/rust-axum-test/src/server/mod.rs b/samples/server/petstore/rust-axum/output/rust-axum-test/src/server/mod.rs index b08d1c72d6a..7acb80ed7ad 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-test/src/server/mod.rs +++ b/samples/server/petstore/rust-axum/output/rust-axum-test/src/server/mod.rs @@ -12,16 +12,10 @@ use crate::{header, types::*}; #[allow(unused_imports)] use crate::models; -use crate::{Api, - AllOfGetResponse, - DummyGetResponse, - DummyPutResponse, - FileResponseGetResponse, - GetStructuredYamlResponse, - HtmlPostResponse, - PostYamlResponse, - RawJsonGetResponse, - SoloObjectPostResponse +use crate::{ + AllOfGetResponse, Api, DummyGetResponse, DummyPutResponse, FileResponseGetResponse, + GetStructuredYamlResponse, HtmlPostResponse, PostYamlResponse, RawJsonGetResponse, + SoloObjectPostResponse, }; /// Setup API Server. @@ -32,729 +26,628 @@ where { // build our application with a route Router::new() - .route("/allOf", - get(all_of_get::) - ) - .route("/dummy", - get(dummy_get::).put(dummy_put::) - ) - .route("/file_response", - get(file_response_get::) - ) - .route("/get-structured-yaml", - get(get_structured_yaml::) - ) - .route("/html", - post(html_post::) - ) - .route("/post-yaml", - post(post_yaml::) - ) - .route("/raw_json", - get(raw_json_get::) - ) - .route("/solo-object", - post(solo_object_post::) - ) + .route("/allOf", get(all_of_get::)) + .route("/dummy", get(dummy_get::).put(dummy_put::)) + .route("/file_response", get(file_response_get::)) + .route("/get-structured-yaml", get(get_structured_yaml::)) + .route("/html", post(html_post::)) + .route("/post-yaml", post(post_yaml::)) + .route("/raw_json", get(raw_json_get::)) + .route("/solo-object", post(solo_object_post::)) .with_state(api_impl) } - #[tracing::instrument(skip_all)] -fn all_of_get_validation( -) -> std::result::Result<( -), ValidationErrors> -{ - -Ok(( -)) +fn all_of_get_validation() -> std::result::Result<(), ValidationErrors> { + Ok(()) } /// AllOfGet - GET /allOf #[tracing::instrument(skip_all)] async fn all_of_get( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || all_of_get_validation()) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - all_of_get_validation( - ) - ).await.unwrap(); - - let Ok(( - )) = validation else { - return Response::builder() + let Ok(()) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().all_of_get( - method, - host, - cookies, - ).await; + let result = api_impl.as_ref().all_of_get(method, host, cookies).await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - AllOfGetResponse::Status200_OK - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + AllOfGetResponse::Status200_OK(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("*/*").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("*/*").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = tokio::task::spawn_blocking(move || { + serde_json::to_vec(&body).map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) + }) + .await + .unwrap()?; + response.body(Body::from(body_content)) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = tokio::task::spawn_blocking(move || - serde_json::to_vec(&body).map_err(|e| { - error!(error = ?e); - StatusCode::INTERNAL_SERVER_ERROR - })).await.unwrap()?; - response.body(Body::from(body_content)) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] -fn dummy_get_validation( -) -> std::result::Result<( -), ValidationErrors> -{ - -Ok(( -)) +fn dummy_get_validation() -> std::result::Result<(), ValidationErrors> { + Ok(()) } /// DummyGet - GET /dummy #[tracing::instrument(skip_all)] async fn dummy_get( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || dummy_get_validation()) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - dummy_get_validation( - ) - ).await.unwrap(); - - let Ok(( - )) = validation else { - return Response::builder() + let Ok(()) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().dummy_get( - method, - host, - cookies, - ).await; + let result = api_impl.as_ref().dummy_get(method, host, cookies).await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - DummyGetResponse::Status200_Success - => { + let resp = match result { + Ok(rsp) => match rsp { + DummyGetResponse::Status200_Success => { + let mut response = response.status(200); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(200); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct DummyPutBodyValidator<'a> { - #[validate] - body: &'a models::DummyPutRequest, - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct DummyPutBodyValidator<'a> { + #[validate] + body: &'a models::DummyPutRequest, +} #[tracing::instrument(skip_all)] fn dummy_put_validation( - body: models::DummyPutRequest, -) -> std::result::Result<( - models::DummyPutRequest, -), ValidationErrors> -{ - let b = DummyPutBodyValidator { body: &body }; - b.validate()?; + body: models::DummyPutRequest, +) -> std::result::Result<(models::DummyPutRequest,), ValidationErrors> { + let b = DummyPutBodyValidator { body: &body }; + b.validate()?; -Ok(( - body, -)) + Ok((body,)) } /// DummyPut - PUT /dummy #[tracing::instrument(skip_all)] async fn dummy_put( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - Json(body): Json, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + Json(body): Json, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || dummy_put_validation(body)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - dummy_put_validation( - body, - ) - ).await.unwrap(); - - let Ok(( - body, - )) = validation else { - return Response::builder() + let Ok((body,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().dummy_put( - method, - host, - cookies, - body, - ).await; + let result = api_impl + .as_ref() + .dummy_put(method, host, cookies, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - DummyPutResponse::Status200_Success - => { + let resp = match result { + Ok(rsp) => match rsp { + DummyPutResponse::Status200_Success => { + let mut response = response.status(200); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(200); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] -fn file_response_get_validation( -) -> std::result::Result<( -), ValidationErrors> -{ - -Ok(( -)) +fn file_response_get_validation() -> std::result::Result<(), ValidationErrors> { + Ok(()) } /// FileResponseGet - GET /file_response #[tracing::instrument(skip_all)] async fn file_response_get( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || file_response_get_validation()) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - file_response_get_validation( - ) - ).await.unwrap(); - - let Ok(( - )) = validation else { - return Response::builder() + let Ok(()) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().file_response_get( - method, - host, - cookies, - ).await; + let result = api_impl + .as_ref() + .file_response_get(method, host, cookies) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - FileResponseGetResponse::Status200_Success - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + FileResponseGetResponse::Status200_Success(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("application/json").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("application/json").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = tokio::task::spawn_blocking(move || { + serde_json::to_vec(&body).map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) + }) + .await + .unwrap()?; + response.body(Body::from(body_content)) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = tokio::task::spawn_blocking(move || - serde_json::to_vec(&body).map_err(|e| { - error!(error = ?e); - StatusCode::INTERNAL_SERVER_ERROR - })).await.unwrap()?; - response.body(Body::from(body_content)) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] -fn get_structured_yaml_validation( -) -> std::result::Result<( -), ValidationErrors> -{ - -Ok(( -)) +fn get_structured_yaml_validation() -> std::result::Result<(), ValidationErrors> { + Ok(()) } /// GetStructuredYaml - GET /get-structured-yaml #[tracing::instrument(skip_all)] async fn get_structured_yaml( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || get_structured_yaml_validation()) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - get_structured_yaml_validation( - ) - ).await.unwrap(); - - let Ok(( - )) = validation else { - return Response::builder() + let Ok(()) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().get_structured_yaml( - method, - host, - cookies, - ).await; + let result = api_impl + .as_ref() + .get_structured_yaml(method, host, cookies) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - GetStructuredYamlResponse::Status200_OK - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + GetStructuredYamlResponse::Status200_OK(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("application/yaml").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("application/yaml").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = body; + response.body(Body::from(body_content)) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = body; - response.body(Body::from(body_content)) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct HtmlPostBodyValidator<'a> { - body: &'a String, - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct HtmlPostBodyValidator<'a> { + body: &'a String, +} #[tracing::instrument(skip_all)] -fn html_post_validation( - body: String, -) -> std::result::Result<( - String, -), ValidationErrors> -{ - -Ok(( - body, -)) +fn html_post_validation(body: String) -> std::result::Result<(String,), ValidationErrors> { + Ok((body,)) } /// HtmlPost - POST /html #[tracing::instrument(skip_all)] async fn html_post( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - body: String, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + body: String, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || html_post_validation(body)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - html_post_validation( - body, - ) - ).await.unwrap(); - - let Ok(( - body, - )) = validation else { - return Response::builder() + let Ok((body,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().html_post( - method, - host, - cookies, - body, - ).await; + let result = api_impl + .as_ref() + .html_post(method, host, cookies, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - HtmlPostResponse::Status200_Success - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + HtmlPostResponse::Status200_Success(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("text/html").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("text/html").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = body; + response.body(Body::from(body_content)) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = body; - response.body(Body::from(body_content)) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct PostYamlBodyValidator<'a> { - body: &'a String, - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct PostYamlBodyValidator<'a> { + body: &'a String, +} #[tracing::instrument(skip_all)] -fn post_yaml_validation( - body: String, -) -> std::result::Result<( - String, -), ValidationErrors> -{ - -Ok(( - body, -)) +fn post_yaml_validation(body: String) -> std::result::Result<(String,), ValidationErrors> { + Ok((body,)) } /// PostYaml - POST /post-yaml #[tracing::instrument(skip_all)] async fn post_yaml( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - body: String, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + body: String, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || post_yaml_validation(body)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - post_yaml_validation( - body, - ) - ).await.unwrap(); - - let Ok(( - body, - )) = validation else { - return Response::builder() + let Ok((body,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().post_yaml( - method, - host, - cookies, - body, - ).await; + let result = api_impl + .as_ref() + .post_yaml(method, host, cookies, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - PostYamlResponse::Status204_OK - => { + let resp = match result { + Ok(rsp) => match rsp { + PostYamlResponse::Status204_OK => { + let mut response = response.status(204); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(204); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[tracing::instrument(skip_all)] -fn raw_json_get_validation( -) -> std::result::Result<( -), ValidationErrors> -{ - -Ok(( -)) +fn raw_json_get_validation() -> std::result::Result<(), ValidationErrors> { + Ok(()) } /// RawJsonGet - GET /raw_json #[tracing::instrument(skip_all)] async fn raw_json_get( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || raw_json_get_validation()) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - raw_json_get_validation( - ) - ).await.unwrap(); - - let Ok(( - )) = validation else { - return Response::builder() + let Ok(()) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().raw_json_get( - method, - host, - cookies, - ).await; + let result = api_impl.as_ref().raw_json_get(method, host, cookies).await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - RawJsonGetResponse::Status200_Success - (body) - => { + let resp = match result { + Ok(rsp) => match rsp { + RawJsonGetResponse::Status200_Success(body) => { + let mut response = response.status(200); + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("*/*").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } - let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("*/*").map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR })?); - } + let body_content = tokio::task::spawn_blocking(move || { + serde_json::to_vec(&body).map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) + }) + .await + .unwrap()?; + response.body(Body::from(body_content)) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let body_content = tokio::task::spawn_blocking(move || - serde_json::to_vec(&body).map_err(|e| { - error!(error = ?e); - StatusCode::INTERNAL_SERVER_ERROR - })).await.unwrap()?; - response.body(Body::from(body_content)) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } - #[derive(validator::Validate)] - #[allow(dead_code)] - struct SoloObjectPostBodyValidator<'a> { - body: &'a crate::types::Object, - } - +#[derive(validator::Validate)] +#[allow(dead_code)] +struct SoloObjectPostBodyValidator<'a> { + body: &'a crate::types::Object, +} #[tracing::instrument(skip_all)] fn solo_object_post_validation( - body: crate::types::Object, -) -> std::result::Result<( - crate::types::Object, -), ValidationErrors> -{ - let b = SoloObjectPostBodyValidator { body: &body }; - b.validate()?; + body: crate::types::Object, +) -> std::result::Result<(crate::types::Object,), ValidationErrors> { + let b = SoloObjectPostBodyValidator { body: &body }; + b.validate()?; -Ok(( - body, -)) + Ok((body,)) } /// SoloObjectPost - POST /solo-object #[tracing::instrument(skip_all)] async fn solo_object_post( - method: Method, - host: Host, - cookies: CookieJar, - State(api_impl): State, - Json(body): Json, + method: Method, + host: Host, + cookies: CookieJar, + State(api_impl): State, + Json(body): Json, ) -> Result -where +where I: AsRef + Send + Sync, A: Api, { + #[allow(clippy::redundant_closure)] + let validation = tokio::task::spawn_blocking(move || solo_object_post_validation(body)) + .await + .unwrap(); - #[allow(clippy::redundant_closure)] - let validation = tokio::task::spawn_blocking(move || - solo_object_post_validation( - body, - ) - ).await.unwrap(); - - let Ok(( - body, - )) = validation else { - return Response::builder() + let Ok((body,)) = validation else { + return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) - .map_err(|_| StatusCode::BAD_REQUEST); - }; + .map_err(|_| StatusCode::BAD_REQUEST); + }; - let result = api_impl.as_ref().solo_object_post( - method, - host, - cookies, - body, - ).await; + let result = api_impl + .as_ref() + .solo_object_post(method, host, cookies, body) + .await; - let mut response = Response::builder(); + let mut response = Response::builder(); - let resp = match result { - Ok(rsp) => match rsp { - SoloObjectPostResponse::Status204_OK - => { + let resp = match result { + Ok(rsp) => match rsp { + SoloObjectPostResponse::Status204_OK => { + let mut response = response.status(204); + response.body(Body::empty()) + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + } + }; - let mut response = response.status(204); - response.body(Body::empty()) - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - }, - }; - - resp.map_err(|e| { error!(error = ?e); StatusCode::INTERNAL_SERVER_ERROR }) + resp.map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) } -