Is it possible to serve the swagger root from a sub path as opposed to the applcation context root?
up vote
1
down vote
favorite
I followed this example swagger configuration but would like to set the swagger root (the path with which the swagger.json is served) to <jersey-context-root>/api-or-some-other-path
except that no matter what I pass to the config.setBasePath(some-sub-path);
the swagger root is always the jersey app-context root defined in the application.yml file, i.e: spring.jersey.application-path
so it seems the basePath is hard-wired.
spring-boot jersey-2.0 swagger-2.0
add a comment |
up vote
1
down vote
favorite
I followed this example swagger configuration but would like to set the swagger root (the path with which the swagger.json is served) to <jersey-context-root>/api-or-some-other-path
except that no matter what I pass to the config.setBasePath(some-sub-path);
the swagger root is always the jersey app-context root defined in the application.yml file, i.e: spring.jersey.application-path
so it seems the basePath is hard-wired.
spring-boot jersey-2.0 swagger-2.0
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I followed this example swagger configuration but would like to set the swagger root (the path with which the swagger.json is served) to <jersey-context-root>/api-or-some-other-path
except that no matter what I pass to the config.setBasePath(some-sub-path);
the swagger root is always the jersey app-context root defined in the application.yml file, i.e: spring.jersey.application-path
so it seems the basePath is hard-wired.
spring-boot jersey-2.0 swagger-2.0
I followed this example swagger configuration but would like to set the swagger root (the path with which the swagger.json is served) to <jersey-context-root>/api-or-some-other-path
except that no matter what I pass to the config.setBasePath(some-sub-path);
the swagger root is always the jersey app-context root defined in the application.yml file, i.e: spring.jersey.application-path
so it seems the basePath is hard-wired.
spring-boot jersey-2.0 swagger-2.0
spring-boot jersey-2.0 swagger-2.0
asked Nov 19 at 14:10
Dark Star1
2,842105595
2,842105595
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
Look at your link and the code
this.register(ApiListingResource.class);
That ApiListingResource
is the actual resource class that serves up the swagger.json
endpoint. If you look at the link, you can see the class is annotated with the path (the {type:json|yaml}
determines what type if data you will get back).
@Path("/swagger.{type:json|yaml}")
If you want to change the path, you need to register it differently. What you need to do is use the Resource.builder(ResourceClass)
method to get a builder where we can change the path. For example you can do something like this.
Resource swaggerResource = Resource.builder(ApiListingResource.class)
.path("foobar/swagger.{type:json|yaml}")
.build();
Then instead of the the ResourceConfig#register()
method, you use the ResourceConfig#registerResource(Resource)
method.
this.registerResource(swaggerResource);
Here's a complete test using Jersey Test Framework
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.model.Resource;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class ResourceBuilderTest extends JerseyTest {
@Path("/swagger.{type:json|yaml}")
public static class ApiListingResource {
@GET
@Produces("text/plain")
public String get() {
return "Hello World!";
}
}
@Override
public ResourceConfig configure() {
Resource swaggerResource = Resource.builder(ApiListingResource.class)
.path("foobar/swagger.{type:json|yaml}")
.build();
ResourceConfig config = new ResourceConfig();
config.registerResources(swaggerResource);
return config;
}
@Test
public void testIt() {
Response response = target("foobar/swagger.json")
.request()
.get();
String data = response.readEntity(String.class);
System.out.println(data);
assertEquals("Hello World!", data);
}
}
Thanks for the detailed explanation, though I have decided to leverage the holon platform to manage Jersey and Swagger
– Dark Star1
Nov 25 at 13:20
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Look at your link and the code
this.register(ApiListingResource.class);
That ApiListingResource
is the actual resource class that serves up the swagger.json
endpoint. If you look at the link, you can see the class is annotated with the path (the {type:json|yaml}
determines what type if data you will get back).
@Path("/swagger.{type:json|yaml}")
If you want to change the path, you need to register it differently. What you need to do is use the Resource.builder(ResourceClass)
method to get a builder where we can change the path. For example you can do something like this.
Resource swaggerResource = Resource.builder(ApiListingResource.class)
.path("foobar/swagger.{type:json|yaml}")
.build();
Then instead of the the ResourceConfig#register()
method, you use the ResourceConfig#registerResource(Resource)
method.
this.registerResource(swaggerResource);
Here's a complete test using Jersey Test Framework
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.model.Resource;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class ResourceBuilderTest extends JerseyTest {
@Path("/swagger.{type:json|yaml}")
public static class ApiListingResource {
@GET
@Produces("text/plain")
public String get() {
return "Hello World!";
}
}
@Override
public ResourceConfig configure() {
Resource swaggerResource = Resource.builder(ApiListingResource.class)
.path("foobar/swagger.{type:json|yaml}")
.build();
ResourceConfig config = new ResourceConfig();
config.registerResources(swaggerResource);
return config;
}
@Test
public void testIt() {
Response response = target("foobar/swagger.json")
.request()
.get();
String data = response.readEntity(String.class);
System.out.println(data);
assertEquals("Hello World!", data);
}
}
Thanks for the detailed explanation, though I have decided to leverage the holon platform to manage Jersey and Swagger
– Dark Star1
Nov 25 at 13:20
add a comment |
up vote
1
down vote
accepted
Look at your link and the code
this.register(ApiListingResource.class);
That ApiListingResource
is the actual resource class that serves up the swagger.json
endpoint. If you look at the link, you can see the class is annotated with the path (the {type:json|yaml}
determines what type if data you will get back).
@Path("/swagger.{type:json|yaml}")
If you want to change the path, you need to register it differently. What you need to do is use the Resource.builder(ResourceClass)
method to get a builder where we can change the path. For example you can do something like this.
Resource swaggerResource = Resource.builder(ApiListingResource.class)
.path("foobar/swagger.{type:json|yaml}")
.build();
Then instead of the the ResourceConfig#register()
method, you use the ResourceConfig#registerResource(Resource)
method.
this.registerResource(swaggerResource);
Here's a complete test using Jersey Test Framework
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.model.Resource;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class ResourceBuilderTest extends JerseyTest {
@Path("/swagger.{type:json|yaml}")
public static class ApiListingResource {
@GET
@Produces("text/plain")
public String get() {
return "Hello World!";
}
}
@Override
public ResourceConfig configure() {
Resource swaggerResource = Resource.builder(ApiListingResource.class)
.path("foobar/swagger.{type:json|yaml}")
.build();
ResourceConfig config = new ResourceConfig();
config.registerResources(swaggerResource);
return config;
}
@Test
public void testIt() {
Response response = target("foobar/swagger.json")
.request()
.get();
String data = response.readEntity(String.class);
System.out.println(data);
assertEquals("Hello World!", data);
}
}
Thanks for the detailed explanation, though I have decided to leverage the holon platform to manage Jersey and Swagger
– Dark Star1
Nov 25 at 13:20
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Look at your link and the code
this.register(ApiListingResource.class);
That ApiListingResource
is the actual resource class that serves up the swagger.json
endpoint. If you look at the link, you can see the class is annotated with the path (the {type:json|yaml}
determines what type if data you will get back).
@Path("/swagger.{type:json|yaml}")
If you want to change the path, you need to register it differently. What you need to do is use the Resource.builder(ResourceClass)
method to get a builder where we can change the path. For example you can do something like this.
Resource swaggerResource = Resource.builder(ApiListingResource.class)
.path("foobar/swagger.{type:json|yaml}")
.build();
Then instead of the the ResourceConfig#register()
method, you use the ResourceConfig#registerResource(Resource)
method.
this.registerResource(swaggerResource);
Here's a complete test using Jersey Test Framework
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.model.Resource;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class ResourceBuilderTest extends JerseyTest {
@Path("/swagger.{type:json|yaml}")
public static class ApiListingResource {
@GET
@Produces("text/plain")
public String get() {
return "Hello World!";
}
}
@Override
public ResourceConfig configure() {
Resource swaggerResource = Resource.builder(ApiListingResource.class)
.path("foobar/swagger.{type:json|yaml}")
.build();
ResourceConfig config = new ResourceConfig();
config.registerResources(swaggerResource);
return config;
}
@Test
public void testIt() {
Response response = target("foobar/swagger.json")
.request()
.get();
String data = response.readEntity(String.class);
System.out.println(data);
assertEquals("Hello World!", data);
}
}
Look at your link and the code
this.register(ApiListingResource.class);
That ApiListingResource
is the actual resource class that serves up the swagger.json
endpoint. If you look at the link, you can see the class is annotated with the path (the {type:json|yaml}
determines what type if data you will get back).
@Path("/swagger.{type:json|yaml}")
If you want to change the path, you need to register it differently. What you need to do is use the Resource.builder(ResourceClass)
method to get a builder where we can change the path. For example you can do something like this.
Resource swaggerResource = Resource.builder(ApiListingResource.class)
.path("foobar/swagger.{type:json|yaml}")
.build();
Then instead of the the ResourceConfig#register()
method, you use the ResourceConfig#registerResource(Resource)
method.
this.registerResource(swaggerResource);
Here's a complete test using Jersey Test Framework
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.model.Resource;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class ResourceBuilderTest extends JerseyTest {
@Path("/swagger.{type:json|yaml}")
public static class ApiListingResource {
@GET
@Produces("text/plain")
public String get() {
return "Hello World!";
}
}
@Override
public ResourceConfig configure() {
Resource swaggerResource = Resource.builder(ApiListingResource.class)
.path("foobar/swagger.{type:json|yaml}")
.build();
ResourceConfig config = new ResourceConfig();
config.registerResources(swaggerResource);
return config;
}
@Test
public void testIt() {
Response response = target("foobar/swagger.json")
.request()
.get();
String data = response.readEntity(String.class);
System.out.println(data);
assertEquals("Hello World!", data);
}
}
answered Nov 19 at 19:19
Paul Samsotha
147k19282465
147k19282465
Thanks for the detailed explanation, though I have decided to leverage the holon platform to manage Jersey and Swagger
– Dark Star1
Nov 25 at 13:20
add a comment |
Thanks for the detailed explanation, though I have decided to leverage the holon platform to manage Jersey and Swagger
– Dark Star1
Nov 25 at 13:20
Thanks for the detailed explanation, though I have decided to leverage the holon platform to manage Jersey and Swagger
– Dark Star1
Nov 25 at 13:20
Thanks for the detailed explanation, though I have decided to leverage the holon platform to manage Jersey and Swagger
– Dark Star1
Nov 25 at 13:20
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376448%2fis-it-possible-to-serve-the-swagger-root-from-a-sub-path-as-opposed-to-the-applc%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown