Skip to content

Commit 1d83ef0

Browse files
committed
Review markups
1 parent f676ab6 commit 1d83ef0

60 files changed

Lines changed: 273 additions & 210 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,19 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
643643
// Set for deduplication of response IDs
644644
Set<String> responseIds = new HashSet();
645645

646+
// Determine the types that this operation produces overall, so that responses with no
647+
// explicit `content` map (e.g. referencing a schema outside of a media type entry) still
648+
// get a sensible default MIME type rather than none at all.
649+
boolean producesXml = false;
650+
boolean producesPlainText = false;
651+
for (String mimeType : getProducesInfo(openAPI, operation)) {
652+
if (isMimetypeXml(mimeType)) {
653+
producesXml = true;
654+
} else if (isMimetypePlain(mimeType)) {
655+
producesPlainText = true;
656+
}
657+
}
658+
646659
for (CodegenResponse rsp : op.responses) {
647660

648661
// Get the original API response so we get process the schema
@@ -709,9 +722,14 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
709722

710723
if (content.size() > 1) {
711724
buildMultiContentTypeResponse(rsp, content);
712-
} else {
713-
String mimeType = content.isEmpty() ? null : content.keySet().iterator().next();
725+
} else if (content.isEmpty()) {
726+
// No explicit content entry for this response: fall back to the operation's
727+
// overall produces info (XML/plain-text) or default to JSON, rather than leaving
728+
// the response without any MIME type extension.
729+
String mimeType = producesXml ? xmlMimeType : producesPlainText ? plainTextMimeType : jsonMimeType;
714730
processInnerResponse(rsp, mimeType);
731+
} else {
732+
processInnerResponse(rsp, content.keySet().iterator().next());
715733
}
716734

717735
for (CodegenProperty header : rsp.headers) {
@@ -794,16 +812,16 @@ private void buildMultiContentTypeResponse(CodegenResponse rsp, Map<String, Medi
794812
List<Map<String, Object>> variants = new ArrayList<>();
795813
List<String> typeArgs = new ArrayList<>();
796814

815+
// Every content type gets its own OneOf variant slot, even when two content types
816+
// resolve to the same Rust type (e.g. an XML and a JSON variant of the same array/object
817+
// schema): the server's outgoing match needs a distinct variant per content type to know
818+
// which serialization to apply, so merging them into one slot would either drop a
819+
// content type or produce an unreachable/duplicate match arm on the server side.
797820
for (Map.Entry<String, MediaType> entry : content.entrySet()) {
798821
String ct = entry.getKey();
799822
Schema schema = entry.getValue() != null ? entry.getValue().getSchema() : null;
800823
String dataType = computeVariantDataType(schema);
801824
String typeArg = dataType != null ? dataType : "()";
802-
803-
if (typeArgs.contains(typeArg)) {
804-
LOGGER.warn("Response has multiple content types resolving to the same type '{}'; skipping duplicate variant for '{}'.", typeArg, ct);
805-
continue;
806-
}
807825
typeArgs.add(typeArg);
808826

809827
Map<String, Object> exts = new LinkedHashMap<>();

modules/openapi-generator/src/main/resources/rust-server/client-response-body.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
let body = match content_type {
1414
{{/-first}}
15-
Ok("{{{contentType}}}") => {
15+
Ok(ct) if ct.eq_ignore_ascii_case("{{{contentType}}}") => {
1616
{{>client-response-body-variant-instance}}
1717
{{{variantName}}}(body)
1818
},

modules/openapi-generator/src/main/resources/rust-server/model_doc.mustache

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
{{#models}}{{#model}}# {{{classname}}}
22

3+
{{#vars}}
4+
{{#-first}}
35
## Properties
46
Name | Type | Description | Notes
57
------------ | ------------- | ------------- | -------------
6-
{{#vars}}**{{{name}}}** | {{#isPrimitiveType}}**{{{dataType}}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{^isContainer}}{{^isDateTime}}*{{/isDateTime}}{{/isContainer}}{{{dataType}}}**]({{{complexType}}}.md){{/isPrimitiveType}} | {{{description}}} | {{^required}}[optional] {{/required}}{{#isReadOnly}}[readonly] {{/isReadOnly}}{{#defaultValue}}[default to {{{.}}}]{{/defaultValue}}
8+
{{/-first}}
9+
**{{{name}}}** | {{#isPrimitiveType}}**{{{dataType}}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{^isContainer}}{{^isDateTime}}*{{/isDateTime}}{{/isContainer}}{{{dataType}}}**]({{{complexType}}}.md){{/isPrimitiveType}} | {{{description}}} | {{^required}}[optional] {{/required}}{{#isReadOnly}}[readonly] {{/isReadOnly}}{{#defaultValue}}[default to {{{.}}}]{{/defaultValue}}
10+
{{/vars}}
11+
{{^vars}}
12+
## Type
13+
{{#arrayModelType}}**Vec<{{{arrayModelType}}}>**{{/arrayModelType}}{{^arrayModelType}}**{{{dataType}}}**{{/arrayModelType}}
714
{{/vars}}
815

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

modules/openapi-generator/src/test/java/org/openapitools/codegen/rust/RustServerCodegenTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,10 @@ public void testMultipleResponseContentTypes() throws IOException {
145145

146146
// Two-content-type 403 response must use a OneOf2 return type.
147147
TestUtils.assertFileContains(clientModPath, "swagger::OneOf2::<");
148-
// Both variant content types must appear as match arms in the dispatch code.
149-
TestUtils.assertFileContains(clientModPath, "Ok(\"text/plain\")");
150-
TestUtils.assertFileContains(clientModPath, "Ok(\"application/json\")");
148+
// Both variant content types must appear as case-insensitive match arms in the dispatch
149+
// code (HTTP media types are case-insensitive per RFC 7231).
150+
TestUtils.assertFileContains(clientModPath, "ct.eq_ignore_ascii_case(\"text/plain\")");
151+
TestUtils.assertFileContains(clientModPath, "ct.eq_ignore_ascii_case(\"application/json\")");
151152
// Content-Type header must be read for dispatch.
152153
TestUtils.assertFileContains(clientModPath, "CONTENT_TYPE");
153154

samples/server/petstore/rust-server/output/openapi-v3/docs/AdditionalPropertiesReferencedAnyOfObject.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# AdditionalPropertiesReferencedAnyOfObject
22

3-
## Properties
4-
Name | Type | Description | Notes
5-
------------ | ------------- | ------------- | -------------
3+
## Type
4+
**std::collections::HashMap<String, models::AnyOfProperty>**
65

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

samples/server/petstore/rust-server/output/openapi-v3/docs/AdditionalPropertiesWithList.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# AdditionalPropertiesWithList
22

3-
## Properties
4-
Name | Type | Description | Notes
5-
------------ | ------------- | ------------- | -------------
3+
## Type
4+
**std::collections::HashMap<String, Vec<String>>**
65

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

samples/server/petstore/rust-server/output/openapi-v3/docs/AnotherXmlArray.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# AnotherXmlArray
22

3-
## Properties
4-
Name | Type | Description | Notes
5-
------------ | ------------- | ------------- | -------------
3+
## Type
4+
**Vec<String>**
65

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

samples/server/petstore/rust-server/output/openapi-v3/docs/AnotherXmlInner.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# AnotherXmlInner
22

3-
## Properties
4-
Name | Type | Description | Notes
5-
------------ | ------------- | ------------- | -------------
3+
## Type
4+
**String**
65

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

samples/server/petstore/rust-server/output/openapi-v3/docs/AnyOfGet202Response.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# AnyOfGet202Response
22

3-
## Properties
4-
Name | Type | Description | Notes
5-
------------ | ------------- | ------------- | -------------
3+
## Type
4+
**swagger::AnyOf2<models::StringObject,models::UuidObject>**
65

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

samples/server/petstore/rust-server/output/openapi-v3/docs/AnyOfHashMapObject.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# AnyOfHashMapObject
22

3-
## Properties
4-
Name | Type | Description | Notes
5-
------------ | ------------- | ------------- | -------------
3+
## Type
4+
**swagger::AnyOf2<String,std::collections::HashMap<String, String>>**
65

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

0 commit comments

Comments
 (0)