Skip to content

Commit 4454b78

Browse files
Updates on running integration tests - need to handle empty response types as simple enums
1 parent e95ced8 commit 4454b78

File tree

2 files changed

+42
-19
lines changed

2 files changed

+42
-19
lines changed

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

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -541,15 +541,27 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
541541
rsp.vendorExtensions.put("x-response-id", responseId);
542542
}
543543

544-
if (rsp.dataType != null) {
545-
List<String> producesTypes = new ArrayList<>();
544+
List<String> producesTypes = new ArrayList<>();
546545

547-
if (original.getContent() != null) {
548-
producesTypes.addAll(original.getContent().keySet());
549-
}
546+
if (original.getContent() != null) {
547+
producesTypes.addAll(original.getContent().keySet());
548+
}
550549

551-
List<Map<String, Object>> responseContentTypes = new ArrayList<>();
550+
List<Map<String, Object>> responseContentTypes = new ArrayList<>();
552551

552+
// If there are no content types (no body), create a single variant without content
553+
if (producesTypes.isEmpty()) {
554+
Map<String, Object> contentTypeInfo = new HashMap<>();
555+
556+
// Use the response-id directly as the variant name for responses without content
557+
if (rsp.vendorExtensions.containsKey("x-response-id")) {
558+
String baseId = (String) rsp.vendorExtensions.get("x-response-id");
559+
contentTypeInfo.put("x-variant-name", baseId);
560+
}
561+
562+
responseContentTypes.add(contentTypeInfo);
563+
} else {
564+
// Process each content type
553565
for (String contentType : producesTypes) {
554566
Map<String, Object> contentTypeInfo = new HashMap<>();
555567
contentTypeInfo.put("mediaType", contentType);
@@ -576,11 +588,7 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
576588
} else {
577589
// Everything else is plain-text
578590
contentTypeInfo.put("x-content-suffix", "PlainText");
579-
if (bytesType.equals(rsp.dataType)) {
580-
contentTypeInfo.put("x-serializer-bytes", true);
581-
} else {
582-
contentTypeInfo.put("x-serializer-plain", true);
583-
}
591+
// Note: serializer flags will be set after determining the actual body type
584592
}
585593

586594
// Group together the x-response-id and x-content-suffix created above in order to produce
@@ -599,6 +607,9 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
599607
bodyType = stringType;
600608
} else if (contentTypeInfo.get("x-output-mime-type").equals(plainTextMimeType)) {
601609
bodyType = bytesType.equals(rsp.dataType) ? bytesType : stringType;
610+
} else if (contentTypeInfo.get("x-output-mime-type").equals(octetMimeType)) {
611+
// For octet-stream, always use ByteArray
612+
bodyType = bytesType;
602613
} else if (contentTypeInfo.get("x-output-mime-type").equals(eventStreamMimeType)) {
603614
Schema<?> ctSchema = Optional.ofNullable(original.getContent())
604615
.map(c -> c.get(contentType))
@@ -619,14 +630,26 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
619630
bodyType = stringType;
620631
}
621632
contentTypeInfo.put("x-body-type", bodyType);
633+
contentTypeInfo.put("dataType", bodyType); // Also set dataType for template conditionals
634+
635+
// Set serializer flags based on the actual body type for plain-text/octet-stream
636+
if (!contentTypeInfo.containsKey("x-serializer-json") &&
637+
!contentTypeInfo.containsKey("x-serializer-form") &&
638+
!contentTypeInfo.containsKey("x-serializer-event-stream")) {
639+
if (bytesType.equals(bodyType)) {
640+
contentTypeInfo.put("x-serializer-bytes", true);
641+
} else {
642+
contentTypeInfo.put("x-serializer-plain", true);
643+
}
644+
}
622645
}
623646

624647
responseContentTypes.add(contentTypeInfo);
625648
}
626-
627-
rsp.vendorExtensions.put("x-response-content-types", responseContentTypes);
628649
}
629650

651+
rsp.vendorExtensions.put("x-response-content-types", responseContentTypes);
652+
630653
for (CodegenProperty header : rsp.headers) {
631654
if (uuidType.equals(header.dataType)) {
632655
additionalProperties.put("apiUsesUuid", true);

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,10 @@ let result = api_impl.as_ref().{{#vendorExtensions}}{{{x-operation-id}}}{{/vendo
293293
{{#x-response-content-types}}
294294
apis::{{classFilename}}::{{{operationId}}}Response::{{{x-variant-name}}}
295295
{{#dataType}}
296-
{{^hasHeaders}}
296+
{{^headers}}
297297
(body)
298-
{{/hasHeaders}}
299-
{{#hasHeaders}}
298+
{{/headers}}
299+
{{#headers}}
300300
{{#-first}}
301301
{
302302
body,
@@ -305,18 +305,18 @@ let result = api_impl.as_ref().{{#vendorExtensions}}{{{x-operation-id}}}{{/vendo
305305
{{#-last}}
306306
}
307307
{{/-last}}
308-
{{/hasHeaders}}
308+
{{/headers}}
309309
{{/dataType}}
310310
{{^dataType}}
311-
{{#hasHeaders}}
311+
{{#headers}}
312312
{{#-first}}
313313
{
314314
{{/-first}}
315315
{{{name}}}{{^-last}},{{/-last}}
316316
{{#-last}}
317317
}
318318
{{/-last}}
319-
{{/hasHeaders}}
319+
{{/headers}}
320320
{{/dataType}}
321321
=> {
322322
{{#dataType}}

0 commit comments

Comments
 (0)