File tree Expand file tree Collapse file tree 8 files changed +48
-11
lines changed
modules/openapi-generator/src
main/java/org/openapitools/codegen/languages
test/resources/3_0/rust-server
samples/server/petstore/rust-server/output/openapi-v3 Expand file tree Collapse file tree 8 files changed +48
-11
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,7 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
69
69
private static final String bytesType = "swagger::ByteArray" ;
70
70
71
71
private static final String xmlMimeType = "application/xml" ;
72
+ private static final String textXmlMimeType = "text/xml" ;
72
73
private static final String octetMimeType = "application/octet-stream" ;
73
74
private static final String plainMimeType = "text/plain" ;
74
75
private static final String jsonMimeType = "application/json" ;
@@ -521,7 +522,8 @@ public String escapeUnsafeCharacters(String input) {
521
522
}
522
523
523
524
private boolean isMimetypeXml (String mimetype ) {
524
- return mimetype .toLowerCase (Locale .ROOT ).startsWith (xmlMimeType );
525
+ return mimetype .toLowerCase (Locale .ROOT ).startsWith (xmlMimeType ) ||
526
+ mimetype .toLowerCase (Locale .ROOT ).startsWith (textXmlMimeType );
525
527
}
526
528
527
529
private boolean isMimetypePlainText (String mimetype ) {
Original file line number Diff line number Diff line change @@ -99,12 +99,16 @@ paths:
99
99
post :
100
100
requestBody :
101
101
content :
102
- application /xml :
102
+ text /xml :
103
103
schema :
104
104
$ref : ' #/components/schemas/anotherXmlObject'
105
105
responses :
106
106
' 201 ' :
107
107
description : ' OK'
108
+ content :
109
+ text/xml :
110
+ schema :
111
+ $ref : " #/components/schemas/anotherXmlObject"
108
112
' 400 ' :
109
113
description : Bad Request
110
114
put :
Original file line number Diff line number Diff line change @@ -81,11 +81,15 @@ paths:
81
81
post :
82
82
requestBody :
83
83
content :
84
- application /xml :
84
+ text /xml :
85
85
schema :
86
86
$ref : ' #/components/schemas/anotherXmlObject'
87
87
responses :
88
88
" 201 " :
89
+ content :
90
+ text/xml :
91
+ schema :
92
+ $ref : ' #/components/schemas/anotherXmlObject'
89
93
description : OK
90
94
" 400 " :
91
95
description : Bad Request
Original file line number Diff line number Diff line change @@ -185,7 +185,7 @@ No authorization required
185
185
[[ 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 )
186
186
187
187
# *** *
188
- > (optional)
188
+ > models::AnotherXmlObject (optional)
189
189
190
190
191
191
### Required Parameters
@@ -203,16 +203,16 @@ Name | Type | Description | Notes
203
203
204
204
### Return type
205
205
206
- (empty response body )
206
+ [ ** models::AnotherXmlObject ** ] ( anotherXmlObject.md )
207
207
208
208
### Authorization
209
209
210
210
No authorization required
211
211
212
212
### HTTP request headers
213
213
214
- - ** Content-Type** : application /xml
215
- - ** Accept** : Not defined
214
+ - ** Content-Type** : text /xml
215
+ - ** Accept** : text/xml,
216
216
217
217
[[ 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 )
218
218
Original file line number Diff line number Diff line change @@ -936,10 +936,22 @@ impl<F, C> Api<C> for Client<F> where
936
936
201 => {
937
937
let body = response. body ( ) ;
938
938
Box :: new (
939
-
940
- future:: ok (
941
- XmlOtherPostResponse :: OK
939
+ body
940
+ . concat2 ( )
941
+ . map_err ( |e| ApiError ( format ! ( "Failed to read response: {}" , e) ) )
942
+ . and_then ( |body|
943
+ str:: from_utf8 ( & body)
944
+ . map_err ( |e| ApiError ( format ! ( "Response was not valid UTF8: {}" , e) ) )
945
+ . and_then ( |body|
946
+ // ToDo: this will move to swagger-rs and become a standard From conversion trait
947
+ // once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
948
+ serde_xml_rs:: from_str :: < models:: AnotherXmlObject > ( body)
949
+ . map_err ( |e| ApiError ( format ! ( "Response body did not match the schema: {}" , e) ) )
950
+ )
942
951
)
952
+ . map ( move |body| {
953
+ XmlOtherPostResponse :: OK ( body)
954
+ } )
943
955
) as Box < dyn Future < Item =_ , Error =_ > >
944
956
} ,
945
957
400 => {
Original file line number Diff line number Diff line change @@ -137,6 +137,7 @@ pub enum XmlExtraPostResponse {
137
137
pub enum XmlOtherPostResponse {
138
138
/// OK
139
139
OK
140
+ ( models:: AnotherXmlObject )
140
141
,
141
142
/// Bad Request
142
143
BadRequest
Original file line number Diff line number Diff line change @@ -50,6 +50,11 @@ pub mod responses {
50
50
pub static ref UUID_GET_DUPLICATE_RESPONSE_LONG_TEXT : Mime = "application/json" . parse( ) . unwrap( ) ;
51
51
}
52
52
53
+ lazy_static ! {
54
+ /// Create Mime objects for the response content types for XmlOtherPost
55
+ pub static ref XML_OTHER_POST_OK : Mime = "text/xml" . parse( ) . unwrap( ) ;
56
+ }
57
+
53
58
}
54
59
55
60
pub mod requests {
@@ -67,7 +72,7 @@ pub mod requests {
67
72
68
73
lazy_static ! {
69
74
/// Create Mime objects for the request content types for XmlOtherPost
70
- pub static ref XML_OTHER_POST : Mime = "application /xml" . parse( ) . unwrap( ) ;
75
+ pub static ref XML_OTHER_POST : Mime = "text /xml" . parse( ) . unwrap( ) ;
71
76
}
72
77
73
78
lazy_static ! {
Original file line number Diff line number Diff line change @@ -637,10 +637,19 @@ where
637
637
Ok ( rsp) => match rsp {
638
638
XmlOtherPostResponse :: OK
639
639
640
+ ( body)
641
+
640
642
641
643
=> {
642
644
response. set_status ( StatusCode :: try_from ( 201 ) . unwrap ( ) ) ;
643
645
646
+ response. headers_mut ( ) . set ( ContentType ( mimetypes:: responses:: XML_OTHER_POST_OK . clone ( ) ) ) ;
647
+
648
+ let mut namespaces = BTreeMap :: new ( ) ;
649
+ // An empty string is used to indicate a global namespace in xmltree.
650
+ namespaces. insert ( "" . to_string ( ) , models:: AnotherXmlObject :: NAMESPACE . to_string ( ) ) ;
651
+ let body = serde_xml_rs:: to_string_with_namespaces ( & body, namespaces) . expect ( "impossible to fail to serialize" ) ;
652
+ response. set_body ( body) ;
644
653
} ,
645
654
XmlOtherPostResponse :: BadRequest
646
655
You can’t perform that action at this time.
0 commit comments