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

Consumer Driven Contracts with OpenAPI

Consumer Driven Contracts with OpenAPI

7379c719bba185bb01143b61b84c373d?s=128

Christian Fischer

October 27, 2020
Tweet

Transcript

  1. Consumer Driven Contracts mit OPENAPI Christian Fischer @agiledojo

  2. Cascading Changes Price Store Marketing Mobile

  3. Consumer Driven Contracts Price Store Marketing Mobile

  4. CDC Frameworks generates generates CDC Service Adapter REST Controller Consumer

    Provider Provider Stub Adapter Test REST API Test BL Stub
  5. What do we have to do now? 1. Write Contracts

    in provided DSL 2. Switch to generated Mocks for Consumer 3. Integrate Contract Test for Provider Let‘s get started Hmm, isn‘t there an easier ways? We already have an OpenAPI Doc for our REST Service.
  6. OPENAPI 3.0 info servers security paths tags externalDocs conponents OPENAPI

    COMPONENTS schemas responses parameters requestBodies headers securitySchemes links callbacks
  7. Swagger Request Validator Service Adapter REST Controller Consumer Provider Provider

    Stub Adapter Test REST API Test BL Stub Request Validator Request Validator https://bitbucket.org/atlassian/swagger-request-validator/src/master/
  8. Example: Provider and Consumers Store Backend Price Service Marketing Backend

    POST /price [„I“,“II“] status: 200 {„inCent“: 152} POST /price [„I“,“II“] status: 200 {„inCent“: 152, „tax“: 32}
  9. Example: The Contracts Store App Backend Price Service Marketing Portal

    store.yml de.agiledojo.cdd:price-api-store marketing.yml de.agiledojo.cdd:price-api-marketing testimplementation testimplementation
  10. Example: The Store Test Fixture Price Service [Wiremock] PriceServiceGatewayAdapter [Adapter

    Class] PriceServiceGatewayAdapterIT [Junit Test] setup & start call & assert add OpenApiValidationListener [Wiremock Listener] validate store.yml [OPENAPI Contract]
  11. Example: The Price Service Test Fixture CalculatorMock [Mockito Mock] PriceApiController

    [Spring REST Controller Class] PriceApiControllerIT [Spring MockMVC Test] call & assert setup MockMvc [HTTP CLient] OpenApiInteractionValidator [Validator] store.yml [OPENAPI Contract] setup validate
  12. CDC: Pact vs OPENAPI

  13. CDC vs OPENAPI CDC (Pact) OPENAPI Specification Style Consumer First,

    Interaction oriented Contract First, Syntax oriented Specification Format API JSON, YAML Languages JVM, JS, NET, Go, Python, Scala, PHP, Ruby, Rust,C++ JVM (Wiremock, RestAssured, MockMVC, Spring Webclient) Contract Broker Pact Server Artifact Repository
  14. JS Pact Validation PriceServiceMock [Pact Mock] Api [Api Adapter Class]

    swagger-mock-validator [npm module] create validate api.pact.spec.js [Pact Test] marketing.yml [OPENAPI Contract] call & assert setup Interactions marketing-priceservice.json [PactContract]
  15. Christian Fischer Software Engineering Coach http://agiledojo.de @agiledojo