-
-
Save justinyoo/751a4b31a24084c0fbcc7ea4add9a520 to your computer and use it in GitHub Desktop.
API Mocking for Developers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
swagger: "2.0" | |
info: | |
title: Product API | |
version: v1 | |
host: myproduct.com | |
basePath: /api | |
schemes: | |
- https | |
paths: | |
/products: | |
get: | |
summary: Gets the list of products | |
produces: | |
- application/json | |
responses: | |
200: | |
description: List of products returned | |
schema: | |
type: array | |
items: | |
$ref: "#/definitions/product" | |
# Sample response | |
examples: | |
application/json: | |
- | |
productId: 1 | |
name: Product A | |
description: This is Product A | |
price: 12.34 | |
- | |
productId: 2 | |
name: Product B | |
description: This is Product B | |
price: 56.78 | |
post: | |
summary: Adds the product details | |
consumes: | |
- application/json | |
produces: | |
- application/json | |
parameters: | |
- | |
in: body | |
name: body | |
description: Product object that needs to be added | |
required: true | |
schema: | |
$ref: "#/definitions/product" | |
responses: | |
201: | |
description: Product added | |
schema: | |
$ref: "#/definitions/product" | |
# Sample response | |
examples: | |
application/json: | |
productId: 3 | |
name: Product A | |
description: This is Product A | |
price: 90.12 | |
/products/{productId}: | |
get: | |
summary: Gets the product details | |
produces: | |
- application/json | |
parameters: | |
- | |
name: productId | |
in: path | |
description: Product Id | |
required: true | |
type: integer | |
format: int32 | |
responses: | |
200: | |
description: Product exists | |
schema: | |
$ref: "#/definitions/product" | |
# Sample response | |
examples: | |
application/json: | |
productId: 1 | |
name: Product A | |
description: This is Product A | |
price: 12.34 | |
404: | |
description: Product corresponding to productId doesn't exist | |
schema: | |
$ref: "#/definitions/error" | |
# Sample response | |
examples: | |
application/json: | |
message: Product Not Found | |
patch: | |
summary: Updates the product details | |
produces: | |
- application/json | |
parameters: | |
- | |
name: productId | |
in: path | |
description: Product Id | |
required: true | |
type: integer | |
format: int32 | |
- | |
in: body | |
name: body | |
description: Product object that needs to be updated | |
required: true | |
schema: | |
$ref: "#/definitions/product" | |
responses: | |
200: | |
description: Product updated | |
schema: | |
$ref: "#/definitions/product" | |
# Sample response | |
examples: | |
application/json: | |
productId: 1 | |
name: Product A | |
description: This is Product A | |
price: 12.34 | |
404: | |
description: Product corresponding to productId doesn't exist | |
schema: | |
$ref: "#/definitions/error" | |
# Sample response | |
examples: | |
application/json: | |
message: Product Not Found | |
definitions: | |
product: | |
type: object | |
required: | |
- name | |
- price | |
properties: | |
productId: | |
type: integer | |
format: int32 | |
name: | |
type: string | |
description: | |
type: string | |
price: | |
type: number | |
format: double | |
error: | |
type: object | |
required: | |
- message | |
properties: | |
message: | |
type: string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment