Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to access "Swagger" object #55

Open
santiagopoli opened this issue May 22, 2015 · 4 comments
Open

How to access "Swagger" object #55

santiagopoli opened this issue May 22, 2015 · 4 comments

Comments

@santiagopoli
Copy link

Hi!

I want to set additional information to my swagger config (Tag descriptions for example) like this example:

 Info info = new Info()
      .title("Swagger Sample App")
      .description("This is a sample server Petstore server.  You can find out more about Swagger " + 
        "at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger.  For this sample, " + 
        "you can use the api key \"special-key\" to test the authorization filters")
      .termsOfService("http://helloreverb.com/terms/")
      .contact(new Contact()
        .email("[email protected]"))
      .license(new License()
        .name("Apache 2.0")
        .url("http://www.apache.org/licenses/LICENSE-2.0.html"));

swagger.setInfo(info);

swagger.tag(new Tag()
      .name("pet")
      .description("Everything about your Pets")
      .externalDocs(new ExternalDocs("Find out more", "http://swagger.io")));
swagger.tag(new Tag()
      .name("store")
      .description("Access to Petstore orders"));
 swagger.tag(new Tag()
      .name("user")
      .description("Operations about user")
      .externalDocs(new ExternalDocs("Find out more about our store", "http://swagger.io")));

I'm unable to set that kind of properties within SwaggerBundleConfiguration (Only title, description, terms of service, license and contact are available). I've actually tried to obtain the Swagger object via ApplicationContext but without any luck (it returns null). Is there a way to access the swagger base object to do this (any other workaround will be appreciated tough)?.

Thanks!

@zerovox
Copy link

zerovox commented Jun 2, 2015

Hey @santiagopoli did you figure this out? I'm looking at doing a similar thing. I have a Bundle provided by someone else which I want to manually add swagger API docs for, but I'm not sure how best to go about it. I'd also like to add tags and external docs as you mentioned. I'm happy to make a Pull Request if you have any thoughts about how best to expose the Swagger object, was thinking we could just add a new method to SwaggerBundle that can be overriden giving access to the Swagger object inside of BeanConfig?

@thiagomoretto
Copy link

dropwizard-swagger uses swagger-jersey2-jaxrs module, more info here: https://github.com/swagger-api/swagger-core/wiki/Java-JAXRS-Quickstart. So, AFAIK, the API documentation is automatically built by using JAX-RS annotations and the additional info could be added by just using Swagger Annotations. This is the way of integration implemented by this bundle.

Looking at https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-Jersey-2.X-Project-Setup-1.5 you can see that the only object available to configure is BeanConfig, that just configures Swagger initialization. I really don't know if you could use swagger-jersey2-jaxrs module and add those infos programatically simultaneously.

@santiagopoli
Copy link
Author

Unfortunately, tags are one of the few things you can't configure via Annotations. Obviously, it would be very difficult to integrate this functionality because it transcends swagger-jersey2-jaxrs.
I'll try to figure this out and make a Pull Request.

@nmonterroso
Copy link

I have a similar need to access the Swagger object in order to add securityDefinition definitions to our Swagger doc. I opened #56 to address this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants