Slide 1

Slide 1 text

Introduction to Open API Specification Lorna Mitchell, Nexmo

Slide 2

Slide 2 text

Describing APIs • Describe RESTful HTTP APIs in a machine-readable way • API description is independent of outputs such as documentation • Enable things that are not "just" documentation @lornajane

Slide 3

Slide 3 text

Spec-First API Design @lornajane

Slide 4

Slide 4 text

About OpenAPI Spec API description language formerly known as "Swagger". Became "OpenAPI Spec" -> v3 released (some tools are still catching up on v3) @lornajane

Slide 5

Slide 5 text

New APIs or Existing Ones? @lornajane

Slide 6

Slide 6 text

New APIs or Existing Ones? Yes! @lornajane

Slide 7

Slide 7 text

Who Writes OpenAPI Specs? @lornajane

Slide 8

Slide 8 text

Anatomy of OpenAPI Spec @lornajane

Slide 9

Slide 9 text

Anatomy of OpenAPI Spec Top-level elements: • openapi • info • servers • paths • components • security • tags @lornajane

Slide 10

Slide 10 text

OpenAPI Spec Examples A JSON or YAML file holds the description (this is YAML) openapi: 3.0.0 servers: - url: 'https://api.nexmo.com' info: version: 1.0.0 title: Secret Management API ... a few hundred more lines here @lornajane

Slide 11

Slide 11 text

Documenting an Endpoint paths: /accounts/{account_id}/secrets: get: summary: Retrieve API Secrets operationId: retrieveSecrets parameters: - $ref: '#/components/parameters/accountId' responses: '200': ... '401': $ref: '#/components/responses/BadCredentialsError' '404': $ref: '#/components/responses/NotFoundError' @lornajane

Slide 12

Slide 12 text

Example 200 Response description: API secret response content: application/json: schema: properties: secrets: type: object description: A list of secrets under the "secrets" key. properties: secrets: type: array items: $ref: '#/components/schemas/SecretInfo' @lornajane

Slide 13

Slide 13 text

SecretInfo Reference schemas: SecretInfo: type: object properties: id: type: string description: Secret ID example: ad6dc56f-07b5-46e1-a527-85530e625800 created_at: type: string description: The date/time the secret was created example: '2017-03-02T16:34:49Z' @lornajane

Slide 14

Slide 14 text

That looks complicated! @lornajane

Slide 15

Slide 15 text

Rendered Example: ReDoc @lornajane

Slide 16

Slide 16 text

Rendered Example: Nexmo @lornajane

Slide 17

Slide 17 text

Tools To Get Things Done @lornajane

Slide 18

Slide 18 text

Please use Source Control See also: https://gitworkbook.com @lornajane

Slide 19

Slide 19 text

Editing Tools There are editors with helpful tools • I like Atom with linter-swagger https://atom.io • Try SwaggerUI, SwaggerHub, etc https://swagger.io/tools/ • APICurio Studio gets good reviews https://www.apicur.io/ • Stoplight looks interesting https://stoplight.io (feel free to tweet your best tools at me, I'll share them all later) @lornajane

Slide 20

Slide 20 text

OAS in Atom @lornajane

Slide 21

Slide 21 text

Validation Tools Tools that check or "lint" your file. • Speccy is a CLI tool with configurable rules http://speccy.io/ • Open API Spec Validator https://github.com/p1c2u/openapi-spec-validator Set up in your editor or use a watch command, e.g.: watch -n 1 speccy lint myspec.yml @lornajane

Slide 22

Slide 22 text

Preview Tools OAS is a standard! So any preview should do: • ReDoc is great https://github.com/Rebilly/ReDoc • Speccy also wraps ReDoc for its serve command • You can run OpenApi-GUI locally https://github.com/mermade/openapi-gui @lornajane

Slide 23

Slide 23 text

Creating OpenAPI Specs is like eating an elephant @lornajane

Slide 24

Slide 24 text

Uses for OpenAPI Spec @lornajane

Slide 25

Slide 25 text

Resources • https://www.openapis.org • https://apievangelist.com • https://speccy.io • https://github.com/Rebilly/ReDoc • https://openapi.tools @lornajane