Class: Aikido::Zen::Request::Schema
- Inherits:
-
Object
- Object
- Aikido::Zen::Request::Schema
show all
- Defined in:
- lib/aikido/zen/request/schema.rb,
lib/aikido/zen/request/schema/builder.rb,
lib/aikido/zen/request/schema/auth_schemas.rb,
lib/aikido/zen/request/schema/empty_schema.rb,
lib/aikido/zen/request/schema/auth_discovery.rb
Overview
Defines the shape of a request received by your application as seen by Zen.
This is used to understand how requests are made against your app, so
dynamic security testing on your API endpoints can take place.
Defined Under Namespace
Classes: AuthDiscovery, AuthSchemas, Builder
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(content_type:, body_schema:, query_schema:, auth_schema:) ⇒ Schema
36
37
38
39
40
41
|
# File 'lib/aikido/zen/request/schema.rb', line 36
def initialize(content_type:, body_schema:, query_schema:, auth_schema:)
@content_type = content_type
@query_schema = query_schema
@body_schema = body_schema
@auth_schema = auth_schema
end
|
Instance Attribute Details
23
24
25
|
# File 'lib/aikido/zen/request/schema.rb', line 23
def auth_schema
@auth_schema
end
|
#body_schema ⇒ Aikido::Zen::Request::Schema::Definition
17
18
19
|
# File 'lib/aikido/zen/request/schema.rb', line 17
def body_schema
@body_schema
end
|
#content_type ⇒ Symbol?
14
15
16
|
# File 'lib/aikido/zen/request/schema.rb', line 14
def content_type
@content_type
end
|
#query_schema ⇒ Aikido::Zen::Request::Schema::Definition
20
21
22
|
# File 'lib/aikido/zen/request/schema.rb', line 20
def query_schema
@query_schema
end
|
Class Method Details
Extracts the request information from the current Context (if configured)
and builds a Schema out of it.
.from_json(data) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/aikido/zen/request/schema.rb', line 55
def self.from_json(data)
if data.empty?
return Request::Schema.new(
content_type: nil,
body_schema: EMPTY_SCHEMA,
query_schema: EMPTY_SCHEMA,
auth_schema: Aikido::Zen::Request::Schema::AuthSchemas.new([])
)
end
content_type = data["body"].nil? ? nil : data["body"]["type"]
body_schema = data["body"].nil? ? EMPTY_SCHEMA : Aikido::Zen::Request::Schema::Definition.from_json(data["body"]["schema"])
query_schema = data["query"].nil? ? EMPTY_SCHEMA : Aikido::Zen::Request::Schema::Definition.from_json(data["query"])
auth_schema = Aikido::Zen::Request::Schema::AuthSchemas.from_json(data["auth"])
Request::Schema.new(
content_type: content_type,
body_schema: body_schema,
query_schema: query_schema,
auth_schema: auth_schema
)
end
|
Instance Method Details
#==(other) ⇒ Object
93
94
95
96
97
98
99
|
# File 'lib/aikido/zen/request/schema.rb', line 93
def ==(other)
other.is_a?(self.class) &&
@content_type == other.content_type &&
@query_schema == other.query_schema &&
@body_schema == other.body_schema &&
@auth_schema == other.auth_schema
end
|
#as_json ⇒ Hash
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/aikido/zen/request/schema.rb', line 44
def as_json
body = {"type" => content_type, "schema" => body_schema.as_json}.compact
body = nil if body.empty?
{
"body" => body,
"query" => query_schema.as_json,
"auth" => auth_schema.as_json
}.compact
end
|
Merges the request specification with another request's specification.
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/aikido/zen/request/schema.rb', line 81
def merge(other)
return self if other.nil?
self.class.new(
content_type: other.content_type,
body_schema: body_schema.merge(other.body_schema),
query_schema: query_schema.merge(other.query_schema),
auth_schema: auth_schema.merge(other.auth_schema)
)
end
|