@@ -94,55 +94,54 @@ def wrapper(*f_args, **f_kwargs):
9494 def _prepare_arguments_doc (self , doc , doc_info , spec , ** kwargs ):
9595 # This callback should run first as it overrides existing parameters
9696 # in doc. Following callbacks should append to parameters list.
97- operation = doc_info .get ('arguments' , {})
98-
99- parameters = [
100- p for p in operation .get ('parameters' , [])
101- if isinstance (p , abc .Mapping )
102- ]
103-
104- # OAS 2
105- if spec .openapi_version .major < 3 :
106- for param in parameters :
107- if param ['in' ] in (
108- self .DEFAULT_LOCATION_CONTENT_TYPE_MAPPING
109- ):
110- content_type = (
111- param .pop ('content_type' , None ) or
112- self .DEFAULT_LOCATION_CONTENT_TYPE_MAPPING [
113- param ['in' ]]
114- )
115- if content_type != DEFAULT_REQUEST_BODY_CONTENT_TYPE :
116- operation ['consumes' ] = [content_type , ]
117- # body and formData are mutually exclusive
118- break
119- # OAS 3
120- else :
121- for param in parameters :
122- if param ['in' ] in (
123- self .DEFAULT_LOCATION_CONTENT_TYPE_MAPPING
124- ):
125- request_body = {
126- x : param [x ]
127- for x in ('description' , 'required' )
128- if x in param
129- }
130- fields = {
131- x : param .pop (x )
132- for x in ('schema' , 'example' , 'examples' )
133- if x in param
134- }
135- content_type = (
136- param .pop ('content_type' , None ) or
137- self .DEFAULT_LOCATION_CONTENT_TYPE_MAPPING [
138- param ['in' ]]
139- )
140- request_body ['content' ] = {content_type : fields }
141- operation ['requestBody' ] = request_body
142- # There can be only one requestBody
143- operation ['parameters' ].remove (param )
144- if not operation ['parameters' ]:
145- del operation ['parameters' ]
146- break
147- doc = deepupdate (doc , operation )
97+ operation = doc_info .get ('arguments' )
98+ if operation :
99+ parameters = [
100+ p for p in operation ['parameters' ]
101+ if isinstance (p , abc .Mapping )
102+ ]
103+ # OAS 2
104+ if spec .openapi_version .major < 3 :
105+ for param in parameters :
106+ if param ['in' ] in (
107+ self .DEFAULT_LOCATION_CONTENT_TYPE_MAPPING
108+ ):
109+ content_type = (
110+ param .pop ('content_type' , None ) or
111+ self .DEFAULT_LOCATION_CONTENT_TYPE_MAPPING [
112+ param ['in' ]]
113+ )
114+ if content_type != DEFAULT_REQUEST_BODY_CONTENT_TYPE :
115+ operation ['consumes' ] = [content_type , ]
116+ # body and formData are mutually exclusive
117+ break
118+ # OAS 3
119+ else :
120+ for param in parameters :
121+ if param ['in' ] in (
122+ self .DEFAULT_LOCATION_CONTENT_TYPE_MAPPING
123+ ):
124+ request_body = {
125+ x : param [x ]
126+ for x in ('description' , 'required' )
127+ if x in param
128+ }
129+ fields = {
130+ x : param .pop (x )
131+ for x in ('schema' , 'example' , 'examples' )
132+ if x in param
133+ }
134+ content_type = (
135+ param .pop ('content_type' , None ) or
136+ self .DEFAULT_LOCATION_CONTENT_TYPE_MAPPING [
137+ param ['in' ]]
138+ )
139+ request_body ['content' ] = {content_type : fields }
140+ operation ['requestBody' ] = request_body
141+ # There can be only one requestBody
142+ operation ['parameters' ].remove (param )
143+ if not operation ['parameters' ]:
144+ del operation ['parameters' ]
145+ break
146+ doc = deepupdate (doc , operation )
148147 return doc
0 commit comments