Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,15 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
private Map<String, CodegenProperty> requiredVarsMap;
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
public CodegenProperty getContains() {
return contains;
Expand Down Expand Up @@ -365,7 +374,6 @@ public String getDiscriminatorName() {
return discriminator == null ? null : discriminator.getPropertyName();
}


@Override
public String getPattern() {
return pattern;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ private static boolean nonEmpty(Map<?, ?> params) {
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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,15 @@ public String 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
@Override
public CodegenProperty getContains() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,15 @@ public boolean notRequiredOrIsNullable() {
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
public CodegenProperty getItems() {
return items;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,15 @@ public boolean equals(Object o) {

}

/**
* 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
@Override
public CodegenProperty getContains() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,13 @@ public String toString() {
sb.append('}');
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ To run a client, follow one of the following simple steps:
{{#apis}}
{{#operations}}
{{#operation}}
{{#vendorExtensions}}
{{#exts}}
{{^x-no-client-example}}
cargo run --example client {{{operationId}}}
{{/x-no-client-example}}
{{/vendorExtensions}}
{{/exts}}
{{/operation}}
{{/operations}}
{{/apis}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ enum Operation {
{{/isBinary}}
{{#isBoolean}}
{{#isPrimitiveType}}
{{#vendorExtensions.x-provide-cli-short-opt}}
{{#exts.x-provide-cli-short-opt}}
#[clap(short, long)]
{{/vendorExtensions.x-provide-cli-short-opt}}
{{^vendorExtensions.x-provide-cli-short-opt}}
{{/exts.x-provide-cli-short-opt}}
{{^exts.x-provide-cli-short-opt}}
#[clap(long)]
{{/vendorExtensions.x-provide-cli-short-opt}}
{{/exts.x-provide-cli-short-opt}}
{{/isPrimitiveType}}
{{/isBoolean}}
{{{paramName}}}: {{^required}}Option<{{/required}}{{{dataType}}}{{^required}}>{{/required}},
Expand Down Expand Up @@ -216,9 +216,9 @@ async fn main() -> Result<()> {
{{paramName}},
{{/allParams}}
} => {
{{#vendorExtensions.x-is-delete}}
{{#exts.x-is-delete}}
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}}
{{#pathParams}}
&{{paramName}}{{^-last}},{{/-last}}
Expand All @@ -227,7 +227,7 @@ async fn main() -> Result<()> {
{{/-last}}
{{/pathParams}}

let result = client.{{{vendorExtensions.x-operation-id}}}(
let result = client.{{{exts.x-operation-id}}}(
{{#allParams}}
{{{paramName}}}{{#isArray}}.as_ref(){{/isArray}},
{{/allParams}}
Expand All @@ -236,7 +236,7 @@ async fn main() -> Result<()> {

match result {
{{#responses}}
{{{operationId}}}Response::{{{vendorExtensions.x-response-id}}}
{{{operationId}}}Response::{{{exts.x-response-id}}}
{{#dataType}}
{{^hasHeaders}}
(body)
Expand All @@ -257,7 +257,7 @@ async fn main() -> Result<()> {
}
{{/-last}}
{{/headers}}
=> "{{{vendorExtensions.x-response-id}}}\n".to_string()
=> "{{{exts.x-response-id}}}\n".to_string()
{{#dataType}}
+
{{/dataType}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl<T> RequestParser<T> for ApiRequestParser {
{{#urls}}
{{#requests}}
// {{{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}}
{{/urls}}
{{/callbacks}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#[allow(clippy::vec_init_then_push)]
async fn {{#vendorExtensions}}{{{x-operation-id}}}{{/vendorExtensions}}(
async fn {{#exts}}{{{x-operation-id}}}{{/exts}}(
&self,
{{#vendorExtensions}}
{{#exts}}
{{#x-callback-params}}
callback_{{.}}: String,
{{/x-callback-params}}
{{/vendorExtensions}}
{{/exts}}
{{#allParams}}
param_{{{paramName}}}: {{^required}}Option<{{/required}}{{#isArray}}&{{/isArray}}{{{dataType}}}{{^required}}>{{/required}},
{{/allParams}}
Expand All @@ -15,20 +15,20 @@
#[allow(clippy::uninlined_format_args)]
let mut uri = format!(
{{#isCallbackRequest}}
"{{vendorExtensions.x-path-format-string}}"
"{{exts.x-path-format-string}}"
{{/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
{{/isCallbackRequest}}
{{#pathParams}}
,{{{paramName}}}=utf8_percent_encode(&param_{{{paramName}}}.to_string(), ID_ENCODE_SET)
{{/pathParams}}
{{#vendorExtensions}}
{{#exts}}
{{#x-callback-params}}
,{{.}}=callback_{{.}}
{{/x-callback-params}}
{{/vendorExtensions}}
{{/exts}}
);

// Query parameters
Expand All @@ -39,7 +39,7 @@
if let Some(param_{{{paramName}}}) = param_{{{paramName}}} {
{{/required}}
query_string.append_pair("{{{baseName}}}",
{{#vendorExtensions}}
{{#exts}}
{{#x-consumes-json}}
&match serde_json::to_string(&param_{{{paramName}}}) {
Ok(str) => str,
Expand All @@ -54,7 +54,7 @@
&param_{{{paramName}}}{{^isString}}.to_string(){{/isString}});
{{/isArray}}
{{/x-consumes-json}}
{{/vendorExtensions}}
{{/exts}}
{{^required}}
}
{{/required}}
Expand All @@ -81,7 +81,7 @@
};

let mut request = match Request::builder()
.method("{{{vendorExtensions.x-http-method}}}")
.method("{{{exts.x-http-method}}}")
.uri(uri)
.body(BoxBody::new(http_body_util::Empty::new())) {
Ok(req) => req,
Expand Down Expand Up @@ -214,7 +214,7 @@
{{>client-response-body-instance}}


Ok({{{operationId}}}Response::{{#vendorExtensions}}{{x-response-id}}{{/vendorExtensions}}
Ok({{{operationId}}}Response::{{#exts}}{{x-response-id}}{{/exts}}
{{^headers}}
(body)
{{/headers}}
Expand All @@ -232,7 +232,7 @@
{{/dataType}}
{{^dataType}}
Ok(
{{{operationId}}}Response::{{#vendorExtensions}}{{x-response-id}}{{/vendorExtensions}}
{{{operationId}}}Response::{{#exts}}{{x-response-id}}{{/exts}}
{{#headers}}
{{#-first}}
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{#vendorExtensions}}
{{#exts}}
{{#x-consumes-multipart-form}}

// Consumes multipart/form body
Expand Down Expand Up @@ -42,7 +42,7 @@
#[allow(clippy::uninlined_format_args)]
params.push(("{{{baseName}}}",
{{^isString}}
format!("{{{vendorExtensions.x-format-string}}}", param_{{{paramName}}})
format!("{{{exts.x-format-string}}}", param_{{{paramName}}})
{{/isString}}
{{#isString}}
{{#isArray}}
Expand Down Expand Up @@ -78,7 +78,7 @@
{{^required}}
if let Some(param_{{{paramName}}}) = param_{{{paramName}}} {
{{/required}}
{{#vendorExtensions}}
{{#exts}}
{{#x-consumes-plain-text}}
{{#isByteArray}}
let body = String::from_utf8(param_body.0).expect("Body was not valid UTF8");
Expand All @@ -93,7 +93,7 @@
{{#x-consumes-json}}
let body = serde_json::to_string(&param_{{{paramName}}}).expect("impossible to fail to serialize");
{{/x-consumes-json}}
{{/vendorExtensions}}
{{/exts}}
*request.body_mut() = body_from_string(body);
{{^required}}
}
Expand All @@ -103,4 +103,4 @@
request.headers_mut().insert(CONTENT_TYPE, HeaderValue::from_static(header));
{{/bodyParam}}
{{/x-consumes-basic}}
{{/vendorExtensions}}
{{/exts}}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let (body_string, multipart_header) = {
let mut multipart = Multipart::new();
{{#vendorExtensions}}
{{#exts}}
{{#formParams}}
{{#-first}}
// For each parameter, encode as appropriate and add to the multipart body as a stream.
Expand Down Expand Up @@ -36,7 +36,7 @@
multipart.add_stream("{{{paramName}}}", {{{paramName}}}_cursor, filename, Some({{{paramName}}}_mime));
{{/isByteArray}}
{{/formParams}}
{{/vendorExtensions}}
{{/exts}}

let mut fields = match multipart.prepare() {
Ok(fields) => fields,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{#vendorExtensions}}
{{#exts}}
{{#x-produces-bytes}}
let body = swagger::ByteArray(body.to_vec());
{{/x-produces-bytes}}
Expand All @@ -19,4 +19,4 @@
let body = body.to_string();
{{/x-produces-plain-text}}
{{/x-produces-bytes}}
{{/vendorExtensions}}
{{/exts}}
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ let param_{{{paramName}}} = match param_{{{paramName}}} {
};
{{/required}}
{{/formParams}}
{{^vendorExtensions.x-consumes-basic}}
{{^exts.x-consumes-basic}}
let body = {{{dataType}}} {
{{#formParams}}
{{{paramName}}}: param_{{{paramName}}},
{{/formParams}}
};
{{/vendorExtensions.x-consumes-basic}}
{{/exts.x-consumes-basic}}
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl<T, A, B, C, ReqBody> Service<Request<ReqBody>> for AddContext<T, A>
{
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 context = context.push(Some(auth_data));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,24 +140,24 @@ fn main() {
{{#apis}}
{{#operations}}
{{#operation}}
{{#vendorExtensions}}
{{#exts}}
{{#x-no-client-example}}
/* Disabled because there's no example.
{{/x-no-client-example}}
{{/vendorExtensions}}
{{/exts}}
Some("{{{operationId}}}") => {
let result = rt.block_on(client.{{{vendorExtensions.x-operation-id}}}(
let result = rt.block_on(client.{{{exts.x-operation-id}}}(
{{#allParams}}
{{{vendorExtensions.x-example}}}{{^-last}},{{/-last}}
{{{exts.x-example}}}{{^-last}},{{/-last}}
{{/allParams}}
));
info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has<XSpanIdString>).get().clone());
},
{{#vendorExtensions}}
{{#exts}}
{{#x-no-client-example}}
*/
{{/x-no-client-example}}
{{/vendorExtensions}}
{{/exts}}
{{/operation}}
{{/operations}}
{{/apis}}
Expand Down
Loading
Loading