Swagger annotations and Swagger spec 2.0

2.4k views Asked by At

I've developed a REST API anotated with Swagger annotations. I've been able to show the api documentation on a swagger-ui application, very nice.

The problem: I'm trying to generate clients acording this specification using the url provided by swagger acording my anotations. The porblem is it seems to be imcompatible, or at least, I don't see how to do the swagger editor reads my url and from then on, generate clients. But swagger editor reports me about some errors...

It's possible to integrate my anotated swagger api with a swagger editor?

Thanks.

3

There are 3 answers

1
cosbor11 On

Swagger editor is used only for editing a swagger spec in either json or yml format. It does not deal with swagger annotations in any way. However, some of the server skeletons that are generated on the swagger-editor website contain annotations. The annotations are a way of reverse engineering your API to generate a json file so that swagger UI can render a webpage based on the public url path to your swagger.json file. If you are maintaining a swagger spec json file anyways, the annotations aren't really needed, you might as well just serve up the raw swagger.json itself, rather than the json that is generated by the annotations.

As to your question, "Is it possible to integrate your API with swagger editor?"... Anything is possible, but I'm not sure as to how or why you want to integrate them.

0
ipeluffo On

The question seems a bit confusing.

If you are trying to generate clients from your REST API Swagger spec, then you should take a look to Swagger-Codegen project.

Description of project:

swagger-codegen contains a template-driven engine to generate client code in different languages by parsing your Swagger Resource Declaration.

0
William Cheng On

Not sure if I understand the question correctly. If you want to generate API clients online, you an use http://generator.swagger.io (besides http://editor.swagger.io). Here is an example to generate API client for Java:

curl -X POST -H "content-type:application/json" -d '{"swaggerUrl":"http://petstore.swagger.io/v2/swagger.json"}' http://generator.swagger.io/api/gen/clients/java