22
Ordina JOIN 2014 Ken Coenen @CoenenKen Senior Java Developer Architecture & Best Practices Competence Lead at Ordina Documenting your REST API with SWAGGER

Documenting your REST API with Swagger - JOIN 2014

Embed Size (px)

Citation preview

Page 1: Documenting your REST API with Swagger - JOIN 2014

Ordina JOIN 2014

Ken Coenen@CoenenKen

Senior Java DeveloperArchitecture & Best Practices Competence Lead at Ordina

Documenting your REST API with SWAGGER

Page 2: Documenting your REST API with Swagger - JOIN 2014

Swagger?

“Swagger is a specification and complete framework implementation for describing, producing, consuming, and

visualizing RESTful web services.”

Page 3: Documenting your REST API with Swagger - JOIN 2014

Describing

Page 4: Documenting your REST API with Swagger - JOIN 2014

Swagger specification

▪ JSON description of your REST API▪ APIs▪ Methods▪ Models

▪ Conversion from YAML to Swagger available▪ No need to write this yourself

Page 5: Documenting your REST API with Swagger - JOIN 2014

JSON description of your API

Page 6: Documenting your REST API with Swagger - JOIN 2014

JSON description of a method

Page 7: Documenting your REST API with Swagger - JOIN 2014

JSON description of a model

Page 8: Documenting your REST API with Swagger - JOIN 2014

Producing and consuming

Page 9: Documenting your REST API with Swagger - JOIN 2014

SDK generators

{ Swagger API spec }

Client code Server code

Page 10: Documenting your REST API with Swagger - JOIN 2014

Framework integration

Page 11: Documenting your REST API with Swagger - JOIN 2014

Documentation generation with Jersey

1. Include Maven dependency (watch out for exclusions!)

Needed for annotation classes

Page 12: Documenting your REST API with Swagger - JOIN 2014

Documentation generation with Jersey (2)

2. Replace regular Jersey servlet with Swagger version

Page 13: Documenting your REST API with Swagger - JOIN 2014

Documentation generation with Jersey (3)

4. API description available on /api/api-docs

3. Annotate your REST services with Swagger annotations

Page 14: Documenting your REST API with Swagger - JOIN 2014

Client codegen

1. Written in Scala2. {{ mustache }} templates 3. Maven goal4. Generate eg. Java code into a separate Maven module5. Add Maven dependency to consuming modules

Page 15: Documenting your REST API with Swagger - JOIN 2014

Client codegen pros and cons

▪ All clients have latest code by executing Codegen

▪ Make sure client code serializes/deserializes objects the same as your backend

▪ Session management▪ Multithreading▪ Maven integration is hard

Page 16: Documenting your REST API with Swagger - JOIN 2014

Visualizing

Page 17: Documenting your REST API with Swagger - JOIN 2014

Swagger UI API

Page 18: Documenting your REST API with Swagger - JOIN 2014

Swagger UI method

Page 19: Documenting your REST API with Swagger - JOIN 2014

Links

▪ Starting point is http://swagger.io/▪ GitHub https://github.com/wordnik/swagger-spec▪ Codegen project https://github.com/wordnik/swagger-codegen▪ YAML to Swagger https://github.com/wordnik/swagger-

codegen/blob/master/bin/yml2swagger.js

Page 20: Documenting your REST API with Swagger - JOIN 2014

Conclusion

Page 21: Documenting your REST API with Swagger - JOIN 2014

Swagger conclusions

▪ Documentation close to server code▪ SwaggerUI is major advantage▪ Don’t expect client codegen to work out-of-the-box

Page 22: Documenting your REST API with Swagger - JOIN 2014

Q&A