Skip to content

Commit

Permalink
Getting started now uses openapi instead of spec file
Browse files Browse the repository at this point in the history
  • Loading branch information
joelrosario committed Jan 14, 2022
1 parent c6e9f9a commit a122aa0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 24 deletions.
51 changes: 36 additions & 15 deletions _includes/authoring_contract_introduction.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,37 @@
Copy paste below text into a file with name "service.spec". This, as you can see, uses the Gherkin syntax to describe a basic GET request.
Copy paste below text into a file with name "service.yaml". This, as you can see, uses the Gherkin syntax to describe a basic GET request.

Feature: Contract for the petstore service

Scenario: Should be able to get a pet by petId
When GET /pets/(petid:number)
Then status 200
And response-body {petid: "(number)"}

There are some extra keywords that make it easier to define APIs.
* GET and related URL
* status
* response-body
* (number) - placeholder for number datatype

These keywords are documented in the contract syntax reference. TODO
---
openapi: "3.0.1"
info:
title: "Contract for the petstore service"
version: "1"
paths:
/pets/{petid}:
get:
summary: "Should be able to get a pet by petId"
parameters:
- name: "petid"
in: "path"
required: true
schema:
type: "number"
responses:
"200":
description: "Should be able to get a pet by petId"
content:
application/json:
schema:
required:
- "id"
- "name"
- "status"
- "type"
properties:
id:
type: "number"
name:
type: "string"
type:
type: "string"
status:
type: "string"
6 changes: 3 additions & 3 deletions documentation/getting_started_programmatically.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public class PetStoreConsumerTest {
public static void setUP() {
// Path to the contract
List<String> contracts = new ArrayList<String>();
contracts.add("/path/to/service/contract/service.spec");
contracts.add("/path/to/service/contract/service.yaml");

// Path to stub data directory
List<String> stubDataDir = new ArrayList<String>();
Expand Down Expand Up @@ -125,7 +125,7 @@ public class PetStoreConsumerTest {

Let us take a closer look at the above test.
* The objective of this test is to help us build a PetStoreConsumer (API Client) class.
* The setUP and tearDown methods are responsible for starting a Specmatic Stub server (based on the service.spec) and stopping it respectively.
* The setUP and tearDown methods are responsible for starting a Specmatic Stub server (based on the service.yaml) and stopping it respectively.
* In the setUP section, we pass the expectation json file to the stub. This tells it to expect a call to /pets/10, to which it must return the given pet info.
* The assert section verifies that PetStoreConsumer is able to translate the response to Pet object

Expand Down Expand Up @@ -252,7 +252,7 @@ public class PetStoreContractTest extends SpecmaticJUnitSupport {

@BeforeAll
public static void setUp() {
File contract = new File("/path/to/service.spec");
File contract = new File("/path/to/service.yaml");
System.setProperty("contractPaths", contract.getAbsolutePath());
System.setProperty("host", "localhost");
System.setProperty("port", "8080");
Expand Down
12 changes: 6 additions & 6 deletions getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ Let us try specifying the above interaction as a contract.

Let us start with the Consumer in this example. We will be running a Stub / Mock Server based on the above contract file.

UI (Consumer) Specmatic Stub <- service.spec
UI (Consumer) Specmatic Stub <- service.yaml
| --- getPetById ---> |
| <-- {Pet JSON} ---- |

To spin up a stub server with the service.spec we authored earlier, run below command.
To spin up a stub server with the service.yaml we authored earlier, run below command.

specmatic stub "<base-dir>/petstore/specmatic/service.spec" --host="localhost" --port="8000"
specmatic stub "<base-dir>/petstore/specmatic/service.yaml" --host="localhost" --port="8000"

The command has defaults and necessary help to guide you through.

Expand All @@ -66,13 +66,13 @@ We can now start consumer development against this stub without any dependency o

Specmatic runs Contract Tests on API to make sure it adheres to the contract.

service.spec -> Specmatic Test API (Provider)
service.yaml -> Specmatic Test API (Provider)
| --- getPetById ---> |
| <-- {Pet JSON} ---- |

Below command runs service.spec as a contract test against the provider.
Below command runs service.yaml as a contract test against the provider.

specmatic test "<base-dir>/petstore/contract/service.spec" --host="localhost" --port="8000"
specmatic test "<base-dir>/petstore/contract/service.yaml" --host="localhost" --port="8000"

You should see below error message.

Expand Down

0 comments on commit a122aa0

Please sign in to comment.