Skip to content

Commit

Permalink
feature: move swagger to apress-documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
deniskorobicyn committed May 5, 2017
1 parent 798cdc3 commit 0cc731e
Show file tree
Hide file tree
Showing 17 changed files with 104 additions and 58 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
source "https://gems.railsc.ru"
source "https://rubygems.org"

gem 'apress-documentation', git: '[email protected]:abak-press/apress-documentation.git'

# Specify your gem's dependencies in apress-api.gemspec
gemspec
14 changes: 14 additions & 0 deletions app/docs/swagger/v1/default_responses/bad_request.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Swagger
module DefaultResponses
module BadRequest
def self.extended(base)
base.response 400 do
key :description, "Переданные параметры не могут быть обработаны"
schema do
key :'$ref', :'Swagger::V1::::Models::Apress::Api::UnprocessableError'
end
end
end
end
end
end
14 changes: 14 additions & 0 deletions app/docs/swagger/v1/default_responses/not_found.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Swagger
module DefaultResponses
module NotFound
def self.extended(base)
base.response 404 do
key :description, "Запрашиваемый ресурс не найден"
schema do
key :'$ref', :'Swagger::V1::::Models::Apress::Api::SimpleError'
end
end
end
end
end
end
14 changes: 14 additions & 0 deletions app/docs/swagger/v1/default_responses/unauthenticated.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Swagger
module DefaultResponses
module Unauthenticated
def self.extended(base)
base.response 401 do
key :description, "Запрос не прошел аутентификацию (проблема с подписью запроса)"
schema do
key :'$ref', :'Swagger::V1::::Models::Apress::Api::SimpleError'
end
end
end
end
end
end
14 changes: 14 additions & 0 deletions app/docs/swagger/v1/default_responses/unauthorized.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Swagger
module DefaultResponses
module Unauthorized
def self.extended(base)
base.response 403 do
key :description, "Нет доступа к ресурсу"
schema do
key :'$ref', :'Swagger::V1::::Models::Apress::Api::SimpleError'
end
end
end
end
end
end
14 changes: 14 additions & 0 deletions app/docs/swagger/v1/default_responses/unprocessable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Swagger
module DefaultResponses
module Unprocessable
def self.extended(base)
base.response 422 do
key :description, "Переданные параметры не валидны"
schema do
key :'$ref', :'Swagger::V1::::Models::Apress::Api::UnprocessableError'
end
end
end
end
end
end
11 changes: 11 additions & 0 deletions app/docs/swagger/v1/default_responses/updates_locked.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Swagger
module DefaultResponses
module UpdatedLocked
def self.extended(base)
base.response 503 do
key :description, "Закрыто редактирование"
end
end
end
end
end
2 changes: 1 addition & 1 deletion app/docs/swagger/v1/models/apress/api/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module V1
module Models
module Apress
module Api
class Client < ::Apress::Api::Swagger::Schema
class Client < ::Apress::Documentation::Swagger::Schema
swagger_schema name.to_sym do
key :required, [
:id,
Expand Down
2 changes: 1 addition & 1 deletion app/docs/swagger/v1/models/apress/api/simple_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module V1
module Models
module Apress
module Api
class SimpleError < ::Apress::Api::Swagger::Schema
class SimpleError < ::Apress::Documentation::Swagger::Schema
swagger_schema name.to_sym do
keys = [
:status,
Expand Down
4 changes: 3 additions & 1 deletion app/docs/swagger/v1/models/apress/api/unproccesable_error.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
require_relative 'unprocessable_error'

module Swagger
module V1
module Models
module Apress
module Api
# Deprecated: Please use `UnprocessableError` instead
class UnproccesableError < ::Apress::Api::Swagger::Schema
class UnproccesableError < ::Apress::Documentation::Swagger::Schema
include UnprocessableError::Schema
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module V1
module Models
module Apress
module Api
class UnprocessableError < ::Apress::Api::Swagger::Schema
class UnprocessableError < ::Apress::Documentation::Swagger::Schema
module Schema
extend ActiveSupport::Concern

Expand Down
2 changes: 1 addition & 1 deletion app/docs/swagger/v1/root.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Swagger
module V1
class Root < ::Apress::Api::Swagger::Schema
class Root < ::Apress::Documentation::Swagger::Schema
swagger_root do
key :swagger, '2.0'
info do
Expand Down
1 change: 0 additions & 1 deletion apress-api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency "jbuilder", ">= 2.3.1"
spec.add_runtime_dependency "attr_extras", ">= 4.4.0"
spec.add_runtime_dependency 'swagger-core', '>= 0.3.0'
spec.add_runtime_dependency 'swagger-blocks', '>= 1.3'

spec.add_development_dependency "bundler", "~> 1.7"
spec.add_development_dependency "rake", "~> 10.0"
Expand Down
11 changes: 11 additions & 0 deletions lib/apress/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,16 @@
require "api_auth"
require "attr_extras"
require 'swagger/blocks'
require 'apress/documentation'
require "apress/api/version"
require "apress/api/engine"

module Apress
module Api
module Swagger
def self.const_missing(name)
::Apress::Documentation::Swagger.const_get(name)
end
end
end
end
9 changes: 3 additions & 6 deletions lib/apress/api/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ module Apress
module Api
class Engine < Rails::Engine
config.autoload_paths << config.root.join("lib")
config.paths.add 'app/docs', :eager_load => true
config.paths.add 'app/docs', eager_load: false

Apress::Documentation.add_load_path(config.root.join('app/docs'))

initializer "apress-api", before: :load_init_rb do |app|
app.config.paths["db/migrate"].concat(config.paths["db/migrate"].expanded)

glob = config.root.join('app/docs/**/*.rb')
app.config.to_prepare do
Dir[glob].each { |file| require_dependency file }
end

app.config.api = {
secret_token_ttl: 1.hour,
refresh_token_ttl: 1.week,
Expand Down
25 changes: 0 additions & 25 deletions lib/apress/api/swagger/generator.rb

This file was deleted.

21 changes: 0 additions & 21 deletions lib/apress/api/swagger/schema.rb

This file was deleted.

0 comments on commit 0cc731e

Please sign in to comment.