Skip to content

Commit

Permalink
Api blueprint documentation (#161)
Browse files Browse the repository at this point in the history
* init dredd with user controller api post create user

* add apib for api group[post] status OK

* add apib for api group[post] when group already exist return http status Unprocessable Entity

* add apib for api group[post] when wrong token should return Unauthorized

* completing api blueprint schema

* add apib for api user[GET] for status OK

* add apib for api user[GET] when user is not found should return http Status Not Found

* add apib for api update user[POST] should return http status OK

* add apib for api update user[POST] when token is wrong should return http status Unauthorized

* add apib for api create vpns[POST] return http status OK

* add apib for api create vpns[POST] when token is wrong should return http status Unauthorized

* update travis.yml to support dredd test

* Revert "update travis.yml to support dredd test"

This reverts commit dc0b6d9.

* cleanup description APIB

* add dredd_hooks to Gemfile

* add dredd setup to readme

* remove unused file and folder at api_blueprints

* fix typo in dredd_setup from againts to against

* rename dredd folder to api_blueprint folder, and sync the dredd config
  • Loading branch information
mufti1 authored and giosakti committed Jul 9, 2019
1 parent 96b9c57 commit 4fff536
Show file tree
Hide file tree
Showing 11 changed files with 601 additions and 67 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ group :development, :test do
gem 'capybara'
gem 'coveralls'
gem 'database_cleaner'
gem 'dredd_hooks'
gem 'factory_bot_rails'
gem 'faker'
gem 'mock_redis'
Expand Down
4 changes: 3 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ GEM
dotenv-rails (2.7.2)
dotenv (= 2.7.2)
railties (>= 3.2, < 6.1)
dredd_hooks (0.1.2)
erubi (1.8.0)
execjs (2.7.0)
factory_bot (4.11.1)
Expand Down Expand Up @@ -378,6 +379,7 @@ DEPENDENCIES
database_cleaner
devise (~> 4.6.0)
dotenv-rails
dredd_hooks
factory_bot_rails
faker
font-awesome-rails
Expand Down Expand Up @@ -417,4 +419,4 @@ DEPENDENCIES
whenever

BUNDLED WITH
2.0.1
2.0.2
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ If you want Gate to setup VPN for you then just install OpenVPN with easy rsa. G

## Additional Topics

* [API Blueprint Test](docs/dredd_setup.md)
* [Additional Setup](docs/additional_setup.md)
* [Administration](docs/administration.md)
* [Newrelic Integration](docs/newrelic.md)
Expand Down
9 changes: 9 additions & 0 deletions api_blueprint/bin/dredd_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
# dredd_server.sh
kill -9 $(lsof -i tcp:9865 -t)
export RAILS_ENV=test
export LOG_LEVEL=info
rake db:drop
rake db:setup
bundle exec rails server --port=9865

166 changes: 166 additions & 0 deletions api_blueprint/group.apib
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
FORMAT: 1A

# API Group

# Group [/api/v1/groups]

## Create Groups [POST]
Create new group

+ Request(application/json)

+ Body

{
"access_token": "token",
"name" : "foo"
}

+ Schema

{
"type": "object",
"properties" : {
"name" : {
"type" : "string"
},
"access_token" : {
"type" : "string"
}
}
}

+ Response 200

+ Headers

x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
content-type: application/json; charset=utf-8
etag: W/"5c15461069e69109955c72671ffc465d"
cache-control: max-age=0, private, must-revalidate
x-request-id: 0613ec11-afd7-4dc0-9096-fee607d71c12
x-runtime: 0.073641
connection: close
transfer-encoding: chunked

+ Body

{
"id": 1,
"name": "foo"
}
+ Schema

{
"type": "object",
"properties" : {
"id" : {
"type" : "int"
},
"name" : {
"type" : "string"
}
}
}

+ Request(application/json)

+ Body

{
"access_token": "token",
"name" : "foo"
}

+ Schema

{
"type": "object",
"properties" : {
"name" : {
"type" : "string"
},
"access_token" : {
"type" : "string"
}
}
}

+ Response 422

+ Headers

x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
content-type: application/json; charset=utf-8
cache-control: no-cache
x-request-id: 30ec7a3a-4794-435b-a5b9-8ff480cd648c
x-runtime: 0.007976
connection: close
transfer-encoding: chunked

+ Body

{
"status": "group already exist",
"id": 1,
"name": "foo"
}
+ Schema

{
"type": "object",
"properties" : {
"status" : {
"type" : "string"
},
"id" : {
"type" : "int"
},
"name" : {
"type" : "string"
}
}
}

+ Request(application/json)

+ Body

{
"access_token": "wrong token",
"name" : "foo"
}

+ Schema

{
"type": "object",
"properties" : {
"name" : {
"type" : "string"
},
"access_token" : {
"type" : "string"
}
}
}

+ Response 401

+ Headers

x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
content-type: text/html
cache-control: no-cache
x-request-id: 30276bf6-0ce6-4ba6-b87d-7528b4f2c85d
x-runtime: 0.002650
connection: close
transfer-encoding: chunked

+ Body
16 changes: 16 additions & 0 deletions api_blueprint/hooks/dredd_hooks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ENV['RAILS_ENV'] ||= 'test'

require File.expand_path('../../config/environment', __dir__)
require 'dredd_hooks/methods'

include DreddHooks::Methods

before_all do |_|
user = User.create(name: 'foo', email: '[email protected]', admin: 1)
access_token = AccessToken.new
access_token.token = 'token'
access_token.user = user
user.access_token = access_token
access_token.save!
user.save!
end
Loading

0 comments on commit 4fff536

Please sign in to comment.