Class: Passerelle::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/passerelle/schema.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSchema

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_hObject



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_jsonObject



41
42
43
# File 'lib/passerelle/schema.rb', line 41

def to_json
  to_h.to_json
end