mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-11-23 03:53:44 +00:00
add exts alias to simply the templates (rust-server) (#22309)
This commit is contained in:
parent
c596bb7d8a
commit
81285b75e4
@ -265,6 +265,15 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
|
|||||||
private Map<String, CodegenProperty> requiredVarsMap;
|
private Map<String, CodegenProperty> requiredVarsMap;
|
||||||
private String ref;
|
private String ref;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An alias for vendor extensions, e.g. one can use {{exts.x-something}} for cleaner template
|
||||||
|
*
|
||||||
|
* @return vendor extensions
|
||||||
|
*/
|
||||||
|
public Map<String, Object> getExts() {
|
||||||
|
return vendorExtensions;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CodegenProperty getContains() {
|
public CodegenProperty getContains() {
|
||||||
return contains;
|
return contains;
|
||||||
@ -365,7 +374,6 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
|
|||||||
return discriminator == null ? null : discriminator.getPropertyName();
|
return discriminator == null ? null : discriminator.getPropertyName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPattern() {
|
public String getPattern() {
|
||||||
return pattern;
|
return pattern;
|
||||||
|
|||||||
@ -79,6 +79,15 @@ public class CodegenOperation {
|
|||||||
return params != null && !params.isEmpty();
|
return params != null && !params.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An alias for vendor extensions, e.g. one can use {{exts.x-something}} for cleaner template
|
||||||
|
*
|
||||||
|
* @return vendor extensions
|
||||||
|
*/
|
||||||
|
public Map<String, Object> getExts() {
|
||||||
|
return vendorExtensions;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if there's at least one parameter
|
* Check if there's at least one parameter
|
||||||
*
|
*
|
||||||
|
|||||||
@ -534,6 +534,15 @@ public class CodegenParameter implements IJsonSchemaValidationProperties {
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An alias for vendor extensions, e.g. one can use {{exts.x-something}} for cleaner template
|
||||||
|
*
|
||||||
|
* @return vendor extensions
|
||||||
|
*/
|
||||||
|
public Map<String, Object> getExts() {
|
||||||
|
return vendorExtensions;
|
||||||
|
}
|
||||||
|
|
||||||
// use schema.getContains or content.mediaType.schema.getContains instead of this
|
// use schema.getContains or content.mediaType.schema.getContains instead of this
|
||||||
@Override
|
@Override
|
||||||
public CodegenProperty getContains() {
|
public CodegenProperty getContains() {
|
||||||
|
|||||||
@ -436,6 +436,15 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti
|
|||||||
return !getRequired() || isNullable;
|
return !getRequired() || isNullable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An alias for vendor extensions, e.g. one can use {{exts.x-something}} for cleaner template
|
||||||
|
*
|
||||||
|
* @return vendor extensions
|
||||||
|
*/
|
||||||
|
public Map<String, Object> getExts() {
|
||||||
|
return vendorExtensions;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CodegenProperty getItems() {
|
public CodegenProperty getItems() {
|
||||||
return items;
|
return items;
|
||||||
|
|||||||
@ -206,6 +206,15 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An alias for vendor extensions, e.g. one can use {{exts.x-something}} for cleaner template
|
||||||
|
*
|
||||||
|
* @return vendor extensions
|
||||||
|
*/
|
||||||
|
public Map<String, Object> getExts() {
|
||||||
|
return vendorExtensions;
|
||||||
|
}
|
||||||
|
|
||||||
// use content.mediaType.schema.getContains instead of this
|
// use content.mediaType.schema.getContains instead of this
|
||||||
@Override
|
@Override
|
||||||
public CodegenProperty getContains() {
|
public CodegenProperty getContains() {
|
||||||
|
|||||||
@ -38,4 +38,13 @@ public class CodegenServer {
|
|||||||
sb.append('}');
|
sb.append('}');
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An alias for vendor extensions, e.g. one can use {{exts.x-something}} for cleaner template
|
||||||
|
*
|
||||||
|
* @return vendor extensions
|
||||||
|
*/
|
||||||
|
public Map<String, Object> getExts() {
|
||||||
|
return vendorExtensions;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -95,11 +95,11 @@ To run a client, follow one of the following simple steps:
|
|||||||
{{#apis}}
|
{{#apis}}
|
||||||
{{#operations}}
|
{{#operations}}
|
||||||
{{#operation}}
|
{{#operation}}
|
||||||
{{#vendorExtensions}}
|
{{#exts}}
|
||||||
{{^x-no-client-example}}
|
{{^x-no-client-example}}
|
||||||
cargo run --example client {{{operationId}}}
|
cargo run --example client {{{operationId}}}
|
||||||
{{/x-no-client-example}}
|
{{/x-no-client-example}}
|
||||||
{{/vendorExtensions}}
|
{{/exts}}
|
||||||
{{/operation}}
|
{{/operation}}
|
||||||
{{/operations}}
|
{{/operations}}
|
||||||
{{/apis}}
|
{{/apis}}
|
||||||
|
|||||||
@ -113,12 +113,12 @@ enum Operation {
|
|||||||
{{/isBinary}}
|
{{/isBinary}}
|
||||||
{{#isBoolean}}
|
{{#isBoolean}}
|
||||||
{{#isPrimitiveType}}
|
{{#isPrimitiveType}}
|
||||||
{{#vendorExtensions.x-provide-cli-short-opt}}
|
{{#exts.x-provide-cli-short-opt}}
|
||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
{{/vendorExtensions.x-provide-cli-short-opt}}
|
{{/exts.x-provide-cli-short-opt}}
|
||||||
{{^vendorExtensions.x-provide-cli-short-opt}}
|
{{^exts.x-provide-cli-short-opt}}
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
{{/vendorExtensions.x-provide-cli-short-opt}}
|
{{/exts.x-provide-cli-short-opt}}
|
||||||
{{/isPrimitiveType}}
|
{{/isPrimitiveType}}
|
||||||
{{/isBoolean}}
|
{{/isBoolean}}
|
||||||
{{{paramName}}}: {{^required}}Option<{{/required}}{{{dataType}}}{{^required}}>{{/required}},
|
{{{paramName}}}: {{^required}}Option<{{/required}}{{{dataType}}}{{^required}}>{{/required}},
|
||||||
@ -216,9 +216,9 @@ async fn main() -> Result<()> {
|
|||||||
{{paramName}},
|
{{paramName}},
|
||||||
{{/allParams}}
|
{{/allParams}}
|
||||||
} => {
|
} => {
|
||||||
{{#vendorExtensions.x-is-delete}}
|
{{#exts.x-is-delete}}
|
||||||
prompt(args.force, "This will delete the given entry, are you sure?")?;
|
prompt(args.force, "This will delete the given entry, are you sure?")?;
|
||||||
{{/vendorExtensions.x-is-delete}}
|
{{/exts.x-is-delete}}
|
||||||
info!("Performing a {{operationId}} request{{^pathParams}}");{{/pathParams}}{{#pathParams}}{{#-first}} on {:?}", ({{/-first}}{{/pathParams}}
|
info!("Performing a {{operationId}} request{{^pathParams}}");{{/pathParams}}{{#pathParams}}{{#-first}} on {:?}", ({{/-first}}{{/pathParams}}
|
||||||
{{#pathParams}}
|
{{#pathParams}}
|
||||||
&{{paramName}}{{^-last}},{{/-last}}
|
&{{paramName}}{{^-last}},{{/-last}}
|
||||||
@ -227,7 +227,7 @@ async fn main() -> Result<()> {
|
|||||||
{{/-last}}
|
{{/-last}}
|
||||||
{{/pathParams}}
|
{{/pathParams}}
|
||||||
|
|
||||||
let result = client.{{{vendorExtensions.x-operation-id}}}(
|
let result = client.{{{exts.x-operation-id}}}(
|
||||||
{{#allParams}}
|
{{#allParams}}
|
||||||
{{{paramName}}}{{#isArray}}.as_ref(){{/isArray}},
|
{{{paramName}}}{{#isArray}}.as_ref(){{/isArray}},
|
||||||
{{/allParams}}
|
{{/allParams}}
|
||||||
@ -236,7 +236,7 @@ async fn main() -> Result<()> {
|
|||||||
|
|
||||||
match result {
|
match result {
|
||||||
{{#responses}}
|
{{#responses}}
|
||||||
{{{operationId}}}Response::{{{vendorExtensions.x-response-id}}}
|
{{{operationId}}}Response::{{{exts.x-response-id}}}
|
||||||
{{#dataType}}
|
{{#dataType}}
|
||||||
{{^hasHeaders}}
|
{{^hasHeaders}}
|
||||||
(body)
|
(body)
|
||||||
@ -257,7 +257,7 @@ async fn main() -> Result<()> {
|
|||||||
}
|
}
|
||||||
{{/-last}}
|
{{/-last}}
|
||||||
{{/headers}}
|
{{/headers}}
|
||||||
=> "{{{vendorExtensions.x-response-id}}}\n".to_string()
|
=> "{{{exts.x-response-id}}}\n".to_string()
|
||||||
{{#dataType}}
|
{{#dataType}}
|
||||||
+
|
+
|
||||||
{{/dataType}}
|
{{/dataType}}
|
||||||
|
|||||||
@ -63,7 +63,7 @@ impl<T> RequestParser<T> for ApiRequestParser {
|
|||||||
{{#urls}}
|
{{#urls}}
|
||||||
{{#requests}}
|
{{#requests}}
|
||||||
// {{{operationId}}} - {{{httpMethod}}} {{{path}}}
|
// {{{operationId}}} - {{{httpMethod}}} {{{path}}}
|
||||||
hyper::Method::{{{vendorExtensions.x-http-method}}} if path.matched(paths::ID_{{{vendorExtensions.x-path-id}}}) => Some("{{{operationId}}}"),
|
hyper::Method::{{{exts.x-http-method}}} if path.matched(paths::ID_{{{exts.x-path-id}}}) => Some("{{{operationId}}}"),
|
||||||
{{/requests}}
|
{{/requests}}
|
||||||
{{/urls}}
|
{{/urls}}
|
||||||
{{/callbacks}}
|
{{/callbacks}}
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
#[allow(clippy::vec_init_then_push)]
|
#[allow(clippy::vec_init_then_push)]
|
||||||
async fn {{#vendorExtensions}}{{{x-operation-id}}}{{/vendorExtensions}}(
|
async fn {{#exts}}{{{x-operation-id}}}{{/exts}}(
|
||||||
&self,
|
&self,
|
||||||
{{#vendorExtensions}}
|
{{#exts}}
|
||||||
{{#x-callback-params}}
|
{{#x-callback-params}}
|
||||||
callback_{{.}}: String,
|
callback_{{.}}: String,
|
||||||
{{/x-callback-params}}
|
{{/x-callback-params}}
|
||||||
{{/vendorExtensions}}
|
{{/exts}}
|
||||||
{{#allParams}}
|
{{#allParams}}
|
||||||
param_{{{paramName}}}: {{^required}}Option<{{/required}}{{#isArray}}&{{/isArray}}{{{dataType}}}{{^required}}>{{/required}},
|
param_{{{paramName}}}: {{^required}}Option<{{/required}}{{#isArray}}&{{/isArray}}{{{dataType}}}{{^required}}>{{/required}},
|
||||||
{{/allParams}}
|
{{/allParams}}
|
||||||
@ -15,20 +15,20 @@
|
|||||||
#[allow(clippy::uninlined_format_args)]
|
#[allow(clippy::uninlined_format_args)]
|
||||||
let mut uri = format!(
|
let mut uri = format!(
|
||||||
{{#isCallbackRequest}}
|
{{#isCallbackRequest}}
|
||||||
"{{vendorExtensions.x-path-format-string}}"
|
"{{exts.x-path-format-string}}"
|
||||||
{{/isCallbackRequest}}
|
{{/isCallbackRequest}}
|
||||||
{{^isCallbackRequest}}
|
{{^isCallbackRequest}}
|
||||||
"{}{{^servers}}{{{basePathWithoutHost}}}{{/servers}}{{#servers.0}}{{{url}}}{{/servers.0}}{{vendorExtensions.x-path-format-string}}",
|
"{}{{^servers}}{{{basePathWithoutHost}}}{{/servers}}{{#servers.0}}{{{url}}}{{/servers.0}}{{exts.x-path-format-string}}",
|
||||||
self.base_path
|
self.base_path
|
||||||
{{/isCallbackRequest}}
|
{{/isCallbackRequest}}
|
||||||
{{#pathParams}}
|
{{#pathParams}}
|
||||||
,{{{paramName}}}=utf8_percent_encode(¶m_{{{paramName}}}.to_string(), ID_ENCODE_SET)
|
,{{{paramName}}}=utf8_percent_encode(¶m_{{{paramName}}}.to_string(), ID_ENCODE_SET)
|
||||||
{{/pathParams}}
|
{{/pathParams}}
|
||||||
{{#vendorExtensions}}
|
{{#exts}}
|
||||||
{{#x-callback-params}}
|
{{#x-callback-params}}
|
||||||
,{{.}}=callback_{{.}}
|
,{{.}}=callback_{{.}}
|
||||||
{{/x-callback-params}}
|
{{/x-callback-params}}
|
||||||
{{/vendorExtensions}}
|
{{/exts}}
|
||||||
);
|
);
|
||||||
|
|
||||||
// Query parameters
|
// Query parameters
|
||||||
@ -39,7 +39,7 @@
|
|||||||
if let Some(param_{{{paramName}}}) = param_{{{paramName}}} {
|
if let Some(param_{{{paramName}}}) = param_{{{paramName}}} {
|
||||||
{{/required}}
|
{{/required}}
|
||||||
query_string.append_pair("{{{baseName}}}",
|
query_string.append_pair("{{{baseName}}}",
|
||||||
{{#vendorExtensions}}
|
{{#exts}}
|
||||||
{{#x-consumes-json}}
|
{{#x-consumes-json}}
|
||||||
&match serde_json::to_string(¶m_{{{paramName}}}) {
|
&match serde_json::to_string(¶m_{{{paramName}}}) {
|
||||||
Ok(str) => str,
|
Ok(str) => str,
|
||||||
@ -54,7 +54,7 @@
|
|||||||
¶m_{{{paramName}}}{{^isString}}.to_string(){{/isString}});
|
¶m_{{{paramName}}}{{^isString}}.to_string(){{/isString}});
|
||||||
{{/isArray}}
|
{{/isArray}}
|
||||||
{{/x-consumes-json}}
|
{{/x-consumes-json}}
|
||||||
{{/vendorExtensions}}
|
{{/exts}}
|
||||||
{{^required}}
|
{{^required}}
|
||||||
}
|
}
|
||||||
{{/required}}
|
{{/required}}
|
||||||
@ -81,7 +81,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mut request = match Request::builder()
|
let mut request = match Request::builder()
|
||||||
.method("{{{vendorExtensions.x-http-method}}}")
|
.method("{{{exts.x-http-method}}}")
|
||||||
.uri(uri)
|
.uri(uri)
|
||||||
.body(BoxBody::new(http_body_util::Empty::new())) {
|
.body(BoxBody::new(http_body_util::Empty::new())) {
|
||||||
Ok(req) => req,
|
Ok(req) => req,
|
||||||
@ -214,7 +214,7 @@
|
|||||||
{{>client-response-body-instance}}
|
{{>client-response-body-instance}}
|
||||||
|
|
||||||
|
|
||||||
Ok({{{operationId}}}Response::{{#vendorExtensions}}{{x-response-id}}{{/vendorExtensions}}
|
Ok({{{operationId}}}Response::{{#exts}}{{x-response-id}}{{/exts}}
|
||||||
{{^headers}}
|
{{^headers}}
|
||||||
(body)
|
(body)
|
||||||
{{/headers}}
|
{{/headers}}
|
||||||
@ -232,7 +232,7 @@
|
|||||||
{{/dataType}}
|
{{/dataType}}
|
||||||
{{^dataType}}
|
{{^dataType}}
|
||||||
Ok(
|
Ok(
|
||||||
{{{operationId}}}Response::{{#vendorExtensions}}{{x-response-id}}{{/vendorExtensions}}
|
{{{operationId}}}Response::{{#exts}}{{x-response-id}}{{/exts}}
|
||||||
{{#headers}}
|
{{#headers}}
|
||||||
{{#-first}}
|
{{#-first}}
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
{{#vendorExtensions}}
|
{{#exts}}
|
||||||
{{#x-consumes-multipart-form}}
|
{{#x-consumes-multipart-form}}
|
||||||
|
|
||||||
// Consumes multipart/form body
|
// Consumes multipart/form body
|
||||||
@ -42,7 +42,7 @@
|
|||||||
#[allow(clippy::uninlined_format_args)]
|
#[allow(clippy::uninlined_format_args)]
|
||||||
params.push(("{{{baseName}}}",
|
params.push(("{{{baseName}}}",
|
||||||
{{^isString}}
|
{{^isString}}
|
||||||
format!("{{{vendorExtensions.x-format-string}}}", param_{{{paramName}}})
|
format!("{{{exts.x-format-string}}}", param_{{{paramName}}})
|
||||||
{{/isString}}
|
{{/isString}}
|
||||||
{{#isString}}
|
{{#isString}}
|
||||||
{{#isArray}}
|
{{#isArray}}
|
||||||
@ -78,7 +78,7 @@
|
|||||||
{{^required}}
|
{{^required}}
|
||||||
if let Some(param_{{{paramName}}}) = param_{{{paramName}}} {
|
if let Some(param_{{{paramName}}}) = param_{{{paramName}}} {
|
||||||
{{/required}}
|
{{/required}}
|
||||||
{{#vendorExtensions}}
|
{{#exts}}
|
||||||
{{#x-consumes-plain-text}}
|
{{#x-consumes-plain-text}}
|
||||||
{{#isByteArray}}
|
{{#isByteArray}}
|
||||||
let body = String::from_utf8(param_body.0).expect("Body was not valid UTF8");
|
let body = String::from_utf8(param_body.0).expect("Body was not valid UTF8");
|
||||||
@ -93,7 +93,7 @@
|
|||||||
{{#x-consumes-json}}
|
{{#x-consumes-json}}
|
||||||
let body = serde_json::to_string(¶m_{{{paramName}}}).expect("impossible to fail to serialize");
|
let body = serde_json::to_string(¶m_{{{paramName}}}).expect("impossible to fail to serialize");
|
||||||
{{/x-consumes-json}}
|
{{/x-consumes-json}}
|
||||||
{{/vendorExtensions}}
|
{{/exts}}
|
||||||
*request.body_mut() = body_from_string(body);
|
*request.body_mut() = body_from_string(body);
|
||||||
{{^required}}
|
{{^required}}
|
||||||
}
|
}
|
||||||
@ -103,4 +103,4 @@
|
|||||||
request.headers_mut().insert(CONTENT_TYPE, HeaderValue::from_static(header));
|
request.headers_mut().insert(CONTENT_TYPE, HeaderValue::from_static(header));
|
||||||
{{/bodyParam}}
|
{{/bodyParam}}
|
||||||
{{/x-consumes-basic}}
|
{{/x-consumes-basic}}
|
||||||
{{/vendorExtensions}}
|
{{/exts}}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
let (body_string, multipart_header) = {
|
let (body_string, multipart_header) = {
|
||||||
let mut multipart = Multipart::new();
|
let mut multipart = Multipart::new();
|
||||||
|
|
||||||
{{#vendorExtensions}}
|
{{#exts}}
|
||||||
{{#formParams}}
|
{{#formParams}}
|
||||||
{{#-first}}
|
{{#-first}}
|
||||||
// For each parameter, encode as appropriate and add to the multipart body as a stream.
|
// For each parameter, encode as appropriate and add to the multipart body as a stream.
|
||||||
@ -36,7 +36,7 @@
|
|||||||
multipart.add_stream("{{{paramName}}}", {{{paramName}}}_cursor, filename, Some({{{paramName}}}_mime));
|
multipart.add_stream("{{{paramName}}}", {{{paramName}}}_cursor, filename, Some({{{paramName}}}_mime));
|
||||||
{{/isByteArray}}
|
{{/isByteArray}}
|
||||||
{{/formParams}}
|
{{/formParams}}
|
||||||
{{/vendorExtensions}}
|
{{/exts}}
|
||||||
|
|
||||||
let mut fields = match multipart.prepare() {
|
let mut fields = match multipart.prepare() {
|
||||||
Ok(fields) => fields,
|
Ok(fields) => fields,
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
{{#vendorExtensions}}
|
{{#exts}}
|
||||||
{{#x-produces-bytes}}
|
{{#x-produces-bytes}}
|
||||||
let body = swagger::ByteArray(body.to_vec());
|
let body = swagger::ByteArray(body.to_vec());
|
||||||
{{/x-produces-bytes}}
|
{{/x-produces-bytes}}
|
||||||
@ -19,4 +19,4 @@
|
|||||||
let body = body.to_string();
|
let body = body.to_string();
|
||||||
{{/x-produces-plain-text}}
|
{{/x-produces-plain-text}}
|
||||||
{{/x-produces-bytes}}
|
{{/x-produces-bytes}}
|
||||||
{{/vendorExtensions}}
|
{{/exts}}
|
||||||
|
|||||||
@ -67,10 +67,10 @@ let param_{{{paramName}}} = match param_{{{paramName}}} {
|
|||||||
};
|
};
|
||||||
{{/required}}
|
{{/required}}
|
||||||
{{/formParams}}
|
{{/formParams}}
|
||||||
{{^vendorExtensions.x-consumes-basic}}
|
{{^exts.x-consumes-basic}}
|
||||||
let body = {{{dataType}}} {
|
let body = {{{dataType}}} {
|
||||||
{{#formParams}}
|
{{#formParams}}
|
||||||
{{{paramName}}}: param_{{{paramName}}},
|
{{{paramName}}}: param_{{{paramName}}},
|
||||||
{{/formParams}}
|
{{/formParams}}
|
||||||
};
|
};
|
||||||
{{/vendorExtensions.x-consumes-basic}}
|
{{/exts.x-consumes-basic}}
|
||||||
|
|||||||
@ -142,7 +142,7 @@ impl<T, A, B, C, ReqBody> Service<Request<ReqBody>> for AddContext<T, A>
|
|||||||
{
|
{
|
||||||
use swagger::auth::api_key_from_header;
|
use swagger::auth::api_key_from_header;
|
||||||
|
|
||||||
if let Some(header) = api_key_from_header(headers, "{{vendorExtensions.x-key-param-name-lower}}") {
|
if let Some(header) = api_key_from_header(headers, "{{exts.x-key-param-name-lower}}") {
|
||||||
let auth_data = AuthData::ApiKey(header);
|
let auth_data = AuthData::ApiKey(header);
|
||||||
let context = context.push(Some(auth_data));
|
let context = context.push(Some(auth_data));
|
||||||
|
|
||||||
|
|||||||
@ -140,24 +140,24 @@ fn main() {
|
|||||||
{{#apis}}
|
{{#apis}}
|
||||||
{{#operations}}
|
{{#operations}}
|
||||||
{{#operation}}
|
{{#operation}}
|
||||||
{{#vendorExtensions}}
|
{{#exts}}
|
||||||
{{#x-no-client-example}}
|
{{#x-no-client-example}}
|
||||||
/* Disabled because there's no example.
|
/* Disabled because there's no example.
|
||||||
{{/x-no-client-example}}
|
{{/x-no-client-example}}
|
||||||
{{/vendorExtensions}}
|
{{/exts}}
|
||||||
Some("{{{operationId}}}") => {
|
Some("{{{operationId}}}") => {
|
||||||
let result = rt.block_on(client.{{{vendorExtensions.x-operation-id}}}(
|
let result = rt.block_on(client.{{{exts.x-operation-id}}}(
|
||||||
{{#allParams}}
|
{{#allParams}}
|
||||||
{{{vendorExtensions.x-example}}}{{^-last}},{{/-last}}
|
{{{exts.x-example}}}{{^-last}},{{/-last}}
|
||||||
{{/allParams}}
|
{{/allParams}}
|
||||||
));
|
));
|
||||||
info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has<XSpanIdString>).get().clone());
|
info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has<XSpanIdString>).get().clone());
|
||||||
},
|
},
|
||||||
{{#vendorExtensions}}
|
{{#exts}}
|
||||||
{{#x-no-client-example}}
|
{{#x-no-client-example}}
|
||||||
*/
|
*/
|
||||||
{{/x-no-client-example}}
|
{{/x-no-client-example}}
|
||||||
{{/vendorExtensions}}
|
{{/exts}}
|
||||||
{{/operation}}
|
{{/operation}}
|
||||||
{{/operations}}
|
{{/operations}}
|
||||||
{{/apis}}
|
{{/apis}}
|
||||||
|
|||||||
@ -1,18 +1,18 @@
|
|||||||
{{#summary}}
|
{{#summary}}
|
||||||
/// {{{.}}}
|
/// {{{.}}}
|
||||||
{{/summary}}
|
{{/summary}}
|
||||||
async fn {{#vendorExtensions}}{{{x-operation-id}}}{{/vendorExtensions}}(
|
async fn {{#exts}}{{{x-operation-id}}}{{/exts}}(
|
||||||
&self,
|
&self,
|
||||||
{{#vendorExtensions}}
|
{{#exts}}
|
||||||
{{#x-callback-params}}
|
{{#x-callback-params}}
|
||||||
callback_{{.}}: String,
|
callback_{{.}}: String,
|
||||||
{{/x-callback-params}}
|
{{/x-callback-params}}
|
||||||
{{/vendorExtensions}}
|
{{/exts}}
|
||||||
{{#allParams}}
|
{{#allParams}}
|
||||||
{{{paramName}}}: {{^required}}Option<{{/required}}{{#isArray}}&{{/isArray}}{{{dataType}}}{{^required}}>{{/required}},
|
{{{paramName}}}: {{^required}}Option<{{/required}}{{#isArray}}&{{/isArray}}{{{dataType}}}{{^required}}>{{/required}},
|
||||||
{{/allParams}}
|
{{/allParams}}
|
||||||
context: &C) -> Result<{{{operationId}}}Response, ApiError>
|
context: &C) -> Result<{{{operationId}}}Response, ApiError>
|
||||||
{
|
{
|
||||||
info!("{{#vendorExtensions}}{{{x-operation-id}}}{{/vendorExtensions}}({{#allParams}}{{#vendorExtensions}}{{{x-format-string}}}{{/vendorExtensions}}{{^-last}}, {{/-last}}{{/allParams}}) - X-Span-ID: {:?}"{{#allParams}}, {{{paramName}}}{{/allParams}}, context.get().0.clone());
|
info!("{{#exts}}{{{x-operation-id}}}{{/exts}}({{#allParams}}{{#exts}}{{{x-format-string}}}{{/exts}}{{^-last}}, {{/-last}}{{/allParams}}) - X-Span-ID: {:?}"{{#allParams}}, {{{paramName}}}{{/allParams}}, context.get().0.clone());
|
||||||
Err(ApiError("Api-Error: Operation is NOT implemented".into()))
|
Err(ApiError("Api-Error: Operation is NOT implemented".into()))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,7 +43,7 @@ pub trait Api<C: Send + Sync> {
|
|||||||
{{#summary}}
|
{{#summary}}
|
||||||
/// {{{.}}}
|
/// {{{.}}}
|
||||||
{{/summary}}
|
{{/summary}}
|
||||||
async fn {{#vendorExtensions}}{{{x-operation-id}}}{{/vendorExtensions}}(
|
async fn {{#exts}}{{{x-operation-id}}}{{/exts}}(
|
||||||
&self,
|
&self,
|
||||||
{{#allParams}}
|
{{#allParams}}
|
||||||
{{{paramName}}}: {{^required}}Option<{{/required}}{{#isArray}}&{{/isArray}}{{{dataType}}}{{^required}}>{{/required}},
|
{{{paramName}}}: {{^required}}Option<{{/required}}{{#isArray}}&{{/isArray}}{{{dataType}}}{{^required}}>{{/required}},
|
||||||
@ -70,7 +70,7 @@ pub trait ApiNoContext<C: Send + Sync> {
|
|||||||
{{#summary}}
|
{{#summary}}
|
||||||
/// {{{.}}}
|
/// {{{.}}}
|
||||||
{{/summary}}
|
{{/summary}}
|
||||||
async fn {{#vendorExtensions}}{{{x-operation-id}}}{{/vendorExtensions}}(
|
async fn {{#exts}}{{{x-operation-id}}}{{/exts}}(
|
||||||
&self,
|
&self,
|
||||||
{{#allParams}}
|
{{#allParams}}
|
||||||
{{{paramName}}}: {{^required}}Option<{{/required}}{{#isArray}}&{{/isArray}}{{{dataType}}}{{^required}}>{{/required}},
|
{{{paramName}}}: {{^required}}Option<{{/required}}{{#isArray}}&{{/isArray}}{{{dataType}}}{{^required}}>{{/required}},
|
||||||
@ -109,7 +109,7 @@ impl<T: Api<C> + Send + Sync, C: Clone + Send + Sync> ApiNoContext<C> for Contex
|
|||||||
{{#summary}}
|
{{#summary}}
|
||||||
/// {{{.}}}
|
/// {{{.}}}
|
||||||
{{/summary}}
|
{{/summary}}
|
||||||
async fn {{#vendorExtensions}}{{{x-operation-id}}}{{/vendorExtensions}}(
|
async fn {{#exts}}{{{x-operation-id}}}{{/exts}}(
|
||||||
&self,
|
&self,
|
||||||
{{#allParams}}
|
{{#allParams}}
|
||||||
{{{paramName}}}: {{^required}}Option<{{/required}}{{#isArray}}&{{/isArray}}{{{dataType}}}{{^required}}>{{/required}},
|
{{{paramName}}}: {{^required}}Option<{{/required}}{{#isArray}}&{{/isArray}}{{{dataType}}}{{^required}}>{{/required}},
|
||||||
@ -117,7 +117,7 @@ impl<T: Api<C> + Send + Sync, C: Clone + Send + Sync> ApiNoContext<C> for Contex
|
|||||||
) -> Result<{{{operationId}}}Response, ApiError>
|
) -> Result<{{{operationId}}}Response, ApiError>
|
||||||
{
|
{
|
||||||
let context = self.context().clone();
|
let context = self.context().clone();
|
||||||
self.api().{{#vendorExtensions}}{{{x-operation-id}}}{{/vendorExtensions}}({{#allParams}}{{{paramName}}}, {{/allParams}}&context).await
|
self.api().{{#exts}}{{{x-operation-id}}}{{/exts}}({{#allParams}}{{{paramName}}}, {{/allParams}}&context).await
|
||||||
}
|
}
|
||||||
|
|
||||||
{{/operation}}
|
{{/operation}}
|
||||||
@ -159,13 +159,13 @@ pub trait CallbackApi<C: Send + Sync> {
|
|||||||
{{#summary}}
|
{{#summary}}
|
||||||
/// {{{.}}}
|
/// {{{.}}}
|
||||||
{{/summary}}
|
{{/summary}}
|
||||||
async fn {{#vendorExtensions}}{{{x-operation-id}}}{{/vendorExtensions}}(
|
async fn {{#exts}}{{{x-operation-id}}}{{/exts}}(
|
||||||
&self,
|
&self,
|
||||||
{{#vendorExtensions}}
|
{{#exts}}
|
||||||
{{#x-callback-params}}
|
{{#x-callback-params}}
|
||||||
callback_{{.}}: String,
|
callback_{{.}}: String,
|
||||||
{{/x-callback-params}}
|
{{/x-callback-params}}
|
||||||
{{/vendorExtensions}}
|
{{/exts}}
|
||||||
{{#allParams}}
|
{{#allParams}}
|
||||||
{{{paramName}}}: {{^required}}Option<{{/required}}{{#isArray}}&{{/isArray}}{{{dataType}}}{{^required}}>{{/required}},
|
{{{paramName}}}: {{^required}}Option<{{/required}}{{#isArray}}&{{/isArray}}{{{dataType}}}{{^required}}>{{/required}},
|
||||||
{{/allParams}}
|
{{/allParams}}
|
||||||
@ -196,13 +196,13 @@ pub trait CallbackApiNoContext<C: Send + Sync> {
|
|||||||
{{#summary}}
|
{{#summary}}
|
||||||
/// {{{.}}}
|
/// {{{.}}}
|
||||||
{{/summary}}
|
{{/summary}}
|
||||||
async fn {{#vendorExtensions}}{{{x-operation-id}}}{{/vendorExtensions}}(
|
async fn {{#exts}}{{{x-operation-id}}}{{/exts}}(
|
||||||
&self,
|
&self,
|
||||||
{{#vendorExtensions}}
|
{{#exts}}
|
||||||
{{#x-callback-params}}
|
{{#x-callback-params}}
|
||||||
callback_{{.}}: String,
|
callback_{{.}}: String,
|
||||||
{{/x-callback-params}}
|
{{/x-callback-params}}
|
||||||
{{/vendorExtensions}}
|
{{/exts}}
|
||||||
{{#allParams}}
|
{{#allParams}}
|
||||||
{{{paramName}}}: {{^required}}Option<{{/required}}{{#isArray}}&{{/isArray}}{{{dataType}}}{{^required}}>{{/required}},
|
{{{paramName}}}: {{^required}}Option<{{/required}}{{#isArray}}&{{/isArray}}{{{dataType}}}{{^required}}>{{/required}},
|
||||||
{{/allParams}}
|
{{/allParams}}
|
||||||
@ -246,25 +246,25 @@ impl<T: CallbackApi<C> + Send + Sync, C: Clone + Send + Sync> CallbackApiNoConte
|
|||||||
{{#summary}}
|
{{#summary}}
|
||||||
/// {{{.}}}
|
/// {{{.}}}
|
||||||
{{/summary}}
|
{{/summary}}
|
||||||
async fn {{#vendorExtensions}}{{{x-operation-id}}}{{/vendorExtensions}}(
|
async fn {{#exts}}{{{x-operation-id}}}{{/exts}}(
|
||||||
&self,
|
&self,
|
||||||
{{#vendorExtensions}}
|
{{#exts}}
|
||||||
{{#x-callback-params}}
|
{{#x-callback-params}}
|
||||||
callback_{{.}}: String,
|
callback_{{.}}: String,
|
||||||
{{/x-callback-params}}
|
{{/x-callback-params}}
|
||||||
{{/vendorExtensions}}
|
{{/exts}}
|
||||||
{{#allParams}}
|
{{#allParams}}
|
||||||
{{{paramName}}}: {{^required}}Option<{{/required}}{{#isArray}}&{{/isArray}}{{{dataType}}}{{^required}}>{{/required}},
|
{{{paramName}}}: {{^required}}Option<{{/required}}{{#isArray}}&{{/isArray}}{{{dataType}}}{{^required}}>{{/required}},
|
||||||
{{/allParams}}
|
{{/allParams}}
|
||||||
) -> Result<{{{operationId}}}Response, ApiError>
|
) -> Result<{{{operationId}}}Response, ApiError>
|
||||||
{
|
{
|
||||||
let context = self.context().clone();
|
let context = self.context().clone();
|
||||||
self.api().{{#vendorExtensions}}{{{x-operation-id}}}{{/vendorExtensions}}(
|
self.api().{{#exts}}{{{x-operation-id}}}{{/exts}}(
|
||||||
{{#vendorExtensions}}
|
{{#exts}}
|
||||||
{{#x-callback-params}}
|
{{#x-callback-params}}
|
||||||
callback_{{.}},
|
callback_{{.}},
|
||||||
{{/x-callback-params}}
|
{{/x-callback-params}}
|
||||||
{{/vendorExtensions}}
|
{{/exts}}
|
||||||
{{#allParams}}
|
{{#allParams}}
|
||||||
{{{paramName}}},
|
{{{paramName}}},
|
||||||
{{/allParams}}
|
{{/allParams}}
|
||||||
|
|||||||
@ -59,7 +59,7 @@ impl std::str::FromStr for {{{classname}}} {
|
|||||||
{{/isEnum}}
|
{{/isEnum}}
|
||||||
{{^isEnum}}
|
{{^isEnum}}
|
||||||
{{#dataType}}
|
{{#dataType}}
|
||||||
#[derive(Debug, Clone, PartialEq, {{#vendorExtensions.x-partial-ord}}PartialOrd, {{/vendorExtensions.x-partial-ord}}serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, PartialEq, {{#exts.x-partial-ord}}PartialOrd, {{/exts.x-partial-ord}}serde::Serialize, serde::Deserialize)]
|
||||||
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
|
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
|
||||||
{{#xmlName}}
|
{{#xmlName}}
|
||||||
#[serde(rename = "{{{.}}}")]
|
#[serde(rename = "{{{.}}}")]
|
||||||
@ -91,8 +91,8 @@ impl std::ops::DerefMut for {{{classname}}} {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{{#vendorExtensions.x-to-string-support}}
|
{{#exts.x-to-string-support}}
|
||||||
{{#vendorExtensions.x-is-string}}
|
{{#exts.x-is-string}}
|
||||||
impl std::fmt::Display for {{{classname}}} {
|
impl std::fmt::Display for {{{classname}}} {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
write!(f, "{}", self.0.clone())
|
write!(f, "{}", self.0.clone())
|
||||||
@ -105,8 +105,8 @@ impl std::str::FromStr for {{{classname}}} {
|
|||||||
std::result::Result::Ok({{{classname}}}(x.to_owned()))
|
std::result::Result::Ok({{{classname}}}(x.to_owned()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{/vendorExtensions.x-is-string}}
|
{{/exts.x-is-string}}
|
||||||
{{^vendorExtensions.x-is-string}}
|
{{^exts.x-is-string}}
|
||||||
/// Converts the {{{classname}}} value to the Query Parameters representation (style=form, explode=false)
|
/// Converts the {{{classname}}} value to the Query Parameters representation (style=form, explode=false)
|
||||||
/// specified in <https://swagger.io/docs/specification/serialization/>
|
/// specified in <https://swagger.io/docs/specification/serialization/>
|
||||||
/// Should be implemented in a serde serializer
|
/// Should be implemented in a serde serializer
|
||||||
@ -129,9 +129,9 @@ impl ::std::str::FromStr for {{{classname}}} {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{/vendorExtensions.x-is-string}}
|
{{/exts.x-is-string}}
|
||||||
{{/vendorExtensions.x-to-string-support}}
|
{{/exts.x-to-string-support}}
|
||||||
{{^vendorExtensions.x-to-string-support}}
|
{{^exts.x-to-string-support}}
|
||||||
/// Converts the {{{classname}}} value to the Query Parameters representation (style=form, explode=false)
|
/// Converts the {{{classname}}} value to the Query Parameters representation (style=form, explode=false)
|
||||||
/// specified in <https://swagger.io/docs/specification/serialization/>
|
/// specified in <https://swagger.io/docs/specification/serialization/>
|
||||||
/// Should be implemented in a serde serializer
|
/// Should be implemented in a serde serializer
|
||||||
@ -152,11 +152,11 @@ impl ::std::str::FromStr for {{{classname}}} {
|
|||||||
std::result::Result::Err("Parsing {{{classname}}} is not supported")
|
std::result::Result::Err("Parsing {{{classname}}} is not supported")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{/vendorExtensions.x-to-string-support}}
|
{{/exts.x-to-string-support}}
|
||||||
{{/dataType}}
|
{{/dataType}}
|
||||||
{{^dataType}}
|
{{^dataType}}
|
||||||
{{#arrayModelType}}
|
{{#arrayModelType}}
|
||||||
{{#vendorExtensions}}{{#x-item-xml-name}}// Utility function for wrapping list elements when serializing xml
|
{{#exts}}{{#x-item-xml-name}}// Utility function for wrapping list elements when serializing xml
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
fn wrap_in_{{{x-item-xml-name}}}<S>(items: &Vec<{{{arrayModelType}}}>, serializer: S) -> std::result::Result<S::Ok, S::Error>
|
fn wrap_in_{{{x-item-xml-name}}}<S>(items: &Vec<{{{arrayModelType}}}>, serializer: S) -> std::result::Result<S::Ok, S::Error>
|
||||||
where
|
where
|
||||||
@ -173,16 +173,16 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
{{/x-item-xml-name}}
|
{{/x-item-xml-name}}
|
||||||
{{/vendorExtensions}}
|
{{/exts}}
|
||||||
{{! vec}}
|
{{! vec}}
|
||||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||||
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
|
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
|
||||||
pub struct {{{classname}}}(
|
pub struct {{{classname}}}(
|
||||||
{{#vendorExtensions}}
|
{{#exts}}
|
||||||
{{#x-item-xml-name}}
|
{{#x-item-xml-name}}
|
||||||
#[serde(serialize_with = "wrap_in_{{{x-item-xml-name}}}")]
|
#[serde(serialize_with = "wrap_in_{{{x-item-xml-name}}}")]
|
||||||
{{/x-item-xml-name}}
|
{{/x-item-xml-name}}
|
||||||
{{/vendorExtensions}}
|
{{/exts}}
|
||||||
Vec<{{{arrayModelType}}}>
|
Vec<{{{arrayModelType}}}>
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -282,11 +282,11 @@ pub struct {{{classname}}} {
|
|||||||
{{/description}}{{#isEnum}} // Note: inline enums are not fully supported by openapi-generator
|
{{/description}}{{#isEnum}} // Note: inline enums are not fully supported by openapi-generator
|
||||||
{{/isEnum}}
|
{{/isEnum}}
|
||||||
#[serde(rename = "{{{baseName}}}")]
|
#[serde(rename = "{{{baseName}}}")]
|
||||||
{{#vendorExtensions}}
|
{{#exts}}
|
||||||
{{#x-item-xml-name}}
|
{{#x-item-xml-name}}
|
||||||
#[serde(serialize_with = "wrap_in_{{{x-item-xml-name}}}")]
|
#[serde(serialize_with = "wrap_in_{{{x-item-xml-name}}}")]
|
||||||
{{/x-item-xml-name}}
|
{{/x-item-xml-name}}
|
||||||
{{/vendorExtensions}}
|
{{/exts}}
|
||||||
{{#hasValidation}}
|
{{#hasValidation}}
|
||||||
#[validate(
|
#[validate(
|
||||||
{{#maxLength}}
|
{{#maxLength}}
|
||||||
|
|||||||
@ -1,14 +1,14 @@
|
|||||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
{{#vendorExtensions.x-must-use-response}}
|
{{#exts.x-must-use-response}}
|
||||||
#[must_use]
|
#[must_use]
|
||||||
{{/vendorExtensions.x-must-use-response}}
|
{{/exts.x-must-use-response}}
|
||||||
pub enum {{{operationId}}}Response {
|
pub enum {{{operationId}}}Response {
|
||||||
{{#responses}}
|
{{#responses}}
|
||||||
{{#message}}
|
{{#message}}
|
||||||
/// {{{.}}}{{/message}}
|
/// {{{.}}}{{/message}}
|
||||||
{{#vendorExtensions}}
|
{{#exts}}
|
||||||
{{{x-response-id}}}
|
{{{x-response-id}}}
|
||||||
{{/vendorExtensions}}
|
{{/exts}}
|
||||||
{{^dataType}}
|
{{^dataType}}
|
||||||
{{#hasHeaders}}
|
{{#hasHeaders}}
|
||||||
{
|
{
|
||||||
@ -16,25 +16,25 @@ pub enum {{{operationId}}}Response {
|
|||||||
{{/dataType}}
|
{{/dataType}}
|
||||||
{{#dataType}}
|
{{#dataType}}
|
||||||
{{^hasHeaders}}
|
{{^hasHeaders}}
|
||||||
{{#vendorExtensions}}
|
{{#exts}}
|
||||||
{{#x-produces-plain-text}}
|
{{#x-produces-plain-text}}
|
||||||
(String)
|
(String)
|
||||||
{{/x-produces-plain-text}}
|
{{/x-produces-plain-text}}
|
||||||
{{^x-produces-plain-text}}
|
{{^x-produces-plain-text}}
|
||||||
({{{dataType}}})
|
({{{dataType}}})
|
||||||
{{/x-produces-plain-text}}
|
{{/x-produces-plain-text}}
|
||||||
{{/vendorExtensions}}
|
{{/exts}}
|
||||||
{{/hasHeaders}}
|
{{/hasHeaders}}
|
||||||
{{#hasHeaders}}
|
{{#hasHeaders}}
|
||||||
{
|
{
|
||||||
{{#vendorExtensions}}
|
{{#exts}}
|
||||||
{{#x-produces-plain-text}}
|
{{#x-produces-plain-text}}
|
||||||
body: String,
|
body: String,
|
||||||
{{/x-produces-plain-text}}
|
{{/x-produces-plain-text}}
|
||||||
{{^x-produces-plain-text}}
|
{{^x-produces-plain-text}}
|
||||||
body: {{{dataType}}},
|
body: {{{dataType}}},
|
||||||
{{/x-produces-plain-text}}
|
{{/x-produces-plain-text}}
|
||||||
{{/vendorExtensions}}
|
{{/exts}}
|
||||||
{{/hasHeaders}}
|
{{/hasHeaders}}
|
||||||
{{/dataType}}
|
{{/dataType}}
|
||||||
{{#headers}}
|
{{#headers}}
|
||||||
|
|||||||
@ -41,7 +41,7 @@ impl<T> RequestParser<T> for ApiRequestParser {
|
|||||||
{{#operations}}
|
{{#operations}}
|
||||||
{{#operation}}
|
{{#operation}}
|
||||||
// {{{operationId}}} - {{{httpMethod}}} {{{path}}}
|
// {{{operationId}}} - {{{httpMethod}}} {{{path}}}
|
||||||
hyper::Method::{{{vendorExtensions.x-http-method}}} if path.matched(paths::ID_{{{vendorExtensions.x-path-id}}}) => Some("{{{operationId}}}"),
|
hyper::Method::{{{exts.x-http-method}}} if path.matched(paths::ID_{{{exts.x-path-id}}}) => Some("{{{operationId}}}"),
|
||||||
{{/operation}}
|
{{/operation}}
|
||||||
{{/operations}}
|
{{/operations}}
|
||||||
{{/apis}}
|
{{/apis}}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
// {{{operationId}}} - {{{httpMethod}}} {{{path}}}
|
// {{{operationId}}} - {{{httpMethod}}} {{{path}}}
|
||||||
hyper::Method::{{vendorExtensions.x-http-method}} if path.matched(paths::ID_{{vendorExtensions.x-path-id}}) => {
|
hyper::Method::{{exts.x-http-method}} if path.matched(paths::ID_{{exts.x-path-id}}) => {
|
||||||
{{#hasAuthMethods}}
|
{{#hasAuthMethods}}
|
||||||
{
|
{
|
||||||
let authorization = match *(&context as &dyn Has<Option<Authorization>>).get() {
|
let authorization = match *(&context as &dyn Has<Option<Authorization>>).get() {
|
||||||
@ -37,7 +37,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
{{/hasAuthMethods}}
|
{{/hasAuthMethods}}
|
||||||
{{#vendorExtensions}}
|
{{#exts}}
|
||||||
{{#x-has-path-params}}
|
{{#x-has-path-params}}
|
||||||
// Path parameters
|
// Path parameters
|
||||||
let path: &str = uri.path();
|
let path: &str = uri.path();
|
||||||
@ -49,7 +49,7 @@
|
|||||||
);
|
);
|
||||||
|
|
||||||
{{/x-has-path-params}}
|
{{/x-has-path-params}}
|
||||||
{{/vendorExtensions}}
|
{{/exts}}
|
||||||
{{#pathParams}}
|
{{#pathParams}}
|
||||||
let param_{{{paramName}}} = match percent_encoding::percent_decode(path_params["{{{baseName}}}"].as_bytes()).decode_utf8() {
|
let param_{{{paramName}}} = match percent_encoding::percent_decode(path_params["{{{baseName}}}"].as_bytes()).decode_utf8() {
|
||||||
Ok(param_{{{paramName}}}) => match param_{{{paramName}}}.parse::<{{{dataType}}}>() {
|
Ok(param_{{{paramName}}}) => match param_{{{paramName}}}.parse::<{{{dataType}}}>() {
|
||||||
@ -66,11 +66,11 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
{{/pathParams}}
|
{{/pathParams}}
|
||||||
{{#vendorExtensions}}
|
{{#exts}}
|
||||||
{{#x-callback-params}}
|
{{#x-callback-params}}
|
||||||
let callback_{{.}} = path_params["{{{.}}}"].to_string();
|
let callback_{{.}} = path_params["{{{.}}}"].to_string();
|
||||||
{{/x-callback-params}}
|
{{/x-callback-params}}
|
||||||
{{/vendorExtensions}}
|
{{/exts}}
|
||||||
{{#headerParams}}
|
{{#headerParams}}
|
||||||
{{#-first}}
|
{{#-first}}
|
||||||
// Header parameters
|
// Header parameters
|
||||||
@ -117,7 +117,7 @@
|
|||||||
{{/-first}}
|
{{/-first}}
|
||||||
let param_{{{paramName}}} = query_params.iter().filter(|e| e.0 == "{{{baseName}}}").map(|e| e.1.clone())
|
let param_{{{paramName}}} = query_params.iter().filter(|e| e.0 == "{{{baseName}}}").map(|e| e.1.clone())
|
||||||
{{#isArray}}
|
{{#isArray}}
|
||||||
{{^vendorExtensions.x-consumes-json}}
|
{{^exts.x-consumes-json}}
|
||||||
.filter_map(|param_{{{paramName}}}| param_{{{paramName}}}.parse().ok())
|
.filter_map(|param_{{{paramName}}}| param_{{{paramName}}}.parse().ok())
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
{{^required}}
|
{{^required}}
|
||||||
@ -127,8 +127,8 @@
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
{{/required}}
|
{{/required}}
|
||||||
{{/vendorExtensions.x-consumes-json}}
|
{{/exts.x-consumes-json}}
|
||||||
{{#vendorExtensions.x-consumes-json}}
|
{{#exts.x-consumes-json}}
|
||||||
.next();
|
.next();
|
||||||
let param_{{{paramName}}} = match param_{{{paramName}}} {
|
let param_{{{paramName}}} = match param_{{{paramName}}} {
|
||||||
Some(param_{{{paramName}}}) => {
|
Some(param_{{{paramName}}}) => {
|
||||||
@ -154,19 +154,19 @@
|
|||||||
.expect("Unable to create Bad Request response for missing query parameter {{{baseName}}}")),
|
.expect("Unable to create Bad Request response for missing query parameter {{{baseName}}}")),
|
||||||
};
|
};
|
||||||
{{/required}}
|
{{/required}}
|
||||||
{{/vendorExtensions.x-consumes-json}}
|
{{/exts.x-consumes-json}}
|
||||||
{{/isArray}}
|
{{/isArray}}
|
||||||
{{^isArray}}
|
{{^isArray}}
|
||||||
.next();
|
.next();
|
||||||
let param_{{{paramName}}} = match param_{{{paramName}}} {
|
let param_{{{paramName}}} = match param_{{{paramName}}} {
|
||||||
Some(param_{{{paramName}}}) => {
|
Some(param_{{{paramName}}}) => {
|
||||||
let param_{{{paramName}}} =
|
let param_{{{paramName}}} =
|
||||||
{{#vendorExtensions.x-consumes-json}}
|
{{#exts.x-consumes-json}}
|
||||||
serde_json::from_str::<{{{dataType}}}>
|
serde_json::from_str::<{{{dataType}}}>
|
||||||
{{/vendorExtensions.x-consumes-json}}
|
{{/exts.x-consumes-json}}
|
||||||
{{^vendorExtensions.x-consumes-json}}
|
{{^exts.x-consumes-json}}
|
||||||
<{{{dataType}}} as std::str::FromStr>::from_str
|
<{{{dataType}}} as std::str::FromStr>::from_str
|
||||||
{{/vendorExtensions.x-consumes-json}}
|
{{/exts.x-consumes-json}}
|
||||||
(¶m_{{{paramName}}});
|
(¶m_{{{paramName}}});
|
||||||
match param_{{{paramName}}} {
|
match param_{{{paramName}}} {
|
||||||
Ok(param_{{{paramName}}}) => Some(param_{{{paramName}}}),
|
Ok(param_{{{paramName}}}) => Some(param_{{{paramName}}}),
|
||||||
@ -192,29 +192,29 @@
|
|||||||
|
|
||||||
{{/-last}}
|
{{/-last}}
|
||||||
{{/queryParams}}
|
{{/queryParams}}
|
||||||
{{#vendorExtensions.x-has-request-body}}
|
{{#exts.x-has-request-body}}
|
||||||
// Handle body parameters (note that non-required body parameters will ignore garbage
|
// Handle body parameters (note that non-required body parameters will ignore garbage
|
||||||
// values, rather than causing a 400 response). Produce warning header and logs for
|
// values, rather than causing a 400 response). Produce warning header and logs for
|
||||||
// any unused fields.
|
// any unused fields.
|
||||||
let result = http_body_util::BodyExt::collect(body).await.map(|f| f.to_bytes().to_vec());
|
let result = http_body_util::BodyExt::collect(body).await.map(|f| f.to_bytes().to_vec());
|
||||||
match result {
|
match result {
|
||||||
Ok(body) => {
|
Ok(body) => {
|
||||||
{{^vendorExtensions.x-consumes-multipart-form}}
|
{{^exts.x-consumes-multipart-form}}
|
||||||
{{^vendorExtensions.x-consumes-form}}
|
{{^exts.x-consumes-form}}
|
||||||
{{^bodyParam.vendorExtensions.x-consumes-plain-text}}
|
{{^bodyParam.exts.x-consumes-plain-text}}
|
||||||
let mut unused_elements : Vec<String> = vec![];
|
let mut unused_elements : Vec<String> = vec![];
|
||||||
{{/bodyParam.vendorExtensions.x-consumes-plain-text}}
|
{{/bodyParam.exts.x-consumes-plain-text}}
|
||||||
{{/vendorExtensions.x-consumes-form}}
|
{{/exts.x-consumes-form}}
|
||||||
{{/vendorExtensions.x-consumes-multipart-form}}
|
{{/exts.x-consumes-multipart-form}}
|
||||||
{{>server-request-body-instance}}
|
{{>server-request-body-instance}}
|
||||||
|
|
||||||
{{/vendorExtensions.x-has-request-body}}
|
{{/exts.x-has-request-body}}
|
||||||
let result = api_impl.{{#vendorExtensions}}{{{x-operation-id}}}{{/vendorExtensions}}(
|
let result = api_impl.{{#exts}}{{{x-operation-id}}}{{/exts}}(
|
||||||
{{#vendorExtensions}}
|
{{#exts}}
|
||||||
{{#x-callback-params}}
|
{{#x-callback-params}}
|
||||||
callback_{{.}},
|
callback_{{.}},
|
||||||
{{/x-callback-params}}
|
{{/x-callback-params}}
|
||||||
{{/vendorExtensions}}
|
{{/exts}}
|
||||||
{{#allParams}}
|
{{#allParams}}
|
||||||
param_{{{paramName}}}{{#isArray}}.as_ref(){{/isArray}},
|
param_{{{paramName}}}{{#isArray}}.as_ref(){{/isArray}},
|
||||||
{{/allParams}}
|
{{/allParams}}
|
||||||
@ -226,24 +226,24 @@
|
|||||||
HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().as_str())
|
HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().as_str())
|
||||||
.expect("Unable to create X-Span-ID header value"));
|
.expect("Unable to create X-Span-ID header value"));
|
||||||
|
|
||||||
{{#vendorExtensions.x-has-request-body}}
|
{{#exts.x-has-request-body}}
|
||||||
{{^vendorExtensions.x-consumes-multipart-form}}
|
{{^exts.x-consumes-multipart-form}}
|
||||||
{{^vendorExtensions.x-consumes-form}}
|
{{^exts.x-consumes-form}}
|
||||||
{{^bodyParam.vendorExtensions.x-consumes-plain-text}}
|
{{^bodyParam.exts.x-consumes-plain-text}}
|
||||||
if !unused_elements.is_empty() {
|
if !unused_elements.is_empty() {
|
||||||
response.headers_mut().insert(
|
response.headers_mut().insert(
|
||||||
HeaderName::from_static("warning"),
|
HeaderName::from_static("warning"),
|
||||||
HeaderValue::from_str(format!("Ignoring unknown fields in body: {unused_elements:?}").as_str())
|
HeaderValue::from_str(format!("Ignoring unknown fields in body: {unused_elements:?}").as_str())
|
||||||
.expect("Unable to create Warning header value"));
|
.expect("Unable to create Warning header value"));
|
||||||
}
|
}
|
||||||
{{/bodyParam.vendorExtensions.x-consumes-plain-text}}
|
{{/bodyParam.exts.x-consumes-plain-text}}
|
||||||
{{/vendorExtensions.x-consumes-form}}
|
{{/exts.x-consumes-form}}
|
||||||
{{/vendorExtensions.x-consumes-multipart-form}}
|
{{/exts.x-consumes-multipart-form}}
|
||||||
{{/vendorExtensions.x-has-request-body}}
|
{{/exts.x-has-request-body}}
|
||||||
match result {
|
match result {
|
||||||
Ok(rsp) => match rsp {
|
Ok(rsp) => match rsp {
|
||||||
{{#responses}}
|
{{#responses}}
|
||||||
{{{operationId}}}Response::{{#vendorExtensions}}{{x-response-id}}{{/vendorExtensions}}
|
{{{operationId}}}Response::{{#exts}}{{x-response-id}}{{/exts}}
|
||||||
{{#dataType}}
|
{{#dataType}}
|
||||||
{{^headers}}
|
{{^headers}}
|
||||||
(body)
|
(body)
|
||||||
@ -309,12 +309,12 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ok(response)
|
Ok(response)
|
||||||
{{#vendorExtensions.x-has-request-body}}
|
{{#exts.x-has-request-body}}
|
||||||
},
|
},
|
||||||
Err(e) => Ok(Response::builder()
|
Err(e) => Ok(Response::builder()
|
||||||
.status(StatusCode::BAD_REQUEST)
|
.status(StatusCode::BAD_REQUEST)
|
||||||
.body(body_from_string(format!("Unable to read body: {}", e.into())))
|
.body(body_from_string(format!("Unable to read body: {}", e.into())))
|
||||||
.expect("Unable to create Bad Request response due to unable to read body")),
|
.expect("Unable to create Bad Request response due to unable to read body")),
|
||||||
}
|
}
|
||||||
{{/vendorExtensions.x-has-request-body}}
|
{{/exts.x-has-request-body}}
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
{{#vendorExtensions}}
|
{{#exts}}
|
||||||
let param_{{{paramName}}}: Option<{{{dataType}}}> = if !body.is_empty() {
|
let param_{{{paramName}}}: Option<{{{dataType}}}> = if !body.is_empty() {
|
||||||
{{#x-consumes-xml}}
|
{{#x-consumes-xml}}
|
||||||
let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body);
|
let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body);
|
||||||
@ -41,7 +41,7 @@
|
|||||||
}
|
}
|
||||||
{{/isString}}
|
{{/isString}}
|
||||||
{{/x-consumes-plain-text}}
|
{{/x-consumes-plain-text}}
|
||||||
{{/vendorExtensions}}
|
{{/exts}}
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
{{#vendorExtensions}}
|
{{#exts}}
|
||||||
{{#formParams}}
|
{{#formParams}}
|
||||||
{{#-first}}
|
{{#-first}}
|
||||||
// Form parameters
|
// Form parameters
|
||||||
{{/-first}}
|
{{/-first}}
|
||||||
let param_{{{paramName}}} =
|
let param_{{{paramName}}} =
|
||||||
{{^isContainer}}
|
{{^isContainer}}
|
||||||
{{#vendorExtensions}}
|
{{#exts}}
|
||||||
{{{x-example}}};
|
{{{x-example}}};
|
||||||
{{/vendorExtensions}}
|
{{/exts}}
|
||||||
{{/isContainer}}
|
{{/isContainer}}
|
||||||
{{#isArray}}
|
{{#isArray}}
|
||||||
{{#required}}
|
{{#required}}
|
||||||
@ -21,4 +21,4 @@
|
|||||||
None;
|
None;
|
||||||
{{/isMap}}
|
{{/isMap}}
|
||||||
{{/formParams}}
|
{{/formParams}}
|
||||||
{{/vendorExtensions}}
|
{{/exts}}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
{{#vendorExtensions}}
|
{{#exts}}
|
||||||
{{#x-consumes-multipart}}
|
{{#x-consumes-multipart}}
|
||||||
{{#x-consumes-multipart-related}}
|
{{#x-consumes-multipart-related}}
|
||||||
{{>server-request-body-multipart-related}}
|
{{>server-request-body-multipart-related}}
|
||||||
@ -21,4 +21,4 @@
|
|||||||
|
|
||||||
{{/bodyParams}}
|
{{/bodyParams}}
|
||||||
{{/x-consumes-multipart}}
|
{{/x-consumes-multipart}}
|
||||||
{{/vendorExtensions}}
|
{{/exts}}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
{{#dataType}}
|
{{#dataType}}
|
||||||
{{#vendorExtensions}}
|
{{#exts}}
|
||||||
{{^x-produces-multipart-related}}
|
{{^x-produces-multipart-related}}
|
||||||
response.headers_mut().insert(
|
response.headers_mut().insert(
|
||||||
CONTENT_TYPE,
|
CONTENT_TYPE,
|
||||||
@ -43,6 +43,6 @@
|
|||||||
.expect("Unable to create Content-Type header for multipart/related"));
|
.expect("Unable to create Content-Type header for multipart/related"));
|
||||||
{{/formParams}}
|
{{/formParams}}
|
||||||
{{/x-produces-multipart-related}}
|
{{/x-produces-multipart-related}}
|
||||||
{{/vendorExtensions}}
|
{{/exts}}
|
||||||
*response.body_mut() = body_from_string(body);
|
*response.body_mut() = body_from_string(body);
|
||||||
{{/dataType}}
|
{{/dataType}}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user