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 @@ -370,6 +370,16 @@ public String toOperationId(String operationId) {
return sanitizeIdentifier(operationId, CasingType.CAMEL_CASE, "call", "method", true);
}

@Override
public String toParamName(String name) {
// rust-server doesn't support r# in param name.
if (parameterNameMapping.containsKey(name)) {
return parameterNameMapping.get(name);
}

return sanitizeIdentifier(name, CasingType.SNAKE_CASE, "param", "parameter", false);
}

@Override
public String toEnumValue(String value, String datatype) {
// rust-server templates expect value to be in quotes
Expand Down Expand Up @@ -1229,6 +1239,9 @@ public CodegenModel fromModel(String name, Schema model) {
&& (mdl.dataType.startsWith("swagger::OneOf") || mdl.dataType.startsWith("swagger::AnyOf"))) {
toStringSupport = false;
partialOrdSupport = false;
} else if (mdl.dataType != null && mdl.dataType.equals("serde_json::Value")) {
// Value doesn't implement PartialOrd
partialOrdSupport = false;
} else if (mdl.getAdditionalPropertiesType() != null) {
toStringSupport = false;
} else if (model instanceof ComposedSchema) {
Expand Down Expand Up @@ -1545,7 +1558,18 @@ private void processParam(CodegenParameter param, CodegenOperation op) {
}
} else {
param.vendorExtensions.put("x-format-string", "{:?}");
if (param.example != null) {
// Check if this is a model-type enum (allowableValues with values list)
if (param.allowableValues != null && param.allowableValues.containsKey("values")) {
List<?> values = (List<?>) param.allowableValues.get("values");
if (!values.isEmpty()) {
// Use the first enum value as the example.
String firstEnumValue = values.get(0).toString();
String enumVariant = toEnumVarName(firstEnumValue, param.dataType);
example = param.dataType + "::" + enumVariant;
} else if (param.example != null) {
example = "serde_json::from_str::<" + param.dataType + ">(r#\"" + param.example + "\"#).expect(\"Failed to parse JSON example\")";
}
} else if (param.example != null) {
example = "serde_json::from_str::<" + param.dataType + ">(r#\"" + param.example + "\"#).expect(\"Failed to parse JSON example\")";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,9 @@ public CodegenModel fromModel(String name, Schema model) {
&& (mdl.dataType.startsWith("swagger::OneOf") || mdl.dataType.startsWith("swagger::AnyOf"))) {
toStringSupport = false;
partialOrdSupport = false;
} else if (mdl.dataType != null && mdl.dataType.equals("serde_json::Value")) {
// Value doesn't implement PartialOrd
partialOrdSupport = false;
} else if (mdl.getAdditionalPropertiesType() != null) {
toStringSupport = false;
} else if (model instanceof ComposedSchema) {
Expand Down Expand Up @@ -1546,7 +1549,18 @@ private void processParam(CodegenParameter param, CodegenOperation op) {
}
else {
param.vendorExtensions.put("x-format-string", "{:?}");
if (param.example != null) {
// Check if this is a model-type enum (allowableValues with values list)
if (param.allowableValues != null && param.allowableValues.containsKey("values")) {
List<?> values = (List<?>) param.allowableValues.get("values");
if (!values.isEmpty()) {
// Use the first enum value as the example.
String firstEnumValue = values.get(0).toString();
String enumVariant = toEnumVarName(firstEnumValue, param.dataType);
example = param.dataType + "::" + enumVariant;
} else if (param.example != null) {
example = "serde_json::from_str::<" + param.dataType + ">(r#\"" + param.example + "\"#).expect(\"Failed to parse JSON example\")";
}
} else if (param.example != null) {
example = "serde_json::from_str::<" + param.dataType + ">(r#\"" + param.example + "\"#).expect(\"Failed to parse JSON example\")";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,17 @@
{{/required}}
{{#exts}}
{{#x-consumes-plain-text}}
{{#isByteArray}}
let body = String::from_utf8(param_body.0).expect("Body was not valid UTF8");
{{/isByteArray}}
{{^isByteArray}}
{{^isByteArray}}
{{^isBinary}}
let body = param_{{{paramName}}};
{{/isByteArray}}
{{/isBinary}}
{{/isByteArray}}
{{#isByteArray}}
let body = String::from_utf8(param_{{{paramName}}}.0).expect("Body was not valid UTF8");
{{/isByteArray}}
{{#isBinary}}
let body = String::from_utf8(param_{{{paramName}}}.0).expect("Body was not valid UTF8");
{{/isBinary}}
{{/x-consumes-plain-text}}
{{#x-consumes-xml}}
let body = param_{{{paramName}}}.as_xml();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@

{{/x-consumes-plain-text}}
{{#x-consumes-plain-text}}
{{#isBinary}}
Some(swagger::ByteArray(body.to_vec()))
{{/isBinary}}
{{#isByteArray}}
Some(swagger::ByteArray(body.to_vec()))
{{/isByteArray}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ paths:
summary: Test a Form Post
operationId: FormTest
requestBody:
required: true
content:
application/x-www-form-urlencoded:
schema:
Expand All @@ -509,7 +510,13 @@ paths:
type: array
items:
type: string
required: true
enum_field:
type: string
enum:
- one_enum
required:
- requiredArray
- enum_field
responses:
'200':
description: OK
Expand Down Expand Up @@ -728,6 +735,9 @@ components:
NullableObject:
type: string
nullable: true
NoTypeObject:
title: an object with no type
description: An object with no type
NullableTest:
type: object
required:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ docs/DuplicateXmlObject.md
docs/EnumWithStarObject.md
docs/Err.md
docs/Error.md
docs/FormTestRequestEnumField.md
docs/Model12345AnyOfObject.md
docs/Model12345AnyOfObjectAnyOf.md
docs/MultigetGet201Response.md
docs/MyId.md
docs/MyIdList.md
docs/NoTypeObject.md
docs/NullableObject.md
docs/NullableTest.md
docs/ObjectHeader.md
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ cargo run --example client XmlOtherPost
cargo run --example client XmlOtherPut
cargo run --example client XmlPost
cargo run --example client XmlPut
cargo run --example client EnumInPathPathParamGet
cargo run --example client MultiplePathParamsWithVeryLongPathToTestFormattingPathParamAPathParamBGet
cargo run --example client CreateRepo
cargo run --example client GetRepoInfo
Expand Down Expand Up @@ -201,11 +202,13 @@ Method | HTTP request | Description
- [EnumWithStarObject](docs/EnumWithStarObject.md)
- [Err](docs/Err.md)
- [Error](docs/Error.md)
- [FormTestRequestEnumField](docs/FormTestRequestEnumField.md)
- [Model12345AnyOfObject](docs/Model12345AnyOfObject.md)
- [Model12345AnyOfObjectAnyOf](docs/Model12345AnyOfObjectAnyOf.md)
- [MultigetGet201Response](docs/MultigetGet201Response.md)
- [MyId](docs/MyId.md)
- [MyIdList](docs/MyIdList.md)
- [NoTypeObject](docs/NoTypeObject.md)
- [NullableObject](docs/NullableObject.md)
- [NullableTest](docs/NullableTest.md)
- [ObjectHeader](docs/ObjectHeader.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,9 @@ components:
NullableObject:
nullable: true
type: string
NoTypeObject:
description: An object with no type
title: an object with no type
NullableTest:
properties:
nullable:
Expand Down Expand Up @@ -847,12 +850,21 @@ components:
anyOf:
- $ref: "#/components/schemas/StringObject"
- $ref: "#/components/schemas/UuidObject"
FormTest_request_enum_field:
enum:
- one_enum
type: string
FormTest_request:
properties:
requiredArray:
items:
type: string
type: array
enum_field:
$ref: "#/components/schemas/FormTest_request_enum_field"
required:
- enum_field
- requiredArray
type: object
AnyOfObject_anyOf:
enum:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ enum Operation {
/// Test a Form Post
FormTest {
#[structopt(parse(try_from_str = parse_json), long)]
required_array: Option<Vec<String>>,
required_array: Vec<String>,
#[structopt(parse(try_from_str = parse_json))]
enum_field: models::FormTestRequestEnumField,
},
GetWithBooleanParameter {
/// Let's check apostrophes get encoded properly!
Expand Down Expand Up @@ -352,11 +354,13 @@ async fn main() -> Result<()> {
}
Operation::FormTest {
required_array,
enum_field,
} => {
info!("Performing a FormTest request");

let result = client.form_test(
required_array.as_ref(),
enum_field,
).await?;
debug!("Result: {:?}", result);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# FormTestRequestEnumField

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# FormTestRequestGrantType

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# NoTypeObject

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


Original file line number Diff line number Diff line change
Expand Up @@ -159,21 +159,15 @@ No authorization required
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)

# **FormTest**
> FormTest(optional)
> FormTest(required_array, enum_field)
Test a Form Post

### Required Parameters

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**optional** | **map[string]interface{}** | optional parameters | nil if no parameters

### Optional Parameters
Optional parameters are passed through a map[string]interface{}.

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**required_array** | [**String**](String.md)| |
**required_array** | [**String**](String.md)| |
**enum_field** | [**FormTest_request_enum_field**](FormTest_request_enum_field.md)| |

### Return type

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ fn main() {
"XmlOtherPut",
"XmlPost",
"XmlPut",
"EnumInPathPathParamGet",
"MultiplePathParamsWithVeryLongPathToTestFormattingPathParamAPathParamBGet",
"CreateRepo",
"GetRepoInfo",
Expand Down Expand Up @@ -197,7 +198,8 @@ fn main() {
},
Some("FormTest") => {
let result = rt.block_on(client.form_test(
Some(&Vec::new())
&Vec::new(),
models::FormTestRequestEnumField::OneEnum
));
info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has<XSpanIdString>).get().clone());
},
Expand Down Expand Up @@ -327,14 +329,12 @@ fn main() {
));
info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has<XSpanIdString>).get().clone());
},
/* Disabled because there's no example.
Some("EnumInPathPathParamGet") => {
let result = rt.block_on(client.enum_in_path_path_param_get(
???
models::StringEnum::Foo
));
info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has<XSpanIdString>).get().clone());
},
*/
Some("MultiplePathParamsWithVeryLongPathToTestFormattingPathParamAPathParamBGet") => {
let result = rt.block_on(client.multiple_path_params_with_very_long_path_to_test_formatting_path_param_a_path_param_b_get(
"path_param_a_example".to_string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,11 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
/// Test a Form Post
async fn form_test(
&self,
required_array: Option<&Vec<String>>,
required_array: &Vec<String>,
enum_field: models::FormTestRequestEnumField,
context: &C) -> Result<FormTestResponse, ApiError>
{
info!("form_test({:?}) - X-Span-ID: {:?}", required_array, context.get().0.clone());
info!("form_test({:?}, {:?}) - X-Span-ID: {:?}", required_array, enum_field, context.get().0.clone());
Err(ApiError("Api-Error: Operation is NOT implemented".into()))
}
async fn get_with_boolean_parameter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,8 @@ impl<S, C> Api<C> for Client<S, C> where
}
async fn form_test(
&self,
param_required_array: Option<&Vec<String>>,
param_required_array: &Vec<String>,
param_enum_field: models::FormTestRequestEnumField,
context: &C) -> Result<FormTestResponse, ApiError>
{
let mut client_service = self.client_service.clone();
Expand Down Expand Up @@ -779,15 +780,17 @@ impl<S, C> Api<C> for Client<S, C> where

// Consumes form body
let mut params = vec![];
if let Some(param_required_array) = param_required_array {
// style=form,explode=true
for param_required_array in param_required_array {
#[allow(clippy::uninlined_format_args)]
params.push(("requiredArray",
format!("{:?}", param_required_array)
));
}
}
#[allow(clippy::uninlined_format_args)]
params.push(("enum_field",
format!("{:?}", param_enum_field)
));

let body = serde_urlencoded::to_string(params).expect("impossible to fail to serialize");

Expand Down
Loading
Loading