swagger-core
swagger-core copied to clipboard
Can I specify 'servers' in generated swagger.json through openapi configuration yaml?
Hello, is it possible to specify servers in the generated swagger.json in any way, besides manually editing it?
I am using an external configuation file openapi-configuration.yaml together with swagger-maven-plugin in generating swagger.json from annotated JAX-RS 2 code.
I cannot find it anywhere in the documentation for Swagger 2.0 configuration, but I assumed that I can specify the servers field here, like so:
openAPI:
info:
version: '1.0'
title: Test
description: Test
contact:
name: Test
email: [email protected]
servers:
- url: "https://localhost:1234/REST"
description: Test
After Maven build, the swagger.json file is generated successfully, but it is missing servers:
{
"openapi" : "3.0.1",
"info" : {
"contact" : {
"email" : "[email protected]",
"name" : "Test"
},
"description" : "Test",
"title" : "Test",
"version" : "1.0"
},
"paths" : {
.....
}
}
I am expecting the following instead:
{
"openapi" : "3.0.1",
"servers": [
{
"url": " https://localhost:1234/REST",
"description": "Test"
}
],
"info" : {
"contact" : {
"email" : "[email protected]",
"name" : "Test"
},
"description" : "Test",
"title" : "Test",
"version" : "1.0"
},
"paths" : {
.....
}
}
I also tried adding the annotation @ApplicationPath to our javax.ws.rs.core.Application class implementation, but did not work.
Below is our pom.xml containing the relevant dependencies only:
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-jaxrs2</artifactId>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-jaxrs2-servlet-initializer-v2</artifactId>
<version>2.1.2</version>
</dependency>
<!-- Generate Swagger.json -->
<build>
<plugins>
<!-- https://github.com/swagger-api/swagger-core/tree/master/modules/swagger-maven-plugin -->
<plugin>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-maven-plugin</artifactId>
<version>2.2.2</version>
<configuration>
<outputFileName>swagger</outputFileName>
<outputPath>${project.basedir}/src/main/resources/documentation</outputPath>
<configurationFilePath>${project.basedir}/src/main/resources/openapi-configuration.yaml</configurationFilePath>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>resolve</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Any help or guidance on the issue is appreciated. Thank you!