Class: DoctorSwagger::Operation

Inherits:
Object
  • Object
show all
Defined in:
lib/doctor_swagger/operation.rb

Instance Method Summary collapse

Constructor Details

#initialize(nickname, &block) ⇒ Operation

Returns a new instance of Operation.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/doctor_swagger/operation.rb', line 5

def initialize(nickname, &block)
  @nickname = nickname
  @summary  = ''
  @parameters = []
  @error_responses = []
  @embeds = []
  @scopes = []
  @type   = ""
  @internal_type = ""
  instance_eval(&block)
  add_embedded_parameter unless @embeds.empty?
end

Instance Method Details

#as_jsonObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/doctor_swagger/operation.rb', line 74

def as_json(*)

  {
    'parameters'           => @parameters.map(&:as_json),
    'httpMethod'           => @method.to_s.upcase,
    'notes'                => @notes,
    'embeds'               => @embeds.map(&:to_s),
    'scopes'               => @scopes.map(&:to_s),
    'errorResponses'       => @error_responses.map(&:as_json),
    'summary'              => @summary,
    'nickname'             => @nickname.to_s,
    'responseClass'        => @type,
    'responseTypeInternal' => @internal_type
  }
end

#embeds(*embeds) ⇒ Object



58
59
60
# File 'lib/doctor_swagger/operation.rb', line 58

def embeds(*embeds)
  @embeds |= embeds
end

#error(http_status, error) ⇒ Object



54
55
56
# File 'lib/doctor_swagger/operation.rb', line 54

def error(http_status, error)
  @error_responses << ErrorResponse.new(http_status, error)
end

#header_parameter(param, &block) ⇒ Object



30
31
32
# File 'lib/doctor_swagger/operation.rb', line 30

def header_parameter(param, &block)
  @parameters << HeaderParameter.new(param, &block)
end

#internal_type(internal_type) ⇒ Object



70
71
72
# File 'lib/doctor_swagger/operation.rb', line 70

def internal_type(internal_type)
  @internal_type = internal_type
end

#method(meth) ⇒ Object



38
39
40
# File 'lib/doctor_swagger/operation.rb', line 38

def method(meth)
  @method = meth
end

#notes(notes) ⇒ Object



42
43
44
# File 'lib/doctor_swagger/operation.rb', line 42

def notes(notes)
  @notes = process_markdown(notes)
end

#path_parameter(param, &block) ⇒ Object



22
23
24
# File 'lib/doctor_swagger/operation.rb', line 22

def path_parameter(param, &block)
  @parameters << PathParameter.new(param, &block)
end

#post_body(&block) ⇒ Object



34
35
36
# File 'lib/doctor_swagger/operation.rb', line 34

def post_body(&block)
  @parameters << PostBody.new(&block)
end

#post_parameter(param, &block) ⇒ Object



26
27
28
# File 'lib/doctor_swagger/operation.rb', line 26

def post_parameter(param, &block)
  @parameters << PostParameter.new(param, &block)
end

#query_parameter(param, &block) ⇒ Object



18
19
20
# File 'lib/doctor_swagger/operation.rb', line 18

def query_parameter(param, &block)
  @parameters << QueryParameter.new(param, &block)
end

#scopes(*scopes) ⇒ Object



62
63
64
# File 'lib/doctor_swagger/operation.rb', line 62

def scopes(*scopes)
  @scopes |= scopes
end

#standard_errorsObject



50
51
52
# File 'lib/doctor_swagger/operation.rb', line 50

def standard_errors
  @error_responses |= Errors.standard_errors
end

#summary(summary) ⇒ Object



46
47
48
# File 'lib/doctor_swagger/operation.rb', line 46

def summary(summary)
  @summary = summary
end

#type(type) ⇒ Object



66
67
68
# File 'lib/doctor_swagger/operation.rb', line 66

def type(type)
  @type = type
end