Class: GrapeOpenapi3::Document
- Inherits:
-
Object
- Object
- GrapeOpenapi3::Document
- Defined in:
- lib/grape_openapi3/document.rb
Overview
Entry point for document assembly. Reads all routes from the Grape API class, builds paths and components, then returns a fully-formed OpenAPI 3.0 Hash (string keys throughout).
Class Method Summary collapse
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(app, config) ⇒ Document
constructor
A new instance of Document.
Constructor Details
#initialize(app, config) ⇒ Document
Returns a new instance of Document.
12 13 14 15 |
# File 'lib/grape_openapi3/document.rb', line 12 def initialize(app, config) @app = app @config = config end |
Class Method Details
.build(app, config) ⇒ Object
8 9 10 |
# File 'lib/grape_openapi3/document.rb', line 8 def self.build(app, config) new(app, config).build end |
Instance Method Details
#build ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/grape_openapi3/document.rb', line 17 def build entity_reader = Readers::EntityReader.new route_list = @app.routes .map { |r| Readers::RouteReader.call(r) } .compact paths = build_paths(route_list, entity_reader) components = build_components(entity_reader) doc = { "openapi" => "3.0.0", "info" => deep_stringify(@config.info), "servers" => @config.servers.map { |s| deep_stringify(s) }, "tags" => @config..map { |t| deep_stringify(t) }, "paths" => paths, "components" => components, "security" => @config.security.map { |s| deep_stringify(s) }, } reject_blank(doc) end |