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

Consumer Driven Contracts with OpenAPI

Consumer Driven Contracts with OpenAPI

Christian Fischer

October 27, 2020
Tweet

More Decks by Christian Fischer

Other Decks in Technology

Transcript

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

    Provider Provider Stub Adapter Test REST API Test BL Stub
  2. 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.
  3. OPENAPI 3.0 info servers security paths tags externalDocs conponents OPENAPI

    COMPONENTS schemas responses parameters requestBodies headers securitySchemes links callbacks
  4. 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/
  5. 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}
  6. 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
  7. 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]
  8. 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
  9. 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
  10. 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]