Skip to content

Commit 4419a01

Browse files
committed
fix imports
1 parent 965a5ce commit 4419a01

7 files changed

Lines changed: 41 additions & 38 deletions

File tree

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

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,6 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
10581058
// add org.springframework.format.annotation.DateTimeFormat when needed
10591059
codegenOperation.allParams.stream().filter(p -> p.isDate || p.isDateTime).findFirst()
10601060
.ifPresent(p -> codegenOperation.imports.add("DateTimeFormat"));
1061-
10621061
// add org.springframework.data.domain.Pageable import when needed
10631062
if (codegenOperation.vendorExtensions.containsKey("x-spring-paginated")) {
10641063
codegenOperation.imports.add("Pageable");
@@ -1084,13 +1083,12 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
10841083

10851084
addSpringNullableImportForOperation(codegenOperation);
10861085

1087-
if (reactive) {
1088-
if (DocumentationProvider.SPRINGFOX.equals(getDocumentationProvider())) {
1089-
codegenOperation.imports.add("ApiIgnore");
1090-
}
1091-
if (sse) {
1092-
var MEDIA_EVENT_STREAM = "text/event-stream";
1093-
// inspecting used streaming media types
1086+
if (includeHttpRequestContext && DocumentationProvider.SPRINGFOX.equals(getDocumentationProvider())) {
1087+
codegenOperation.imports.add("ApiIgnore");
1088+
}
1089+
if (reactive && sse) {
1090+
var MEDIA_EVENT_STREAM = "text/event-stream";
1091+
// inspecting used streaming media types
10941092
/*
10951093
expected definition:
10961094
content:
@@ -1102,36 +1100,35 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
11021100
type: <type> or
11031101
$ref: <typeRef>
11041102
*/
1105-
Map<String, List<Schema>> schemaTypes = operation.getResponses().entrySet().stream()
1106-
.map(e -> Pair.of(e.getValue(), fromResponse(e.getKey(), e.getValue())))
1107-
.filter(p -> p.getRight().is2xx) // consider only success
1108-
.map(p -> p.getLeft().getContent().get(MEDIA_EVENT_STREAM))
1109-
.map(MediaType::getSchema)
1110-
.collect(Collectors.toList()).stream()
1111-
.collect(Collectors.groupingBy(Schema::getType));
1112-
if (schemaTypes.containsKey("array")) {
1113-
// we have a match with SSE pattern
1114-
// double check potential conflicting, multiple specs
1115-
if (schemaTypes.keySet().size() > 1) {
1116-
throw new RuntimeException("only 1 response media type supported, when SSE is detected");
1117-
}
1118-
// double check schema format
1119-
List<Schema> eventTypes = schemaTypes.get("array");
1120-
if (eventTypes.stream().anyMatch(schema -> !"event-stream".equalsIgnoreCase(schema.getFormat()))) {
1121-
throw new RuntimeException("schema format 'event-stream' is required, when SSE is detected");
1122-
}
1123-
// double check item types
1124-
Set<String> itemTypes = eventTypes.stream()
1125-
.map(schema -> schema.getItems().getType() != null
1126-
? schema.getItems().getType()
1127-
: schema.getItems().get$ref())
1128-
.collect(Collectors.toSet());
1129-
if (itemTypes.size() > 1) {
1130-
throw new RuntimeException("only single item type is supported, when SSE is detected");
1131-
}
1132-
codegenOperation.vendorExtensions.put("x-sse", true);
1133-
} // Not an SSE compliant definition
1134-
}
1103+
Map<String, List<Schema>> schemaTypes = operation.getResponses().entrySet().stream()
1104+
.map(e -> Pair.of(e.getValue(), fromResponse(e.getKey(), e.getValue())))
1105+
.filter(p -> p.getRight().is2xx) // consider only success
1106+
.map(p -> p.getLeft().getContent().get(MEDIA_EVENT_STREAM))
1107+
.map(MediaType::getSchema)
1108+
.collect(Collectors.toList()).stream()
1109+
.collect(Collectors.groupingBy(Schema::getType));
1110+
if (schemaTypes.containsKey("array")) {
1111+
// we have a match with SSE pattern
1112+
// double check potential conflicting, multiple specs
1113+
if (schemaTypes.keySet().size() > 1) {
1114+
throw new RuntimeException("only 1 response media type supported, when SSE is detected");
1115+
}
1116+
// double check schema format
1117+
List<Schema> eventTypes = schemaTypes.get("array");
1118+
if (eventTypes.stream().anyMatch(schema -> !"event-stream".equalsIgnoreCase(schema.getFormat()))) {
1119+
throw new RuntimeException("schema format 'event-stream' is required, when SSE is detected");
1120+
}
1121+
// double check item types
1122+
Set<String> itemTypes = eventTypes.stream()
1123+
.map(schema -> schema.getItems().getType() != null
1124+
? schema.getItems().getType()
1125+
: schema.getItems().get$ref())
1126+
.collect(Collectors.toSet());
1127+
if (itemTypes.size() > 1) {
1128+
throw new RuntimeException("only single item type is supported, when SSE is detected");
1129+
}
1130+
codegenOperation.vendorExtensions.put("x-sse", true);
1131+
} // Not an SSE compliant definition
11351132
}
11361133
return codegenOperation;
11371134
}

samples/server/petstore/springboot-include-http-request-context/src/main/java/org/openapitools/api/AnotherFakeApi.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
package org.openapitools.api;
77

8+
import springfox.documentation.annotations.ApiIgnore;
89
import org.openapitools.model.ClientDto;
910
import io.swagger.annotations.*;
1011
import org.springframework.http.HttpStatus;

samples/server/petstore/springboot-include-http-request-context/src/main/java/org/openapitools/api/FakeApi.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
package org.openapitools.api;
77

8+
import springfox.documentation.annotations.ApiIgnore;
89
import org.openapitools.model.ApiResponseDto;
910
import java.math.BigDecimal;
1011
import org.openapitools.model.ChildWithNullableDto;

samples/server/petstore/springboot-include-http-request-context/src/main/java/org/openapitools/api/FakeClassnameTestApi.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
package org.openapitools.api;
77

8+
import springfox.documentation.annotations.ApiIgnore;
89
import org.openapitools.model.ClientDto;
910
import io.swagger.annotations.*;
1011
import org.springframework.http.HttpStatus;

samples/server/petstore/springboot-include-http-request-context/src/main/java/org/openapitools/api/PetApi.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
package org.openapitools.api;
77

8+
import springfox.documentation.annotations.ApiIgnore;
89
import org.openapitools.model.ApiResponseDto;
910
import org.springframework.lang.Nullable;
1011
import org.openapitools.model.PetDto;

samples/server/petstore/springboot-include-http-request-context/src/main/java/org/openapitools/api/StoreApi.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
package org.openapitools.api;
77

8+
import springfox.documentation.annotations.ApiIgnore;
89
import java.util.Map;
910
import org.openapitools.model.OrderDto;
1011
import io.swagger.annotations.*;

samples/server/petstore/springboot-include-http-request-context/src/main/java/org/openapitools/api/UserApi.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
package org.openapitools.api;
77

8+
import springfox.documentation.annotations.ApiIgnore;
89
import java.time.OffsetDateTime;
910
import org.openapitools.model.UserDto;
1011
import io.swagger.annotations.*;

0 commit comments

Comments
 (0)