Class: Aws::Resources::Validator::OperationValidator

Inherits:
Object
  • Object
show all
Defined in:
aws-sdk-resources/lib/aws-sdk-resources/validator/operation_validator.rb

Constant Summary collapse

PARAM_SOURCES =
%w(identifier dataMember string integer boolean)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ OperationValidator


9
10
11
12
13
14
15
# File 'aws-sdk-resources/lib/aws-sdk-resources/validator/operation_validator.rb', line 9

def initialize(context)
  @context = context
  @operation = context.value
  @definition = context.definition
  @api = context.api
  @path = context.path
end

Instance Attribute Details

#apiHash (readonly)


21
22
23
# File 'aws-sdk-resources/lib/aws-sdk-resources/validator/operation_validator.rb', line 21

def api
  @api
end

#definitionHash (readonly)


18
19
20
# File 'aws-sdk-resources/lib/aws-sdk-resources/validator/operation_validator.rb', line 18

def definition
  @definition
end

#pathString (readonly)


24
25
26
# File 'aws-sdk-resources/lib/aws-sdk-resources/validator/operation_validator.rb', line 24

def path
  @path
end

Instance Method Details

#path_set?Boolean


38
39
40
# File 'aws-sdk-resources/lib/aws-sdk-resources/validator/operation_validator.rb', line 38

def path_set?
  @operation.key?('path')
end

#request_set?Boolean


27
28
29
# File 'aws-sdk-resources/lib/aws-sdk-resources/validator/operation_validator.rb', line 27

def request_set?
  @operation.key?('request')
end

#resource_set?Boolean


33
34
35
# File 'aws-sdk-resources/lib/aws-sdk-resources/validator/operation_validator.rb', line 33

def resource_set?
  @operation.key?('resource')
end

#validate_param_source_type_not_used(source_type) ⇒ Boolean


146
147
148
149
150
151
152
# File 'aws-sdk-resources/lib/aws-sdk-resources/validator/operation_validator.rb', line 146

def validate_param_source_type_not_used(source_type)
  (@operation['request']['params'] || []).each.with_index do |param, n|
    if param['source'] == source_type
      error("'#{path}/request/params/#{n}/sourceType' is set to '#{source_type}' which is not valid in this context.")
    end
  end
end

#validate_path(options = {}) ⇒ Object

Validates a path by resolving it against the resource definition and the API model. You must specify the :origin and optionally the :target.

== Origins

  • :response - Resolves the path starting from the operation output.

  • :request - Resolves the path starting from the operation input.

  • :self - Resolves the path starting from the resource data/shape.

== Target

  • :resource - Requires the path to resolve to the shape of the operation resource entry.

  • :self - Requries the path to resolve to the shape of the current resource.

Options Hash (options):

  • :origin (:response, :request, :self)
  • :target (:self, :resource)

124
125
126
127
128
129
130
# File 'aws-sdk-resources/lib/aws-sdk-resources/validator/operation_validator.rb', line 124

def validate_path(options = {})
  if path_set?
    validate_path_resolves(options)
  else
    true
  end
end

#validate_path_is_pluralBoolean


135
136
137
138
139
140
141
# File 'aws-sdk-resources/lib/aws-sdk-resources/validator/operation_validator.rb', line 135

def validate_path_is_plural
  if @operation['path'].match(/\[/)
    true
  else
    error("'#{path}/path' must be plural.")
  end
end

#validate_path_setBoolean


94
95
96
97
98
99
100
# File 'aws-sdk-resources/lib/aws-sdk-resources/validator/operation_validator.rb', line 94

def validate_path_set
  if path_set?
    true
  else
    error("'#{path}/path' must be set.")
  end
end

#validate_request(&block) ⇒ Boolean

Performs generic request validation including:

  • request is defined
  • request operation is defined in the api
  • request params resolve as input parameters
  • etc. Yields to the given block if the request is defined and exists in the api.

50
51
52
53
54
55
56
57
58
# File 'aws-sdk-resources/lib/aws-sdk-resources/validator/operation_validator.rb', line 50

def validate_request(&block)
  if
    validate_request_set &&
    validate_operation_exists
  then
    yield if block_given?
    validate_params
  end
end

#validate_request_not_setBoolean


63
64
65
66
67
68
69
# File 'aws-sdk-resources/lib/aws-sdk-resources/validator/operation_validator.rb', line 63

def validate_request_not_set
  if @operation['request']
    error("'#{path}/request' is not valid in this context.")
  else
    true
  end
end

#validate_resource(&block) ⇒ Boolean

Performs basic validation on the resource definition.


84
85
86
87
88
89
90
# File 'aws-sdk-resources/lib/aws-sdk-resources/validator/operation_validator.rb', line 84

def validate_resource(&block)
  if resource_set?
    validate_resource_exists
  else
    error("'#{path}/resource' must be set.")
  end
end

#validate_resource_not_setBoolean


74
75
76
77
78
79
80
# File 'aws-sdk-resources/lib/aws-sdk-resources/validator/operation_validator.rb', line 74

def validate_resource_not_set
  if @operation.key?('resource')
    error("'#{path}/resource' is not valid in this context.")
  else
    true
  end
end