Skip to content

Commit

Permalink
using the generated openapi doc in swagger-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
liweinan committed Nov 12, 2024
1 parent 8582448 commit 7ebd335
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 15 deletions.
48 changes: 39 additions & 9 deletions servlet/resteasy-wildfly-spring-boot-sample-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

<properties>
<version.eclipse.microprofile.openapi>3.1.1</version.eclipse.microprofile.openapi>
<swagger.version>2.2.25</swagger.version>
<version.springdoc>2.6.0</version.springdoc>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -87,19 +89,23 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- MP OpenAPI -->
<!-- <dependency>-->
<!-- <groupId>org.eclipse.microprofile.openapi</groupId>-->
<!-- <artifactId>microprofile-openapi-api</artifactId>-->
<!-- <version>${version.eclipse.microprofile.openapi}</version>-->
<!-- <scope>provided</scope>-->
<!-- </dependency>-->
<!-- springdoc ui -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.6.0</version>
<version>${version.springdoc}</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
<version>${version.springdoc}</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>${swagger.version}</version>
</dependency>

</dependencies>

<build>
Expand All @@ -109,7 +115,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.2</version>
</plugin>
</plugins>
</pluginManagement>
Expand All @@ -121,6 +126,31 @@
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<!-- see https://github.com/swagger-api/swagger-core/tree/master/modules/swagger-maven-plugin -->
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-maven-plugin-jakarta</artifactId>
<version>${swagger.version}</version>
<configuration>
<outputFileName>openapi</outputFileName>
<!-- https://springdoc.org/faq.html#_how_can_use_custom_jsonyml_file_instead_of_generated_one-->
<outputPath>${project.build.directory}/classes/static</outputPath>
<outputFormat>JSONANDYAML</outputFormat>
<resourcePackages>
<package>com.sample.app</package>
</resourcePackages>
<prettyPrint>true</prettyPrint>
<alwaysResolveAppPath>true</alwaysResolveAppPath>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>resolve</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.sample.app;

//import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import io.swagger.v3.oas.annotations.responses.ApiResponse;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;

Expand All @@ -14,7 +14,8 @@ public class HelloResource {
@Autowired
EchoBean bean;

// @APIResponse(description = "return hello world")
@Operation
@ApiResponse(description = "return hello world")
@GET
public String get() {
return bean.echo("Hello, world!");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.sample.app;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.info.Info;
import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;
//import org.eclipse.microprofile.openapi.annotations.OpenAPIDefinition;
//import org.eclipse.microprofile.openapi.annotations.info.Info;

@OpenAPIDefinition(info = @Info(title = "my-rest-app", description = "My Rest App", version = "1.0.0"))
@ApplicationPath("/rest")
//@OpenAPIDefinition(info = @Info(title = "RestApp", version = "1.0.0"))
public class RestApp extends Application {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.sample.app;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.info.Info;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ resteasy:
app:
registration: property
classes: com.sample.app.RestApp
springdoc:
swagger-ui:
url: "/openapi.json"

0 comments on commit 7ebd335

Please sign in to comment.