-
-
Notifications
You must be signed in to change notification settings - Fork 7k
[Java][SSE] Replacing ApiResponse reference by the corresponding ApiResponse object #17273
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
Conversation
CC @wing328 |
operation.getResponses().put(key, ModelUtils.getReferencedApiResponse(openAPI, apiResponse)); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@axel7083 thanks for the PR. Should the fix be done in the default codegen to get the referenced response component/schema correctly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, I think I might have fixed it in the latest master.
Can you please give it a try with the latest master?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, sadly I get the same error.
Exception: Cannot invoke "io.swagger.v3.oas.models.media.Content.get(Object)" because the return value of "io.swagger.v3.oas.models.responses.ApiResponse.getContent()" is null
at org.openapitools.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:1340)
at org.openapitools.codegen.DefaultGenerator.processPaths(DefaultGenerator.java:1234)
at org.openapitools.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:608)
at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:1065)
at org.openapitools.codegen.java.spring.SpringCodegenTest.testSSEOperationSupport(SpringCodegenTest.java:3235)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:577)
at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:135)
at org.testng.internal.invokers.TestInvoker.invokeMethod(TestInvoker.java:673)
at org.testng.internal.invokers.TestInvoker.invokeTestMethod(TestInvoker.java:220)
at org.testng.internal.invokers.MethodRunner.runInSequence(MethodRunner.java:50)
at org.testng.internal.invokers.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:945)
at org.testng.internal.invokers.TestInvoker.invokeTestMethods(TestInvoker.java:193)
at org.testng.internal.invokers.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:128)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.testng.TestRunner.privateRun(TestRunner.java:808)
at org.testng.TestRunner.run(TestRunner.java:603)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:429)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:423)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:383)
at org.testng.SuiteRunner.run(SuiteRunner.java:326)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:95)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1249)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.runSuites(TestNG.java:1092)
at org.testng.TestNG.run(TestNG.java:1060)
at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:105)
Caused by: java.lang.NullPointerException: Cannot invoke "io.swagger.v3.oas.models.media.Content.get(Object)" because the return value of "io.swagger.v3.oas.models.responses.ApiResponse.getContent()" is null
at org.openapitools.codegen.languages.SpringCodegen.lambda$fromOperation$16(SpringCodegen.java:1280)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1845)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
at org.openapitools.codegen.languages.SpringCodegen.fromOperation(SpringCodegen.java:1282)
at org.openapitools.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:1308)
... 29 more
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can find in https://github.com/OpenAPITools/openapi-generator/blob/2129b759a31bc1b22e84728053f5fed7fe137990/modules/openapi-generator/src/test/resources/3_0/sse.yaml the file including the failing test on the latest master
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did a test with the following using the latest master
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g spring -i https://raw.githubusercontent.com/OpenAPITools/openapi-generator/2129b759a31bc1b22e84728053f5fed7fe137990/modules/openapi-generator/src/test/resources/3_0/sse.yaml -o /tmp/spring -c /tmp/config.json
and the output compiles without issues
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the snapshot version of the latest master can be found in https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/7.2.0-SNAPSHOT/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
happy to reopen this PR if needed. closing it for the time being
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot reopen
2129b75
to
a51a0eb
Compare
@wing328 sorry for the late response, I am reopening since I cannot understand one major issue, which is the difference of output between the direct java command, and the tests method Scenarios
When directly compiling the .jar and using with the java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g spring -i modules/openapi-generator/src/test/resources/3_0/sse.yaml -o ./tmp/spring -c ./tmp/config.json However, when using running the test method, we get the error I tried to fix in the PR. The problems seems to be, when running the test, the content of the operation do not seems to be normalised/format properly, the $ref is not replace by the corresponding content (as it should?). mvn -Dorg.openapitools.codegen.java.spring.SpringCodegenTest#testSSEOperationSupport test Here some interesting stuff I fund while comparing both with debug mode. When the generate method is called we can see a very distinct difference between the
Line 1195 in 9eb5882
Configuration file
{
"library": "spring-boot",
"interfaceOnly": "false",
"serverSentEvents": "true",
"delegatePattern": "true",
"reactive": "true"
}
openapi: 3.0.1
info:
title: SSE test
description: SSE test cases
version: 1.0.0
servers:
- url: 'https'
tags:
- name: sse
paths:
/path/variant4:
post:
operationId: sseVariant4
tags:
- sse
responses:
'200':
$ref: '#/components/responses/EventTypeResponse'
components:
schemas:
EventType:
type: object
properties:
attribute1:
type: string
responses:
EventTypeResponse:
description: acknowledged
content:
text/event-stream:
schema:
type: array
format: event-stream
items:
$ref: '#/components/schemas/EventType' |
…nd instantiate the generator. This fixes the different behavior between Test and CLI seen in OpenAPITools#17273 (comment)
…nd instantiate the generator. This fixes the different behavior between Test and CLI seen in OpenAPITools#17273 (comment)
Fixes #17271
This PR is adding a test case that is currently failing in the current context.
The problems come from the following line which is directly getting the content of the ApiResponse, when it can and is allowed to be a reference. Thus leading to a Null Pointer Exception
openapi-generator/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java
Line 1285 in 4a0ab21
This can be fixed, by replacing the ApiResponse reference by their corresponding ApiResponse in the
processOperation
method.