Module: Sinatra::Schema
- Defined in:
- lib/sinatra/schema.rb,
lib/sinatra/schema/link.rb,
lib/sinatra/schema/root.rb,
lib/sinatra/schema/error.rb,
lib/sinatra/schema/version.rb,
lib/sinatra/schema/resource.rb,
lib/sinatra/schema/dsl/links.rb,
lib/sinatra/schema/reference.rb,
lib/sinatra/schema/definition.rb,
lib/sinatra/schema/json_schema.rb,
lib/sinatra/schema/dsl/resources.rb,
lib/sinatra/schema/param_parsing.rb,
lib/sinatra/schema/dsl/definitions.rb,
lib/sinatra/schema/param_validation.rb
Defined Under Namespace
Modules: DSL, ParamParsing, ParamValidation
Classes: BadParams, BadReference, BadRequest, BadResponse, Definition, Error, JsonSchema, Link, Reference, Resource, Root
Constant Summary
collapse
- VERSION =
"0.1.3"
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.registered(app) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/sinatra/schema.rb', line 21
def self.registered(app)
app.helpers ParamParsing
app.helpers ParamValidation
app.error(Sinatra::Schema::BadRequest) do |e|
halt(400, MultiJson.encode(error: e.message))
end
app.error(Sinatra::Schema::BadParams) do |e|
halt(422, MultiJson.encode(error: e.message))
end
app.get "/schema" do
content_type("application/schema+json")
response.["Cache-Control"] = "public, max-age=3600"
MultiJson.encode(JsonSchema.dump(app.schema_root), pretty: true)
end
end
|
Instance Method Details
#resource(path_or_id) {|spec| ... } ⇒ Object
44
45
46
47
48
|
# File 'lib/sinatra/schema.rb', line 44
def resource(path_or_id)
spec = DSL::Resources.new(self, path_or_id)
yield(spec)
schema_root.add_resource(spec.resource)
end
|
#schema_root ⇒ Object
40
41
42
|
# File 'lib/sinatra/schema.rb', line 40
def schema_root
Root.instance
end
|