Class: Passerelle::Schema
- Inherits:
-
Object
- Object
- Passerelle::Schema
- Defined in:
- lib/passerelle/schema.rb
Class Method Summary collapse
- .endpoint(path, method:, &block) ⇒ Object
- .info(&block) ⇒ Object
-
.model(model_class, &block) ⇒ Object
DSL methods will be defined here.
- .models(*model_classes) ⇒ Object
- .security_scheme(name, &block) ⇒ Object
- .server(url) ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ Schema
constructor
A new instance of Schema.
- #to_h ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize ⇒ Schema
Returns a new instance of Schema.
34 35 36 37 38 39 |
# File 'lib/passerelle/schema.rb', line 34 def initialize # By convention, discover all ApplicationRecord descendants @models = discover_models @endpoints = [] @info = default_info end |
Class Method Details
.endpoint(path, method:, &block) ⇒ Object
13 14 15 |
# File 'lib/passerelle/schema.rb', line 13 def endpoint(path, method:, &block) # TODO: Store custom endpoint configuration end |
.info(&block) ⇒ Object
17 18 19 |
# File 'lib/passerelle/schema.rb', line 17 def info(&block) # TODO: Store API info (title, version, description) end |
.model(model_class, &block) ⇒ Object
DSL methods will be defined here
9 10 11 |
# File 'lib/passerelle/schema.rb', line 9 def model(model_class, &block) # TODO: Store model configuration end |
.models(*model_classes) ⇒ Object
29 30 31 |
# File 'lib/passerelle/schema.rb', line 29 def models(*model_classes) # TODO: Override default model discovery end |
.security_scheme(name, &block) ⇒ Object
25 26 27 |
# File 'lib/passerelle/schema.rb', line 25 def security_scheme(name, &block) # TODO: Store security scheme end |
.server(url) ⇒ Object
21 22 23 |
# File 'lib/passerelle/schema.rb', line 21 def server(url) # TODO: Store server URL end |
Instance Method Details
#to_h ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/passerelle/schema.rb', line 45 def to_h { openapi: "3.0.3", info: @info, paths: generate_paths, components: generate_components } end |
#to_json ⇒ Object
41 42 43 |
# File 'lib/passerelle/schema.rb', line 41 def to_json to_h.to_json end |