Skip to content

Fixing multiple problems with SpringCodegen when activating ServerSentEvents #20658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .github/workflows/samples-spring-jdk17.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ on:
- samples/server/petstore/springboot-lombok-data
- samples/server/petstore/springboot-lombok-tostring
- samples/server/petstore/springboot-file-delegate-optional
- samples/server/petstore/springboot-reactive-serverSentEvents
pull_request:
paths:
- samples/openapi3/client/petstore/spring-cloud-3-with-optional
- samples/openapi3/server/petstore/springboot-3
- samples/server/petstore/springboot-lombok-data
- samples/server/petstore/springboot-lombok-tostring
- samples/server/petstore/springboot-file-delegate-optional
- samples/server/petstore/springboot-reactive-serverSentEvents
jobs:
build:
name: Build Java Spring (JDK17)
Expand All @@ -30,6 +32,7 @@ jobs:
- samples/server/petstore/springboot-lombok-data
- samples/server/petstore/springboot-lombok-tostring
- samples/server/petstore/springboot-file-delegate-optional
- samples/server/petstore/springboot-reactive-serverSentEvents
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/samples-spring.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ jobs:
- samples/server/petstore/springboot-lombok-data
- samples/server/petstore/springboot-reactive
- samples/server/petstore/springboot-reactive-noResponseEntity
- samples/server/petstore/springboot-reactive-serverSentEvents
- samples/server/petstore/springboot-spring-pageable-delegatePattern-without-j8
- samples/server/petstore/springboot-spring-pageable-delegatePattern
- samples/server/petstore/springboot-spring-pageable-without-j8
Expand Down
12 changes: 12 additions & 0 deletions bin/configs/spring-boot-reactive-serverSentEvents.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
generatorName: spring
outputDir: samples/server/petstore/springboot-reactive-serverSentEvents
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

@kgeilmann kgeilmann Feb 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

Fixed the email as well, thanks for pointing it out

inputSpec: modules/openapi-generator/src/test/resources/3_0/spring/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/JavaSpring
additionalProperties:
groupId: org.openapitools.openapi3
artifactId: springboot-reactive-serverSentEvents
documentationProvider: springfox
reactive: "true"
hideGenerationTimestamp: "true"
delegatePattern: "true"
serverSentEvents: "true"
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,18 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
List<CodegenOperation> operations = objectMap.getOperation();
for (CodegenOperation operation : operations) {
if (operation.pathParams != null && operation.pathParams.size() > 0) {

// For types with `isAnyType` we assume it's a `serde_json::Value` type.
// However for path, query, and headers it's unlikely to be JSON so we default to `String`.
// Note that we keep the default `serde_json::Value` for body parameters.
for (var param : operation.allParams) {
if (param.isAnyType && (param.isPathParam || param.isQueryParam || param.isHeaderParam)) {
param.dataType = "String";
param.isPrimitiveType = true;
param.isString = true;
}
}

for (var pathParam : operation.pathParams) {
if (!pathParam.baseName.contains("-")) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import org.openapitools.codegen.templating.mustache.SplitStringLambda;
import org.openapitools.codegen.templating.mustache.SpringHttpStatusLambda;
import org.openapitools.codegen.templating.mustache.TrimWhitespaceLambda;
import org.openapitools.codegen.utils.ModelUtils;
import org.openapitools.codegen.utils.ProcessUtils;
import org.openapitools.codegen.utils.URLPathUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -1033,18 +1034,19 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
content:
text/event-stream:
schema:
type: array
format: event-stream
items:
type: <type> or
$ref: <typeRef>
type: array
format: event-stream
items:
type: <type> or
$ref: <typeRef>
*/
Map<String, List<Schema>> schemaTypes = operation.getResponses().entrySet().stream()
.filter(p -> p.getValue().getContent() != null || p.getValue().get$ref() != null)
.map(e -> Pair.of(e.getValue(), fromResponse(e.getKey(), e.getValue())))
.filter(p -> p.getRight().is2xx) // consider only success
.map(p -> p.getLeft().getContent().get(MEDIA_EVENT_STREAM))
.map(MediaType::getSchema)
.collect(Collectors.toList()).stream()
.filter(Objects::nonNull)
.map(s -> ModelUtils.unaliasSchema(openAPI, s.getSchema()))
.collect(Collectors.groupingBy(Schema::getType));
if(schemaTypes.containsKey("array")) {
// we have a match with SSE pattern
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@

<build>
<sourceDirectory>src/main/java</sourceDirectory>
{{^interfaceOnly}}
<plugins>
{{^interfaceOnly}}
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
Expand All @@ -76,6 +76,21 @@
{{/lombok}}
</configuration>
</plugin>
{{/interfaceOnly}}
{{#interfaceOnly}}
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
{{/interfaceOnly}}
{{#apiFirst}}
<plugin>
<groupId>org.openapitools</groupId>
Expand Down Expand Up @@ -109,7 +124,6 @@
</plugin>
{{/apiFirst}}
</plugins>
{{/interfaceOnly}}
</build>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
{{/parentOverridden}}
<build>
<sourceDirectory>src/main/java</sourceDirectory>
{{^interfaceOnly}}
<plugins>
{{^interfaceOnly}}
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
Expand All @@ -69,6 +69,21 @@
{{/lombok}}
</configuration>
</plugin>
{{/interfaceOnly}}
{{#interfaceOnly}}
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
{{/interfaceOnly}}
{{#apiFirst}}
<plugin>
<groupId>org.openapitools</groupId>
Expand Down Expand Up @@ -102,7 +117,6 @@
</plugin>
{{/apiFirst}}
</plugins>
{{/interfaceOnly}}
</build>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@

<build>
<sourceDirectory>src/main/java</sourceDirectory>
{{#interfaceOnly}}<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>{{/interfaceOnly}}
</build>

{{^parentOverridden}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@
{{/parentOverridden}}
<build>
<sourceDirectory>src/main/java</sourceDirectory>
{{#interfaceOnly}}<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>{{/interfaceOnly}}
</build>

{{^parentOverridden}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@
</execution>
</executions>
</plugin>{{/interfaceOnly}}
{{#interfaceOnly}}<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>{{/interfaceOnly}}
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@
</execution>
</executions>
</plugin>{{/interfaceOnly}}
{{#interfaceOnly}}<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>{{/interfaceOnly}}
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@
</execution>
</executions>
</plugin>{{/interfaceOnly}}
{{#interfaceOnly}}<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>{{/interfaceOnly}}
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@
</execution>
</executions>
</plugin>{{/interfaceOnly}}
{{#interfaceOnly}}<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>{{/interfaceOnly}}
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
Expand Down
Loading
Loading