Class: SwaggerApi::Generator
- Inherits:
-
Object
- Object
- SwaggerApi::Generator
- Defined in:
- lib/swagger_api.rb
Instance Method Summary collapse
- #components ⇒ Object
- #config ⇒ Object
- #create ⇒ Object
- #default_bad_request_response ⇒ Object
- #default_not_found_response ⇒ Object
- #default_responses ⇒ Object
- #default_unauthorized_response ⇒ Object
- #info ⇒ Object
- #json ⇒ Object
- #prettify ⇒ Object
- #responses ⇒ Object
- #security_schemes ⇒ Object
- #server_url ⇒ Object
Instance Method Details
#components ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/swagger_api.rb', line 27 def components { responses: responses, schemas: Components.new(controllers: config.controllers).create, requestBodies: RequestBodies.new(controllers: config.controllers).create, securitySchemes: security_schemes } end |
#config ⇒ Object
36 37 38 |
# File 'lib/swagger_api.rb', line 36 def config @yaml_config ||= JSON.parse(YAML.load_file("#{Rails.root}/config/swagger.yml").to_json, object_class: OpenStruct) end |
#create ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/swagger_api.rb', line 16 def create @config ||= { openapi: '3.0.0', security: [{ api_key: [] }], info: info, servers: [{ url: server_url }], paths: Paths.new(controllers: config.controllers).create, components: components } end |
#default_bad_request_response ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/swagger_api.rb', line 90 def default_bad_request_response { BadRequest: { description: 'Bad Request', content: { 'application/json; charset=utf-8' => { schema: { example: ['The field name is invalid.', 'The id must be present'], type: 'array', items: { type: 'string' } } } } } } end |
#default_not_found_response ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/swagger_api.rb', line 58 def default_not_found_response { NotFound: { description: 'The specified resource was not found', content: { 'application/json; charset=utf-8' => { schema: { type: 'string', example: 'Not Found' } } } } } end |
#default_responses ⇒ Object
54 55 56 |
# File 'lib/swagger_api.rb', line 54 def default_responses {}.merge(default_not_found_response).merge().merge(default_bad_request_response) end |
#default_unauthorized_response ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/swagger_api.rb', line 74 def { Unauthorized: { description: 'Unauthorized', content: { 'application/json; charset=utf-8' => { schema: { type: 'string', example: 'Not Authorized' } } } } } end |
#info ⇒ Object
109 110 111 112 113 114 115 |
# File 'lib/swagger_api.rb', line 109 def info { version: config.info.version, title: config.info.title, description: config.info.description } end |
#json ⇒ Object
12 13 14 |
# File 'lib/swagger_api.rb', line 12 def json create.to_json end |
#prettify ⇒ Object
8 9 10 |
# File 'lib/swagger_api.rb', line 8 def prettify JSON.pretty_generate(JSON.parse(json)) end |
#responses ⇒ Object
50 51 52 |
# File 'lib/swagger_api.rb', line 50 def responses @responses ||= default_responses end |
#security_schemes ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/swagger_api.rb', line 40 def security_schemes { api_key: { type: 'apiKey', name: 'Authorization', in: 'header' } } end |
#server_url ⇒ Object
117 118 119 120 |
# File 'lib/swagger_api.rb', line 117 def server_url return unless config.servers.respond_to?(Rails.env) config.servers.send(Rails.env).url end |