Contributions
Re: Add basic authentication in swagger-ui in project with Spring-security
I think I've found the solution : Adding @SecurityScheme(name = "myHttpSecurity", type = SecuritySchemeType.HTTP, in = SecuritySchemeIn.HEADER ) Then, the authorize button appears :) Now, I still have to find how to print description about security informations in swagger-ui3.3KViews0likes0CommentsAdd basic authentication in swagger-ui in project with Spring-security
Hi, I want to add the functionality to authenticate in swagger-ui in order to test protected endpoints. In previous project with old swagger version and spring-boot with spring-mvc I was able to do that, but I don't know how to do this with my new project. I'm using : Spring-boot 2 with spring-security and spring-boot-starter-jersey swagger 2.0.6 (swagger core v3 with swagger-jaxrs2) swagger 3.20.3 Thanks for your help !3.3KViews0likes1Comment@ApiResponse messages inheritance
Hi, I'm facing a problem that I don't know if it's an issue or a normal behaviour of swagger. And if it's a normal behaviour, maybe it could be improved I'm defining interfaces and swagger documentation on the interfaces' methods like this : public interface FirstEndpoint<C> { @POST @Path("/") @ApiResponses(value = { @ApiResponse(responseCode = "201", description = "Created"), @ApiResponse(responseCode = "400", description = "Bad Request"), @ApiResponse(responseCode = "403", description = "Forbidden"), @ApiResponse(responseCode = "404", description = "Not Found")}) default String firstEndpoint(C param) { return "firstEndpoint-ok"; } } And public interface SecondEndpoint<C> { @GET @Path("/{id}") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "400", description = "Bad Request"), @ApiResponse(responseCode = "403", description = "Forbidden"), @ApiResponse(responseCode = "404", description = "Not Found")}) default String secondEnpoint(C param) { return "secondEnpoint-ok"; } } Then in some cases I may want to change the description so in the class of my controller which implements these interfaces I do this : @Path("/testresponse") @Tag(name = "Test response messages") public class TestApiResponseResource implements FirstEndpoint<SampleDTO>, SecondEndpoint<SampleOtherDTO> { @Override public String firstEndpoint(SampleDTO param) { return "firstEndpoint Implemented !"; } @Override @ApiResponse(responseCode = "404", description = "I said : not Found") public String secondEnpoint(SampleOtherDTO param) { return "secondEnpoint Implemented !"; } } As you can see : for «firstEndpoint» I don't override any @ApiResponse for «secondEndpoint» I've override only one @ApiResponse for 404 response Full source code available here : https://github.com/githubjul/test-swagger-with-interfaces The expected behaviour would be for : for «firstEndpoint», get all messages declared in interface => Ok, I get them ! for «secondEnpoint», get all messages declared in interface, except for 404, I want to have my custom message => Ko, in only get my 404 message, I've lost all messages declared in interface Si is this a bug ? If it's not, how can I simply overrid only one @ApiResponse message ? The expected behaviour I want would be : override only specific messages : use @ApiResponse replace all messages : use @ApiResponses Thanks for your help, JulienSolved3.2KViews0likes2CommentsRe: No OpenAPI visible endpoint for endpoint declared in interface with default implementation
Hi, Thanks for your answer. I've written a sample project to show the problem. Here is the repository. https://github.com/githubjul/test-swagger-with-interfaces The creation of this test allows me to understand exactly where is the problem, it's a little more tricky than I thought. First of all, you're absolutely right : there is no problem with default method in interfaces. My problem is a mix between default method in interface and inheritance. First interface : public interface OriginalEndpoint<C> { String originalEndpoint(C c); } Second interface : public interface SecondEndpoint<C> extends OriginalEndpoint<C> { @GET @Path("/{id}") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "400", description = "Bad Request"), @ApiResponse(responseCode = "403", description = "Forbidden"), @ApiResponse(responseCode = "404", description = "Not Found")}) default String secondEnpoint(C param) { return "secondEnpoint-ok"; } @Override @GET @Path("/original/{id}") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "400", description = "Bad Request"), @ApiResponse(responseCode = "403", description = "Forbidden"), @ApiResponse(responseCode = "404", description = "Not Found")}) default String originalEndpoint(C param) { return "originalEndpoint-ok"; } } In the swagger generated : secondEnpoint ( Get on «/{id}) is present originalEndpoint ( Get on «/original/{id}») is not present The reason I used this inheritance in interfaces is because I have multiple default implementations for same «base» interfaces. One default implementation for Jersey, and another one for Spring MVC3.1KViews0likes2CommentsNo OpenAPI visible endpoint for endpoint declared in interface with default implementation
I'm writing a generic system de create REST endpoints. I'm using Jersey + Spring in my project but my problem is only related to OpenAPI . I use Swagger 2 (OpenAPI 3.0) I'm declaring all my endpoints and their documentation in interfaces, with a default implementation. So in my class I don't have to declare the methods which already have a default implementation. Here is a sample of my code : public interface SampleEndpoints { @POST @Path("/") @ApiResponses(value = { @ApiResponse(responseCode = "201", description = "Created"), @ApiResponse(responseCode = "400", description = "Bad Request"), @ApiResponse(responseCode = "403", description = "Forbidden"), @ApiResponse(responseCode = "404", description = "Not Found")}) default String create(Object param ) { return "ok"; } @GET @Path("/{id}") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Ok"), @ApiResponse(responseCode = "400", description = "Bad Request"), @ApiResponse(responseCode = "403", description = "Forbidden"), @ApiResponse(responseCode = "404", description = "Not Found")}) String find(String id); } The controller class @Component @Path("/cars") public class CarsController implements SampleEndpoints { public String find(String id) { return "Yes I've found it"; } } As you can see I don't have to implement the create method because its default implementation is sufficient. My problem is that the create method doesn't appear in the generated openapi.json (but the find method is there, with all the informations) If instead of an interface I declare SampleEndpoints as a class, and make my CarsController inherit of SampleEndpoints, then the open Api documentation works. So I'd like to know if there is a way to make it works with interface ? I can't manage to find a solution, but using interface instead of inheritance is mandatory because my controller needs to implements multiple interfaces. Thanks for all your ideas :)Solved3.2KViews0likes4Comments