@@ -86,15 +86,38 @@ public List<OperationTemplateRepresentation> CreateRepresentations(IDictionary<s
86
86
// schema has not yet been created, id is null
87
87
schemaId = null ,
88
88
typeName = pair . Value . Schema != null ? pair . Value . Schema . Type : null ,
89
- // content type is neither application/x-www-form-urlencoded or multipart/form-data, form parameters are null
90
89
formParameters = null
91
90
} ;
91
+ // if content type is neither application/x-www-form-urlencoded or multipart/form-data form parameters are null
92
+ if ( pair . Value . Schema != null && ( pair . Key == "application/x-www-form-urlencoded" || pair . Key == "multipart/form-data" ) )
93
+ {
94
+ representation . formParameters = CreateFormParameters ( pair . Value . Schema ) . ToArray ( ) ;
95
+ } ;
92
96
representations . Add ( representation ) ;
93
97
}
94
98
return representations ;
95
99
96
100
}
97
101
102
+ public List < OperationTemplateParameter > CreateFormParameters ( OpenApiSchema schema )
103
+ {
104
+ List < OperationTemplateParameter > formParameters = new List < OperationTemplateParameter > ( ) ;
105
+ if ( schema . Example != null )
106
+ {
107
+ foreach ( KeyValuePair < string , OperationSchemaExample > pair in schema . Example as Dictionary < string , OperationSchemaExample > )
108
+ {
109
+ OperationTemplateParameter formParameter = new OperationTemplateParameter ( )
110
+ {
111
+ name = pair . Key ,
112
+ required = schema . Required . FirstOrDefault ( val => val == pair . Key ) != null ,
113
+ defaultValue = ( JsonConvert . SerializeObject ( pair . Value . Value ) )
114
+ } ;
115
+ formParameters . Add ( formParameter ) ;
116
+ } ;
117
+ }
118
+ return formParameters ;
119
+ }
120
+
98
121
public List < OperationTemplateParameter > CreateResponseHeaders ( IDictionary < string , OpenApiHeader > headerPairs )
99
122
{
100
123
List < OperationTemplateParameter > headers = new List < OperationTemplateParameter > ( ) ;
@@ -180,4 +203,9 @@ public class OpenApiParameterHeaderIntersection {
180
203
public IOpenApiAny Example { get ; set ; }
181
204
public IDictionary < string , OpenApiExample > Examples { get ; set ; }
182
205
}
206
+
207
+ public class OperationSchemaExample
208
+ {
209
+ public object Value { get ; set ; }
210
+ }
183
211
}
0 commit comments