Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Automating your API Client Library

Automating your API Client Library

Explaining how we automatically generate our API client library using swagger and swaggen.

Avatar for Jeffrey Macko

Jeffrey Macko

September 21, 2018
Tweet

More Decks by Jeffrey Macko

Other Decks in Programming

Transcript

  1. What is automation ? Automation is the technology by which

    a process or procedure is performed without human assistance. — Wikipédia Automating your API Client Library - FrenchKit 2018 - @jeffreymacko
  2. Why did we do this ? — Our webservice API

    is pretty large — Our webservice API has changed a lot recently — It's fun to try new technologies and share them with you — We will most certainly never have to use AFNetworking or Alamofire again! Automating your API Client Library - FrenchKit 2018 - @jeffreymacko
  3. Goals — Always be up to date with the webservice

    API — Reduce work on repetitive tasks with low added value — Simplifying our codebase, improve consistency — Up to date documentation baked into the API client library Automating your API Client Library - FrenchKit 2018 - @jeffreymacko
  4. Step to edit our client library(before) Way too many steps

    ! Automating your API Client Library - FrenchKit 2018 - @jeffreymacko
  5. Step to edit our client library(a!er) Automating your API Client

    Library - FrenchKit 2018 - @jeffreymacko
  6. How did we did it ? — Generate an API

    Description file — Define how we want to have our code generated througt templates files — Use the API Description file to generate the API Client library Automating your API Client Library - FrenchKit 2018 - @jeffreymacko
  7. This is how we do it ! — Generate an

    API Description file — Define how we want to have our code generated througt templates files — Use the API Description file to generate the API Client library Automating your API Client Library - FrenchKit 2018 - @jeffreymacko
  8. What is an API Description file A file that is

    used to describe and document HTTP RESTful APIs like Swagger, OpenAPI, API Blueprint or RAML. Automating your API Client Library - FrenchKit 2018 - @jeffreymacko
  9. API Description file — Share API design process — Generate

    API documentation — Generate API validation / testing — Generate client code — Generate server code — Generate mock Server — Generate mock Client Automating your API Client Library - FrenchKit 2018 - @jeffreymacko
  10. SwagGen — Customise models and API Client with templating and

    options — Generate all models — Generate the API Client layer Automating your API Client Library - FrenchKit 2018 - @jeffreymacko
  11. paths: /pet: post: summary: "Add a new pet to the

    store" operationId: "addPet" consumes: - "application/json" - "application/xml" produces: - "application/xml" - "application/json" parameters: - in: "body" name: "body" description: "Pet object that needs to be added to the store" required: true schema: $ref: "#/definitions/Pet" responses: 405: description: "Invalid input" Automating your API Client Library - FrenchKit 2018 - @jeffreymacko
  12. definitions: Pet: type: "object" required: - "name" properties: id: type:

    "integer" format: "int64" category: $ref: "#/definitions/Category" name: type: "string" example: "doggie" status: type: "string" description: "pet status in the store" enum: - "available" - "pending" - "sold" Automating your API Client Library - FrenchKit 2018 - @jeffreymacko
  13. Automated generation ./swaggen generate swagger.json Loading spec from swagger.json Loaded

    spec: "PagesJaunes" - 44 operations, 330 definitions Loaded template: 19 template files, 15 options Destination: /Users/jmacko/pj/Swagger/SwaggerService/Generated/Swift Generation complete: 390 created Automating your API Client Library - FrenchKit 2018 - @jeffreymacko
  14. Automated generation ./swaggen generate swagger.json Loading spec from swagger.json Loaded

    spec: "PagesJaunes" - 44 operations, 330 definitions Loaded template: 19 template files, 15 options Destination: /Users/jmacko/pj/Swagger/SwaggerService/Generated/Swift Generation complete: 390 created Only 6,42s Automating your API Client Library - FrenchKit 2018 - @jeffreymacko
  15. Automated generation ./swaggen generate swagger.json Loading spec from swagger.json Loaded

    spec: "PagesJaunes" - 44 operations, 330 definitions Loaded template: 19 template files, 15 options Destination: /Users/jmacko/pj/Swagger/SwaggerService/Generated/Swift Generation complete: 390 created Only 6,42s for generating an API Client library Automating your API Client Library - FrenchKit 2018 - @jeffreymacko
  16. Automated generation ./swaggen generate swagger.json Loading spec from swagger.json Loaded

    spec: "PagesJaunes" - 44 operations, 330 definitions Loaded template: 19 template files, 15 options Destination: /Users/jmacko/pj/Swagger/SwaggerService/Generated/Swift Generation complete: 390 created Only 6,42s for generating an API Client library - 330 models - API Client Layer (44 endpoints) Automating your API Client Library - FrenchKit 2018 - @jeffreymacko
  17. Automated generation ./swaggen generate swagger.json Loading spec from swagger.json Loaded

    spec: "PagesJaunes" - 44 operations, 330 definitions Loaded template: 19 template files, 15 options Destination: /Users/jmacko/pj/Swagger/SwaggerService/Generated/Swift Generation complete: 390 created Only 6,42s for generating an API Client library - 330 models - API Client Layer (44 endpoints) It can also work on Android or any other language Automating your API Client Library - FrenchKit 2018 - @jeffreymacko
  18. Human generation ( ! / " ) Automating your API

    Client Library - FrenchKit 2018 - @jeffreymacko
  19. Human generation ( ! / " ) Working on repetitive

    tasks with low added value Automating your API Client Library - FrenchKit 2018 - @jeffreymacko
  20. Human generation ( ! / " ) Working on repetitive

    tasks with low added value Only 2678400s Automating your API Client Library - FrenchKit 2018 - @jeffreymacko
  21. Human generation ( ! / " ) Working on repetitive

    tasks with low added value Only 2678400s of human work: - 330 models - API Client Layer (44 endpoints) - A few bugs - Less rigorous code - Less new features in the product Automating your API Client Library - FrenchKit 2018 - @jeffreymacko