Top Banner
TED EPSTEIN, FOUNDER & CEO | [email protected] 1 COPYRIGHT © 2017, MODELSOLV, INC. | ALL RIGHTS RESERVED. API Contract as Code Rapid Development with OpenAPI
17

API Contract as Code: Rapid Development with OpenAPI

Jan 22, 2018

Download

Software

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: API Contract as Code: Rapid Development with OpenAPI

TED EPSTEIN, FOUNDER & CEO | [email protected]

1COPYRIGHT © 2017, MODELSOLV, INC. | ALL RIGHTS RESERVED.

API Contract as CodeRapid Development with OpenAPI

Page 2: API Contract as Code: Rapid Development with OpenAPI

First Swagger Value Proposition• Keep your API docs in sync with implementation!

… and look cooldoing it!

COPYRIGHT © 2017, MODELSOLV, INC. | ALL RIGHTS RESERVED. 2

Page 3: API Contract as Code: Rapid Development with OpenAPI

Code-First• Or “API Code-as-Contract”

COPYRIGHT © 2017, MODELSOLV, INC. | ALL RIGHTS RESERVED. 3

Page 4: API Contract as Code: Rapid Development with OpenAPI

So why not all code, all the time? • Not Cross-functional team-friendly◦ Coders aren’t always the best communicators.

◦ Tech writers don’t want to maintain embedded code comments(and you may not want them to).

• De-emphasizes API design◦ Outside-in design, from the user’s perspective

◦ As a distinct process

◦ Leveraging available tools for docs, mocking, testing, etc.

◦ Conscious, collaborative focus to API design quality

COPYRIGHT © 2017, MODELSOLV, INC. | ALL RIGHTS RESERVED. 4

Page 5: API Contract as Code: Rapid Development with OpenAPI

But there’s another reason…• Leverage◦Higher productivity

◦Greater expressive power

• An OpenAPI Description is code!◦High focus, high abstraction

◦Generated code can be a scaffold to get started quickly…

◦… and it can be first-class code.

COPYRIGHT © 2017, MODELSOLV, INC. | ALL RIGHTS RESERVED. 5

Page 6: API Contract as Code: Rapid Development with OpenAPI

COPYRIGHT © 2017, MODELSOLV, INC. | ALL RIGHTS RESERVED. 6

API Contract-As-CodeDevelopment Workflow

Page 7: API Contract as Code: Rapid Development with OpenAPI

COPYRIGHT © 2017, MODELSOLV, INC. | ALL RIGHTS RESERVED. 7

API Contract-As-CodeDevelopment Workflow

Page 8: API Contract as Code: Rapid Development with OpenAPI

COPYRIGHT © 2017, MODELSOLV, INC. | ALL RIGHTS RESERVED. 8

API Contract-As-CodeDevelopment Workflow

Page 9: API Contract as Code: Rapid Development with OpenAPI

COPYRIGHT © 2017, MODELSOLV, INC. | ALL RIGHTS RESERVED. 9

API Contract-As-CodeDevelopment Workflow

Page 10: API Contract as Code: Rapid Development with OpenAPI

COPYRIGHT © 2017, MODELSOLV, INC. | ALL RIGHTS RESERVED. 10

API Contract-As-CodeDevelopment Workflow

Page 11: API Contract as Code: Rapid Development with OpenAPI

COPYRIGHT © 2017, MODELSOLV, INC. | ALL RIGHTS RESERVED. 11

API Contract-As-CodeDevelopment Workflow

Page 12: API Contract as Code: Rapid Development with OpenAPI

COPYRIGHT © 2017, MODELSOLV, INC. | ALL RIGHTS RESERVED. 12

API Contract-As-CodeDevelopment Workflow

Page 13: API Contract as Code: Rapid Development with OpenAPI

Demo

COPYRIGHT © 2017, MODELSOLV, INC. | ALL RIGHTS RESERVED. 13

Page 14: API Contract as Code: Rapid Development with OpenAPI

Achieving Separation• “Write-once” codegen for implementation

• Delegation

• Interface / Implementation

• Abstract Base Class / Concrete Implementation

• Dependency Injection

• Dynamic merge (e.g. C# partial classes)

COPYRIGHT © 2017, MODELSOLV, INC. | ALL RIGHTS RESERVED. 14

Page 15: API Contract as Code: Rapid Development with OpenAPI

Project Layout• All in one project

• One project for API spec, generate intosecond project for implementation

• Generated library

COPYRIGHT © 2017, MODELSOLV, INC. | ALL RIGHTS RESERVED. 15

Page 16: API Contract as Code: Rapid Development with OpenAPI

Validating Implementation vs. SpecImplementation Completeness:“Every method is implemented”◦ Use static typing when available

◦ Use generated or dynamic unit tests fordynamic languages

Specification Completeness“Every method implemented is in the specification”◦ Harder to enforce, but easy to prevent.

◦ Static code analysis or reflective tests couldbe useful

CorrectnessMethods implement the contract (mechanics)Methods have the expected outcome (semantics)◦ Use testing tools or frameworks, same as as

you would with code-first

COPYRIGHT © 2017, MODELSOLV, INC. | ALL RIGHTS RESERVED. 16

Page 17: API Contract as Code: Rapid Development with OpenAPI

OpenAPI 3.0 - More Descriptive Power, New Possibilities…-• Links

• Callbacks

• oneOf / anyOf Schemas

• Component Model

COPYRIGHT © 2017, MODELSOLV, INC. | ALL RIGHTS RESERVED. 17