question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SwaggerDefinition annotation does not work

See original GitHub issue

Following https://github.com/swagger-api/swagger-core/wiki/Annotations-1.5.X#swagger-definition I created an interface ‘ApiConfig’ with no method in it and put it the interface in the package that swagger will scan.

I am using jersey 2.15 and swagger-jersey2-jaxrs version is 1.5.10. I also tried swagger-jersey2-jaxrs 1.5.14 with no luck.

This is the interface I created.

@SwaggerDefinition(
        info = @Info(
                description = "my apis",
                version = "1.0.0",
                title = "my apis"
        ),
        schemes = {SwaggerDefinition.Scheme.HTTP},
        tags = {@Tag(name = "mytag", description = "test tag")},
        securityDefinition = @SecurityDefinition(
                oAuth2Definitions = {
                        @OAuth2Definition(
                                key = "testoauth",
                                description = "MES OAuth",
                                authorizationUrl = "http://www.example.com/",
                                tokenUrl = "",
                                scopes = {
                                        @Scope(
                                                name = "test",
                                                description = "testscope"
                                        ),
                                        @Scope(
                                                name = "general:save",
                                                description = "save operation"
                                        ),
                                        @Scope(
                                                name = "general:update",
                                                description = "update operation"
                                        )
                                },
                                flow = OAuth2Definition.Flow.IMPLICIT
                        )
                }
        )
)
public interface ApiConfig {
}

But the result ‘swagger.json’ does not contain anything I specified in the annotation(I hit ‘swagger.json’ in chrome and searched ‘securityDefinition’ and got nothing). Then I added @Path("") to the interface, and restarted web server, it worked as expected. What did I do wrong?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:7

github_iconTop GitHub Comments

4reactions
zak905commented, Sep 8, 2017

I got it to work, you should add @Provider annotation on the interface, otherwise it will not be picked up by Jersey container

0reactions
johnsnow20087349commented, Jul 12, 2019

Had exactly the same issue, and @zak905 's suggestion worked for me.

Thanks!

doesn’t work for me, because I use msf4j, not Jersey

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issue in adding Annotation SwaggerDefinition at class level
When the migration is complete, you will access your Teams at stackoverflowteams.com, and they will no longer appear in the left sidebar on ......
Read more >
data in @SwaggerDefinition doesn't go to html and json ...
The main objective for SwaggerDefinition annotation is to specify base path for my JAX-RS ... v 1.5.3) but when I run swagger-maven-plugin on...
Read more >
SwaggerDefinition (swagger-annotations 1.5.0 API)
Annotation Type SwaggerDefinition ... consumes for this swagger definition. These will be added to all api definitions that don't have local overrides -...
Read more >
How to force swagger.json file to be generated using UTF-8?
I'm trying to implement WSO2 for an API that will be publically opened, ... charset=utf-8" }" on @SwaggerDefinition, but nothing changes.
Read more >
Spring Boot and Swagger: Documenting RESTful Services
You can filter out APIs you do not want to document with Swagger. Exposing Meta API Information Using @SwaggerDefinition. You can also expose ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found