OpenAPI and Java - Portland - 2019-12-10

99d4c0ed3c8027ea1c37b53d6441d042?s=47 sullis
December 10, 2019

OpenAPI and Java - Portland - 2019-12-10

Portland Java User Group
Portland Oregon
December 10, 2019

#openapi
#java

99d4c0ed3c8027ea1c37b53d6441d042?s=128

sullis

December 10, 2019
Tweet

Transcript

  1. OpenAPI and Java Sean Sullivan Portland Java User Group December

    10, 2019
  2. About me software engineer Portland Oregon Java Scala

  3. Agenda OpenAPI Real world examples Java tools and libraries API

    guidelines
  4. OpenAPI

  5. OpenAPI is a specification for describing API’s

  6. API specifications

  7. WSDL (SOAP) WADL (REST)

  8. Swagger (REST) OpenAPI (REST)

  9. https://en.wikipedia.org/wiki/OpenAPI_Specification

  10. REST API’s

  11. API Driven Development

  12. “API first”

  13. source: Adobe Tech Blog June 2017

  14. Code first vs API schema first

  15. JSON or YAML

  16. Real world examples

  17. Case Study: stripe.com OpenAPI

  18. https://github.com/stripe/openapi

  19. https://github.com/stripe/openapi

  20. Case Study: squareup.com OpenAPI

  21. https://github.com/square/connect-api-specification

  22. Case Study: Kubernetes OpenAPI

  23. https://github.com/kubernetes/kubernetes/tree/master/api/openapi-spec

  24. https://github.com/kubernetes-client/java Kubernetes Java Client

  25. https://github.com/kubernetes-client/java Kubernetes Java Client code generation

  26. Case Study: Microsoft Azure OpenAPI

  27. https://github.com/Azure/azure-rest-api-specs azure-rest-api-specs

  28. Case Study: Amazon EventBridge OpenAPI

  29. https://docs.aws.amazon.com/eventbridge Amazon EventBridge “EventBridge is a serverless event bus service

    that makes it easy to connect your applications with data from a variety of sources”
  30. https://docs.aws.amazon.com/eventbridge EventBridge Schema Registry Schemas are defined using JSON files,

    using the OpenAPI specification
  31. https://www.tbray.org/ongoing/When/201x/2019/12/02/Strongly-Typed-Events Strongly typed events

  32. Java tools and libraries

  33. Swagger libraries swagger-core swagger-parser swagger-codegen swagger-inflector

  34. https://github.com/swagger-api/swagger-parser Swagger parser

  35. pom.xml <dependency> <groupId>io.swagger.parser.v3</groupId> <artifactId>swagger-parser</artifactId> <version>2.0.16</version> </dependency> Swagger parser

  36. https://github.com/swagger-api/swagger-parser import io.swagger.v3.parser.OpenAPIV3Parser; import io.swagger.v3.oas.models.OpenAPI; String url = “http://petstore.swagger.io/v3/openapi.json”; OpenAPI

    openAPI = new OpenAPIV3Parser().read(url); Swagger parser
  37. https://github.com/swagger-api/swagger-parser Swagger parser Pull Request #1271

  38. ObjectMapperFactory.java return new JsonFactoryBuilder() .enable(StreamReadFeature.STRICT_DUPLICATE_DETECTION) .build(); Swagger parser Pull Request

    #1271
  39. Code generators Guardrail openapi-generator swagger-codegen AutoRest

  40. Guardrail project

  41. https://guardrail.dev/ Guardrail

  42. https://github.com/twilio/guardrail Guardrail

  43. https://github.com/twilio/guardrail Guardrail: Scala ScalaMeta

  44. https://github.com/twilio/guardrail Guardrail: Java JavaParser

  45. Guardrail example

  46. guardrail-maven-plugin <plugin> <groupId>com.twilio</groupId> <artifactId>guardrail-maven-plugin_2.12</artifactId> <version>0.54.5</version> <executions> … </executions> </plugin>

  47. guardrail-maven-plugin <configuration> <language>java</language> <kind>client</kind> <framework>dropwizard</framework> <specPath>${project.basedir}/src/main/openapi/petstore.json</specPath> <packageName>com.example.clients.petstore</packageName> </configuration> Java client

  48. guardrail-maven-plugin

  49. openapi-generator project

  50. openapi-generator

  51. openapi-generator

  52. openapi-generator

  53. REST API guidelines

  54. https://github.com/microsoft/api-guidelines

  55. https://www.infoq.com/news/2016/07/microsoft-rest-api/ July 2016

  56. https://cloud.google.com/apis/design/

  57. https://github.com/zalando/restful-api-guidelines

  58. https://github.com/paypal/api-standards/blob/master/api-style-guide.md

  59. Final thoughts use OpenAPI to define REST API’s adopt “API

    First” approach use a code generator to generate client libraries contribute to open source projects
  60. The End