Skip to content

Instantly share code, notes, and snippets.

@DKbyo
Created November 18, 2016 00:22
Show Gist options
  • Select an option

  • Save DKbyo/bf482408854059855ceddd01978a31b1 to your computer and use it in GitHub Desktop.

Select an option

Save DKbyo/bf482408854059855ceddd01978a31b1 to your computer and use it in GitHub Desktop.
# this is an example of the Uber API
# as a demonstration of an API spec in YAML
swagger: '2.0'
info:
title: Cool Climate User API
description: API used by the Cool Climate Network in the Cool Climate Calculator
version: "1.0.0"
# the domain of the service
host: calculator.coolclimatenetwork.net
# array of all schemes that your API supports
schemes:
- http
# will be prefixed to all paths
basePath: /
produces:
- application/json
paths:
/user:
post:
summary: Add new user
description: This endpoint sign up a new user in the Cool Climate Calculator in order to store the user answers.
consumes:
- application/json
produces:
- application/json
parameters:
- name: user
in: body
required: true
schema:
$ref: '#/definitions/User'
tags:
- User
responses:
200:
description: Result of user sign up
schema:
$ref: '#/definitions/ResponseUser'
delete:
summary: Delete the user from Cool Climate Calculator
description: This endpoint delete the user in the Cool Climate Calculator
produces:
- application/json
parameters:
- name: Authorization
in: header
type: string
required: true
description: User's jti token
tags:
- User
responses:
200:
description: Result of the user deletion
schema:
$ref: '#/definitions/ResponseGeneric'
put:
summary: Update the user profile, total carbon footprint and answers
description: This endpoint update the user profile, total carbon footprint and answers in the Cool Climate Calculator
produces:
- application/json
parameters:
- name: Authorization
in: header
type: string
required: true
description: User's jti token
- name: user
in: body
required: true
schema:
$ref: '#/definitions/User'
tags:
- User
responses:
200:
description: Result of the user profile update
schema:
$ref: '#/definitions/ResponseGeneric'
/user/login:
post:
summary: Login in the Cool Climate Calculator
description: This enpoint login the user in the Cool Climate Calculator and retrieve a jti token necessary for all other endpoints.
consumes:
- application/json
produces:
- application/json
parameters:
- name: user login
in: body
required: true
schema:
$ref: '#/definitions/UserLogin'
tags:
- User
responses:
200:
description: Result of user login
schema:
$ref: '#/definitions/ResponseUser'
/user/loginfacebook:
post:
summary: Login or signup in the Cool Climate Calculator using facebook id and facebook access token
description: This enpoint login or singup the user in the Cool Climate Calculator an retrieve a jti token necessary for all other endpoints using the Facebook login.
consumes:
- application/json
produces:
- application/json
parameters:
- name: user facebook login
in: body
required: true
schema:
$ref: '#/definitions/UserLoginFacebook'
tags:
- User
responses:
200:
description: Result of user login
schema:
$ref: '#/definitions/ResponseUser'
/user/logout:
get:
summary: Logout from the Cool Climate Calculator
description: This endpoint logout from the Cool Climate Calculator and invalidate the token
produces:
- application/json
parameters:
- name: Authorization
in: header
type: string
required: true
description: User's jti token
tags:
- User
responses:
200:
description: Result of the user logout
schema:
$ref: '#/definitions/ResponseGeneric'
/user/logoutall:
get:
summary: Logout from the Cool Climate Calculator
description: This endpoint logout from the Cool Climate Calculator and invalidate all the tokens
produces:
- application/json
parameters:
- name: Authorization
in: header
type: string
required: true
description: User's jti token
tags:
- User
responses:
200:
description: Result of the user logout
schema:
$ref: '#/definitions/ResponseGeneric'
/user/answers:
put:
summary: Update the user's answers
description: This endpoint update the user's answers of the Cool Climate Calculator
produces:
- application/json
parameters:
- name: Authorization
in: header
type: string
required: true
description: User's jti token
- name: Answers
in: body
required: true
schema:
$ref: '#/definitions/Answers'
tags:
- User
responses:
200:
description: Result of the update answers
schema:
$ref: '#/definitions/ResponseGeneric'
/user/location:
put:
summary: Update the user's location
description: This endpoint update the user's location of the Cool Climate Calculator
produces:
- application/json
parameters:
- name: Authorization
in: header
type: string
required: true
description: User's jti token
- name: Location
in: body
required: true
schema:
$ref: '#/definitions/Location'
tags:
- User
responses:
200:
description: Result of the update answers
schema:
$ref: '#/definitions/ResponseGeneric'
/user/reset/req:
post:
summary: Reset user's password
description: Send an email to the user in order to reset the password
produces:
- application/json
parameters:
- name: Authorization
in: header
type: string
required: true
description: User's jti token
- name: Email
in: body
required: true
schema:
$ref: '#/definitions/Email'
tags:
- User
responses:
200:
description: Result of the update answers
schema:
$ref: '#/definitions/ResponseGeneric'
/user/reset:
post:
summary: Confirm the user's password
description: This endpoint confirm the reset of user's password, is generated using the /user/reset/req endpoint,
produces:
- application/json
parameters:
- name: id
in: formData
type: string
required: true
description: User id
- name: token
in: formData
type: string
required: true
description: User's token that was sent via email
- name: password
in: formData
type: string
required: true
description: New user's password
tags:
- User
responses:
200:
description: Result of the update answers
schema:
$ref: '#/definitions/ResponseGeneric'
/user/leaders:
post:
summary: Get the leaders
description: This endpoint retrieve ascendingly the users by total carbon footprint
produces:
- application/json
parameters:
- name: limit
in: query
type: number
required: false
description: Number of records
- name: offset
in: query
type: number
required: false
description: Start point of the query
- name: category
in: query
type: string
required: false
enum:
- food
- housing
- shopping
- transport
description: Carbon footprint category
- name: city
in: query
type: string
required: false
description: Leaders city
- name: state
in: query
type: string
required: false
description: Leaders state
tags:
- User
responses:
200:
description: Result of the update answers
schema:
$ref: '#/definitions/ResponseGeneric'
definitions:
User:
type: object
properties:
first_name:
type: string
description: User's first name
last_name:
type: string
description: User's last name
password:
type: string
format: password
description: User's password
email:
type: string
description: User's email, this should be unique, is used to login into the Cool Climate Calculator
city:
type: string
description: User's city
state:
type: string
description: User's state
country:
type: string
description: User's country
answers:
type: object
description: Answers of the Cool Climate Calculator
total_footprint:
type: number
description: Total of carbon footprint calculated by the Cool Climate Calculator
ResponseGeneric:
type: object
properties:
success:
type: boolean
description: A flag that indicates if the process was successful
error:
type: string
description: A JSON strinfigied with the error description
ResponseUser:
type: object
properties:
success:
type: boolean
description: A flag that indicates if the process was successful
data:
$ref: '#/definitions/DataResponseUser'
error:
type: string
description: A JSON strinfigied with the error description
DataResponseUser:
type: object
properties:
name:
type: string
description: User's first name
token:
type: string
description: User's jti token used to call all the other API endpoints
Data:
$ref: '#/definitions/Answers'
Answers:
type: string
description: The answers of the Cool Climate Calculator
UserLogin:
type: object
properties:
email:
type: string
description: User's email
password:
type: string
format: password
description: User's password
UserLoginFacebook:
type: object
properties:
facebookID:
type: string
description: User's facebook id
facebookToken:
type: string
description: User's facebook token
answers:
$ref: '#/definitions/Answers'
Location:
type: object
properties:
city:
type: string
description: User's city
state:
type: string
description: User's state
country:
type: string
description: User's country
Email:
type: object
properties:
email:
type: string
description: User's email
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment