-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from cosywasswa/api-documentation
Api documentation
- Loading branch information
Showing
11 changed files
with
203 additions
and
2 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Rswag::Api.configure do |c| | ||
|
||
# Specify a root folder where Swagger JSON files are located | ||
# This is used by the Swagger middleware to serve requests for API descriptions | ||
# NOTE: If you're using rswag-specs to generate Swagger, you'll need to ensure | ||
# that it's configured to generate files in the same folder | ||
c.swagger_root = Rails.root.to_s + '/swagger' | ||
|
||
# Inject a lambda function to alter the returned Swagger prior to serialization | ||
# The function will have access to the rack env for the current request | ||
# For example, you could leverage this to dynamically assign the "host" property | ||
# | ||
#c.swagger_filter = lambda { |swagger, env| swagger['host'] = env['HTTP_HOST'] } | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Rswag::Ui.configure do |c| | ||
|
||
# List the Swagger endpoints that you want to be documented through the | ||
# swagger-ui. The first parameter is the path (absolute or relative to the UI | ||
# host) to the corresponding endpoint and the second is a title that will be | ||
# displayed in the document selector. | ||
# NOTE: If you're using rspec-api to expose Swagger files | ||
# (under swagger_root) as JSON or YAML endpoints, then the list below should | ||
# correspond to the relative paths for those endpoints. | ||
|
||
c.swagger_endpoint '/api-docs/v1/swagger.yaml', 'API V1 Docs' | ||
|
||
# Add Basic Auth in case your API is private | ||
# c.basic_auth_enabled = true | ||
# c.basic_auth_credentials 'username', 'password' | ||
end |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require 'swagger_helper' | ||
|
||
describe 'Comments API' do | ||
path '/users/{user_id}/posts/{post_id}/comments' do | ||
parameter name: 'user_id', in: :path, type: :integer, required: true, description: 'User ID' | ||
parameter name: 'post_id', in: :path, type: :integer, required: true, description: 'Post ID' | ||
get 'Retrieve all comments of a post' do | ||
tags 'Comments' | ||
produces 'application/json' | ||
response '200', 'OK' do | ||
run_test! | ||
end | ||
end | ||
post 'Create a new comment for a post' do | ||
tags 'Comments' | ||
consumes 'application/json' | ||
parameter name: :comment, in: :body, schema: { | ||
type: :object, | ||
properties: { | ||
text: { type: :string } | ||
}, | ||
required: ['text'] | ||
} | ||
response '201', 'Created' do | ||
let(:comment) { { text: 'string' } } | ||
run_test! | ||
end | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require 'swagger_helper' | ||
|
||
describe 'Posts API' do | ||
path '/users/{user_id}/posts' do | ||
parameter name: 'user_id', in: :path, type: :integer, required: true, description: 'User ID' | ||
get 'Retrieve all the posts of a user' do | ||
tags 'Posts' | ||
produces 'application/json' | ||
response '200', 'OK' do | ||
run_test! | ||
end | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.configure do |config| | ||
# Specify a root folder where Swagger JSON files are generated | ||
# NOTE: If you're using the rswag-api to serve API descriptions, you'll need | ||
# to ensure that it's configured to serve Swagger from the same folder | ||
config.swagger_root = Rails.root.join('swagger').to_s | ||
|
||
# Define one or more Swagger documents and provide global metadata for each one | ||
# When you run the 'rswag:specs:swaggerize' rake task, the complete Swagger will | ||
# be generated at the provided relative path under swagger_root | ||
# By default, the operations defined in spec files are added to the first | ||
# document below. You can override this behavior by adding a swagger_doc tag to the | ||
# the root example_group in your specs, e.g. describe '...', swagger_doc: 'v2/swagger.json' | ||
config.swagger_docs = { | ||
'v1/swagger.yaml' => { | ||
openapi: '3.0.1', | ||
info: { | ||
title: 'API V1', | ||
version: 'v1' | ||
}, | ||
paths: {}, | ||
servers: [ | ||
{ | ||
url: 'https://{defaultHost}', | ||
variables: { | ||
defaultHost: { | ||
default: 'www.example.com' | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
|
||
# Specify the format of the output Swagger file when running 'rswag:specs:swaggerize'. | ||
# The swagger_docs configuration option has the filename including format in | ||
# the key, this may want to be changed to avoid putting yaml in json files. | ||
# Defaults to json. Accepts ':json' and ':yaml'. | ||
config.swagger_format = :yaml | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--- | ||
openapi: 3.0.1 | ||
info: | ||
title: API V1 | ||
version: v1 | ||
paths: | ||
"/users/{user_id}/posts/{post_id}/comments": | ||
parameters: | ||
- name: user_id | ||
in: path | ||
required: true | ||
description: User ID | ||
schema: | ||
type: integer | ||
- name: post_id | ||
in: path | ||
required: true | ||
description: Post ID | ||
schema: | ||
type: integer | ||
get: | ||
summary: Retrieve all comments of a post | ||
tags: | ||
- Comments | ||
responses: | ||
'200': | ||
description: OK | ||
post: | ||
summary: Create a new comment for a post | ||
tags: | ||
- Comments | ||
parameters: [] | ||
responses: | ||
'201': | ||
description: Created | ||
requestBody: | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
properties: | ||
text: | ||
type: string | ||
required: | ||
- text | ||
"/users/{user_id}/posts": | ||
parameters: | ||
- name: user_id | ||
in: path | ||
required: true | ||
description: User ID | ||
schema: | ||
type: integer | ||
get: | ||
summary: Retrieve all the posts of a user | ||
tags: | ||
- Posts | ||
responses: | ||
'200': | ||
description: OK | ||
servers: | ||
- url: https://{defaultHost} | ||
variables: | ||
defaultHost: | ||
default: www.example.com |