У меня проблема с получением документации по чванству. Я сделал конфигурацию на основе:
https://synaptiklabs.com/posts/adding-swagger-to-a-javaee-project-javaee-series-2-part-2/
пом. xml:
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jaxrs</artifactId>
<version>1.5.0</version>
</dependency>
...
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${version.war.plugin}</version>
<configuration>
<!-- Java EE 7 doesn't require web.xml, Maven needs to catch up! -->
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<!-- The WildFly plugin deploys your war to a local WildFly container -->
<!-- To use, run: mvn package wildfly:deploy -->
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>${version.wildfly.maven.plugin}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>swagger-ui</id>
<phase>prepare-package</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<skipCache>false</skipCache>
<url>https://github.com/swagger-api/swagger-ui/archive/master.tar.gz</url>
<unpack>true</unpack>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>target/${build.finalName}/docs</outputDirectory>
<resources>
<resource>
<directory>${project.build.directory}/swagger-ui-master/dist</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<executions>
<execution>
<id>replace-swagger-json-location</id>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<file>${project.build.directory}/${build.finalName}/docs/index.html</file>
<replacements>
<replacement>
<token>https://petstore.swagger.io/v2/swagger.json</token>
<value>/rest-api/swagger.json</value>
</replacement>
</replacements>
</configuration>
</plugin>
</plugins>
</build>
Класс приложения:
@ApplicationPath("/")
public class StudentServiceApp extends Application {
public StudentServiceApp() {
init();
}
private void init() {
// Swagger class that holds its configuration
BeanConfig beanConfig = new BeanConfig();
beanConfig.setVersion("1.0.2");
beanConfig.setSchemes(new String[] {"http"});
beanConfig.setHost("localhost:8080");
beanConfig.setBasePath("/rest-api");
beanConfig.setResourcePackage("pl.edu.agh.soa.rest");
beanConfig.setTitle("Student service documentation");
beanConfig.setScan(true);
}
}
Служба:
@Api(value = "Student Service")
@Path("students")
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
public class StudentService {
@Inject
private StudentList students;
@GET
@Path("/")
@ApiOperation(value = "Retrieve all students")
public Response getStudents(@QueryParam("course") String course,
@QueryParam("firstName") String firstName) {
List<Student> filteredStudents = students.filter(course, firstName);
return Response.ok(filteredStudents).status(Response.Status.OK).variant(null).build();
}
}
После развертывания с помощью mvn clean install wildfly:deploy
я могу видеть сваггер. json по адресу: http://localhost: 8080 / rest-api / swagger. json, однако, когда я пытаюсь: http://localhost: 8080 / rest-api / docs / Я получаю:
RESTEASY003210: Не удалось найти ресурс для полного путь: http://localhost: 8080 / rest-api / docs /
Я пытался открыть proj \ rest-api \ target \ rest-api \ docs \ index. htm из файловой системы и получил:
{
"schemaValidationMessages":
[
{
"level":"error",
"message":"Can't read from file file:///rest-api/swagger.json"
}
]
}