@@ -134,12 +134,15 @@ def _get_parameters(link, encoding):
134
134
"""
135
135
parameters = []
136
136
properties = {}
137
+ examples = {}
137
138
required = []
138
139
139
140
for field in link .fields :
140
- location = get_location (link , field )
141
- field_description = _get_field_description (field )
142
- field_type = _get_field_type (field )
141
+ location = openapi_codec .encode .get_location (link , field )
142
+ field_description = openapi_codec .encode ._get_field_description (field )
143
+ field_type = openapi_codec .encode ._get_field_type (field )
144
+ field_example = getattr (field , 'example' , None )
145
+
143
146
if location == 'form' :
144
147
if encoding in ('multipart/form-data' , 'application/x-www-form-urlencoded' ):
145
148
# 'formData' in swagger MUST be one of these media types.
@@ -164,6 +167,10 @@ def _get_parameters(link, encoding):
164
167
if field_type == 'array' :
165
168
schema_property ['items' ] = {'type' : 'string' }
166
169
properties [field .name ] = schema_property
170
+
171
+ if field_example is not None :
172
+ examples [field .name ] = field_example
173
+
167
174
if field .required :
168
175
required .append (field .name )
169
176
elif location == 'body' :
@@ -193,13 +200,16 @@ def _get_parameters(link, encoding):
193
200
parameters .append (parameter )
194
201
195
202
if properties :
203
+ schema = {
204
+ 'type' : 'object' ,
205
+ 'properties' : properties
206
+ }
207
+ if examples :
208
+ schema ['example' ] = examples
196
209
parameter = {
197
210
'name' : 'data' ,
198
211
'in' : 'body' ,
199
- 'schema' : {
200
- 'type' : 'object' ,
201
- 'properties' : properties
202
- }
212
+ 'schema' : schema
203
213
}
204
214
if required :
205
215
parameter ['schema' ]['required' ] = required
0 commit comments