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 @@ -861,6 +861,24 @@ private boolean postProcessOperationWithModels(final CodegenOperation op) {
}

if (op.bodyParam != null) {
final var dataType = op.bodyParam.dataType;
if (dataType.startsWith(vecType + "<String")) {
op.bodyParam.vendorExtensions.put("is-vec-string", true);
} else if (dataType.startsWith(vecType + "<models::")) {
op.bodyParam.vendorExtensions.put("is-vec-nested", true);
} else if (dataType.startsWith(mapType + "<String, String")) {
op.bodyParam.vendorExtensions.put("is-map-string", true);
} else if (dataType.startsWith(mapType + "<String, models::")) {
op.bodyParam.vendorExtensions.put("is-map-nested", true);
} else if (dataType.startsWith(mapType + "<String")) {
op.bodyParam.vendorExtensions.put("is-map", true);
} else if (dataType.startsWith("models::")) {
op.bodyParam.isModel = true;
} else if (dataType.equals("String")) {
op.bodyParam.isString = true;
op.bodyParam.vendorExtensions.put("is-string", true);
}

if (consumesJson) {
op.bodyParam.vendorExtensions.put("x-consumes-json", true);
} else if (consumesFormUrlEncoded) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ use validator::Validate;
use crate::header;
use crate::{models, types::*};

#[allow(dead_code)]
fn from_validation_error(e: validator::ValidationError) -> validator::ValidationErrors {
let mut errs = validator::ValidationErrors::new();
errs.add("na", e);
errs
}

#[allow(dead_code)]
pub fn check_xss_string(v: &str) -> std::result::Result<(), validator::ValidationError> {
if ammonia::is_html(v) {
Expand Down Expand Up @@ -465,7 +472,7 @@ pub fn check_xss_map<T>(v: &std::collections::HashMap<String, T>) -> std::result
#[serde(default)]
{{/required}}
pub {{{paramName}}}: {{{dataType}}},
{{/isArray}}
{{/isArray}}
{{^isArray}}
{{#required}}
pub {{{paramName}}}: {{#isNullable}}Nullable<{{/isNullable}}{{{dataType}}}{{#isNullable}}>{{/isNullable}},
Expand Down Expand Up @@ -580,10 +587,36 @@ impl std::str::FromStr for {{{classname}}} {
#[derive(Debug, Clone, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)]
{{/isMap}}
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
pub struct {{{classname}}}({{{dataType}}});
pub struct {{{classname}}}(pub {{{dataType}}});

impl validator::Validate for {{{classname}}} {
fn validate(&self) -> std::result::Result<(), validator::ValidationErrors> {
{{^isNullable}}
{{#vendorExtensions.is-nested}}
let _ = self.0.validate()?;
{{/vendorExtensions.is-nested}}
{{#vendorExtensions.is-string}}
let _ = check_xss_string(&self.0).map_err(from_validation_error)?;
{{/vendorExtensions.is-string}}
{{#vendorExtensions.is-vec-nested}}
for v in self.0.iter() {
let _ = v.validate()?;
}
{{/vendorExtensions.is-vec-nested}}
{{#vendorExtensions.is-vec-string}}
let _ = check_xss_vec_string(&self.0).map_err(from_validation_error)?;
{{/vendorExtensions.is-vec-string}}
{{#vendorExtensions.is-map-nested}}
let _ = check_xss_map_nested(&self.0).map_err(from_validation_error)?;
{{/vendorExtensions.is-map-nested}}
{{#vendorExtensions.is-map}}
let _ = check_xss_map(&self.0).map_err(from_validation_error)?;
{{/vendorExtensions.is-map}}
{{#vendorExtensions.is-map-string}}
let _ = check_xss_map_string(&self.0).map_err(from_validation_error)?;
{{/vendorExtensions.is-map-string}}
{{/isNullable}}

std::result::Result::Ok(())
}
}
Expand Down Expand Up @@ -656,7 +689,7 @@ impl ::std::str::FromStr for {{{classname}}} {
{{! vec}}
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
pub struct {{{classname}}}(Vec<{{{arrayModelType}}}>);
pub struct {{{classname}}}(pub Vec<{{{arrayModelType}}}>);

impl validator::Validate for {{{classname}}} {
fn validate(&self) -> std::result::Result<(), validator::ValidationErrors> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ use crate::{header, types::*};

#[allow(unused_imports)]
use crate::{apis, models};

#[allow(unused_imports)]
use crate::{models::check_xss_string, models::check_xss_vec_string, models::check_xss_map_string, models::check_xss_map_nested, models::check_xss_map};
Original file line number Diff line number Diff line change
Expand Up @@ -5,67 +5,108 @@
#[derive(validator::Validate)]
#[allow(dead_code)]
struct {{{operationIdCamelCase}}}BodyValidator<'a> {
{{#hasValidation}}
#[validate(
{{#maxLength}}
{{#minLength}}
length(min = {{minLength}}, max = {{maxLength}}),
{{/minLength}}
{{^minLength}}
length(max = {{maxLength}}),
{{/minLength}}
{{/maxLength}}
{{^maxLength}}
{{#minLength}}
length(min = {{minLength}}),
{{/minLength}}
{{/maxLength}}
{{#pattern}}
{{^x-consumes-plain-text}}
{{#isModel}}
#[validate(nested)]
{{/isModel}}
{{^isModel}}
{{#hasValidation}}
#[validate(
{{#maxLength}}
{{#minLength}}
length(min = {{minLength}}, max = {{maxLength}}),
{{/minLength}}
{{^minLength}}
length(max = {{maxLength}}),
{{/minLength}}
{{/maxLength}}
{{^maxLength}}
{{#minLength}}
length(min = {{minLength}}),
{{/minLength}}
{{/maxLength}}
{{#pattern}}
{{#isString}}
regex(path = *RE_{{#lambda.uppercase}}{{{operationIdCamelCase}}}BodyValidator{{/lambda.uppercase}}),
{{/isString}}
{{^isString}}
custom(function = "validate_byte_{{#lambda.lowercase}}{{{operationIdCamelCase}}}BodyValidator{{/lambda.lowercase}}"),
{{/isString}}
{{/pattern}}
{{#isString}}
regex(path = *RE_{{#lambda.uppercase}}{{{operationIdCamelCase}}}BodyValidator{{/lambda.uppercase}}),
{{/isString}}
{{^isString}}
custom(function = "validate_byte_{{#lambda.lowercase}}{{{operationIdCamelCase}}}BodyValidator{{/lambda.lowercase}}"),
custom(function = "check_xss_string"),
{{/isString}}
{{/pattern}}
{{#maximum}}
{{#minimum}}
range(min = {{minimum}}, max = {{maximum}}),
{{/minimum}}
{{^minimum}}
range(max = {{maximum}}),
{{/minimum}}
{{/maximum}}
{{#minimum}}
{{^maximum}}
range(min = {{minimum}}),
{{/maximum}}
{{/minimum}}
{{#maxItems}}
{{#minItems}}
length(min = {{minItems}}, max = {{maxItems}}),
{{/minItems}}
{{^minItems}}
length(max = {{maxItems}}),
{{/minItems}}
{{/maxItems}}
{{^maxItems}}
{{#minItems}}
length(min = {{minItems}}),
{{/minItems}}
{{/maxItems}}
)]
{{/hasValidation}}
{{^x-consumes-plain-text}}
{{#maximum}}
{{#minimum}}
range(min = {{minimum}}, max = {{maximum}}),
{{/minimum}}
{{^minimum}}
range(max = {{maximum}}),
{{/minimum}}
{{/maximum}}
{{#minimum}}
{{^maximum}}
range(min = {{minimum}}),
{{/maximum}}
{{/minimum}}
{{#maxItems}}
{{#minItems}}
length(min = {{minItems}}, max = {{maxItems}}),
{{/minItems}}
{{^minItems}}
length(max = {{maxItems}}),
{{/minItems}}
{{/maxItems}}
{{^maxItems}}
{{#minItems}}
length(min = {{minItems}}),
{{/minItems}}
{{/maxItems}}
{{#vendorExtensions.is-vec-nested}}
nested,
{{/vendorExtensions.is-vec-nested}}
{{#vendorExtensions.is-vec-string}}
custom(function = "check_xss_vec_string"),
{{/vendorExtensions.is-vec-string}}
{{#vendorExtensions.is-map-nested}}
custom(function = "check_xss_map_nested"),
{{/vendorExtensions.is-map-nested}}
{{#vendorExtensions.is-map}}
custom(function = "check_xss_map"),
{{/vendorExtensions.is-map}}
{{#vendorExtensions.is-map-string}}
custom(function = "check_xss_map_string"),
{{/vendorExtensions.is-map-string}} )]
{{/hasValidation}}
{{^hasValidation}}
{{^isMap}}
#[validate(nested)]
{{/isMap}}
{{#vendorExtensions.is-nested}}
#[validate(nested)]
{{/vendorExtensions.is-nested}}
{{#vendorExtensions.is-string}}
#[validate(custom(function = "check_xss_string"))]
{{/vendorExtensions.is-string}}
{{#vendorExtensions.is-vec-nested}}
#[validate(nested)]
{{/vendorExtensions.is-vec-nested}}
{{#vendorExtensions.is-vec-string}}
#[validate(custom(function = "check_xss_vec_string"))]
{{/vendorExtensions.is-vec-string}}
{{#vendorExtensions.is-map-nested}}
#[validate(custom(function = "check_xss_map_nested"))]
{{/vendorExtensions.is-map-nested}}
{{#vendorExtensions.is-map}}
#[validate(custom(function = "check_xss_map"))]
{{/vendorExtensions.is-map}}
{{#vendorExtensions.is-map-string}}
#[validate(custom(function = "check_xss_map_string"))]
{{/vendorExtensions.is-map-string}}
{{/hasValidation}}
{{/isModel}}
body: &'a {{{dataType}}},
{{/x-consumes-plain-text}}
{{#x-consumes-plain-text}}
{{#isString}}
#[validate(custom(function = "check_xss_string"))]
body: &'a String,
{{/isString}}
{{^isString}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,56 @@ paths:
"application/json":
schema:
"$ref": "#/components/schemas/Message"
"/issue21143_1":
post:
operationId: i21143_1
requestBody:
required: true
content:
"application/json":
schema:
type: array
items:
type: integer
responses:
"200":
description: Re-serialize and echo the request data
content:
"application/json":
schema:
"$ref": "#/components/schemas/Message"
"/issue21143_2":
post:
operationId: i21143_2
requestBody:
required: true
content:
"application/json":
schema:
type: string
responses:
"200":
description: Re-serialize and echo the request data
content:
"application/json":
schema:
"$ref": "#/components/schemas/Message"
"/issue21143_3":
post:
operationId: i21143_3
requestBody:
required: true
content:
"application/json":
schema:
type: integer
responses:
"200":
description: Re-serialize and echo the request data
content:
"application/json":
schema:
"$ref": "#/components/schemas/Message"
components:
schemas:
Message:
Expand Down Expand Up @@ -87,7 +137,7 @@ components:
- d
SomethingCompletelyDifferent:
oneOf:
- items:
type: object
type: array
- type: object
- items:
type: object
type: array
- type: object
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.16.0-SNAPSHOT
7.17.0-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ server, you can easily generate a server stub.
To see how to make this your own, look here: [README]((https://openapi-generator.tech))

- API version: 1.0.0
- Generator version: 7.16.0-SNAPSHOT
- Generator version: 7.17.0-SNAPSHOT



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ use validator::Validate;
use crate::header;
use crate::{models, types::*};

#[allow(dead_code)]
fn from_validation_error(e: validator::ValidationError) -> validator::ValidationErrors {
let mut errs = validator::ValidationErrors::new();
errs.add("na", e);
errs
}

#[allow(dead_code)]
pub fn check_xss_string(v: &str) -> std::result::Result<(), validator::ValidationError> {
if ammonia::is_html(v) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ use crate::{header, types::*};
#[allow(unused_imports)]
use crate::{apis, models};

#[allow(unused_imports)]
use crate::{
models::check_xss_map, models::check_xss_map_nested, models::check_xss_map_string,
models::check_xss_string, models::check_xss_vec_string,
};

/// Setup API Server.
pub fn new<I, A, E, C>(api_impl: I) -> Router
where
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.16.0-SNAPSHOT
7.17.0-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ server, you can easily generate a server stub.
To see how to make this your own, look here: [README]((https://openapi-generator.tech))

- API version: 1.0.0
- Generator version: 7.16.0-SNAPSHOT
- Generator version: 7.17.0-SNAPSHOT



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ use validator::Validate;
use crate::header;
use crate::{models, types::*};

#[allow(dead_code)]
fn from_validation_error(e: validator::ValidationError) -> validator::ValidationErrors {
let mut errs = validator::ValidationErrors::new();
errs.add("na", e);
errs
}

#[allow(dead_code)]
pub fn check_xss_string(v: &str) -> std::result::Result<(), validator::ValidationError> {
if ammonia::is_html(v) {
Expand Down
Loading
Loading