Open piglingcn opened 6 years ago
I guess your question refers to a java backend (spring or jaxrs) and you are calling the URL that displays the spec corresponding to the running server.
The answer is no.
Explanation: Javadoc is a comment in the code and the JVM can not access it at runtime.
Have you a lot of those?
I guess writing a small tool that copy Javadoc content into the @apioperation
and @apiresponses
annotation could a good solution...
it should avoid duplicate info it should do it in an intrusive way it does not have not be at runtime
I have a prototype for a solution to this problem, which is to define an annotation processor that replaces a string argument of a particular annotation with the Javadoc comment of the element that has the annotation. In the case of OpenAPI, the annotation would be @Operation
and the argument would be description
. For an OpenAPI specification to be generated that has method Javadoc injected into the "description"
field, that annotation processor has to be specified when the application is compiled. For example, the application would have the following snippet in pom.xml
:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<annotationProcessors>
<annotationProcessor>io.swagger.annotations.processor.JavadocCommentProcessor</annotationProcessor>
</annotationProcessors>
</configuration>
</plugin>
</plugins>
</build>
I too would like to see a way to do this. I understand what @jmini is saying but @adriansuarez approach seems logical to me. Perhaps it could be packaged with the swagger dependency?
+1 for adding a way to use the JavaDoc instead of annotations in Swagger. When company policy requires adding JavaDoc to every method, the Swagger annotations end up being simple duplicates of this code. They are also less readable than JavaDoc, being mixed with the rest of the code.
my question is can I use the Javadocs instead of making every developer to create @ApiOperation & @ApiResponses so that it saves time for my team?