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

Stop writing your API clients by hand

Stop writing your API clients by hand

Introduction and demo of how one can use the Open API Spec to generate API clients on demand.

Alan Cooke

August 22, 2018
Tweet

More Decks by Alan Cooke

Other Decks in Programming

Transcript

  1. Open API aka Swagger — Open standard — Machine readable

    — Language agnostic approach to API specification
  2. Path specification paths: /v2/track: post: operationId: Track summary: Track tags:

    - Event consumes: - application/json parameters: - name: body in: body schema: $ref: '#/definitions/Event' responses: '200': description: '' security: - X-Outbound-Key: []
  3. Model specification definitions: User: title: User type: object properties: user_id:

    type: string first_name: type: string last_name: type: string email: type: string required: - user_id
  4. Tooling — Open source tools — Node service you run

    locally or hosting service, allows you edit and mock APIs — Commercial tooling — Stoplight.io
  5. Code generators — Open Source repo: https://github.com/swagger-api/ swagger-codegen/ Project broken

    into two parts 1. Command Line Interface - swagger-codegen-cli 1. Code generator - swagger-codegen
  6. Writing your own generator 1. Java class, allows you todo

    any special pre/post processing of models 2. Collection of mustache template files used to translate model into code
  7. public struct {{classname}}: Codable { {{#allVars}} {{#description}}/** {{description}} */ {{/description}}public

    var {{name}}: {{{datatype}}} {{^required}}?{{/required}} {{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}} {{/allVars}} }