Skip to content

Commit

Permalink
Merge pull request #25 from sergeyklay/feature/json-decorator
Browse files Browse the repository at this point in the history
Use thin controller and JSON decorator
  • Loading branch information
sergeyklay authored Feb 20, 2023
2 parents c027dae + d848b82 commit 8decfa1
Show file tree
Hide file tree
Showing 20 changed files with 235 additions and 327 deletions.
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*.md linguist-documentation -linguist-detectable
LICENSE linguist-documentation -linguist-detectable
*.spec linguist-language=Gherkin linguist-detectable
*.json linguist-language=Json linguist-detectable

/contracts/*.yaml linguist-language=Yaml linguist-detectable

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/contracts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,6 @@ jobs:
- name: Test specification
run: specmatic test --testBaseURL=http://127.0.0.1:5000

- name: Run backward compatibility check on changed files
if: matrix.os != 'windows-latest' && steps.current-branch.outputs.ref != 'main'
run: specmatic compatible git commits contracts/documentation.yaml main HEAD
# - name: Run backward compatibility check on changed files
# if: matrix.os != 'windows-latest' && steps.current-branch.outputs.ref != 'main'
# run: specmatic compatible git commits contracts/documentation.yaml main HEAD
52 changes: 15 additions & 37 deletions contracts/documentation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ components:
format: int32
minimum: 1
example: 42
self_url:
type: string
example: https://example.com/v1/products/1
title:
type: string
example: iPhone 9
Expand Down Expand Up @@ -88,38 +91,20 @@ components:
title: Not Found Response
type: object
required:
- code
- status
- title
- description
- name
properties:
code:
status:
type: integer
format: int32
example: 404
description:
type: string
example: Specified product not found
name:
title:
type: string
example: Not Found
BadRequestResponse:
title: Bad Request Response
type: object
required:
- code
- description
- name
properties:
code:
type: integer
format: int32
example: 400
description:
type: string
example: Invalid product ID data type
name:
type: string
example: Bad Request
example: Specified product not found
parameters:
ProductIdParameter:
in: path
Expand All @@ -130,8 +115,13 @@ components:
format: int32
minimum: 1
required: true
example: 42

examples:
success:
summary: An ID of an existing product
value: 42
not-found:
summary: An ID of an not existing product
value: 10000000

paths:
/v1/products:
Expand Down Expand Up @@ -226,12 +216,6 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Product'
'400':
description: Bad Request
content:
application/json:
schema:
$ref: '#/components/schemas/BadRequestResponse'
'404':
description: Product not found
content:
Expand All @@ -248,12 +232,6 @@ paths:
responses:
'204':
description: Successful operation
'400':
description: Bad Request
content:
application/json:
schema:
$ref: '#/components/schemas/BadRequestResponse'
'404':
description: Product not found
content:
Expand Down
50 changes: 18 additions & 32 deletions contracts/products.spec
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
Feature: Products API
Feature: Single product API

Background:
Given openapi ./documentation.yaml

Scenario Outline: Bad request when getting the product by ID
When GET /v1/products/(id:number)
Then status 400
Examples:
| id |
| 1.1 |

Scenario Outline: Getting a product that does not exist
When GET /v1/products/(id:number)
Then status 404
Examples:
| id |
| 100 |
| id |
| 10000000 |

Scenario Outline: Successful getting product by ID
When GET /v1/products/(id:number)
Then status 200
Examples:
| id |
| 1 |
| 42 |

Scenario Outline: Deleting a product that does not exist
When DELETE /v1/products/(id:number)
Then status 404
Examples:
| id |
| 10000000 |

Scenario Outline: Successful deleting product by ID
When DELETE /v1/products/(id:number)
Then status 204
Examples:
| id |
| 7777 |

Scenario Outline: Successful getting list of products
When GET /v1/products
Expand All @@ -45,24 +52,3 @@ Feature: Products API
| phone |
| HP |
| |

Scenario Outline: Bad request when deleting the product by ID
When DELETE /v1/products/(id:number)
Then status 400
Examples:
| id |
| 1.1 |

Scenario Outline: Deleting a product that does not exist
When DELETE /v1/products/(id:number)
Then status 404
Examples:
| id |
| 100 |

Scenario Outline: Successful deleting product by ID
When DELETE /v1/products/(id:number)
Then status 204
Examples:
| id |
| 1 |
64 changes: 32 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "specmatic-testing-example",
"version": "1.4.0",
"version": "1.5.0",
"private": true,
"description": "Provider-side demo using Specmatic to do contract driven development",
"main": "index.js",
Expand Down
Loading

0 comments on commit 8decfa1

Please sign in to comment.