@@ -27,16 +27,17 @@ public List<OperationTemplate> CreateOperationTemplates(OpenApiDocument doc)
27
27
description = operation . Value . Description ,
28
28
displayName = operation . Value . Summary ,
29
29
templateParameters = CreateTemplateParameters ( operation . Value . Parameters ) . ToArray ( ) ,
30
-
31
- //unfinished
32
30
responses = CreateOperationResponses ( operation . Value . Responses ) . ToArray ( ) ,
33
31
request = CreateOperationRequest ( operation . Value ) ,
32
+
33
+ //unfinished
34
34
policies = null
35
35
}
36
36
} ;
37
37
operationTemplates . Add ( op ) ;
38
38
}
39
39
}
40
+
40
41
return operationTemplates ;
41
42
}
42
43
@@ -47,9 +48,7 @@ public OperationTemplateRequest CreateOperationRequest(OpenApiOperation operatio
47
48
description = operation . RequestBody != null ? operation . RequestBody . Description : null ,
48
49
queryParameters = CreateTemplateParameters ( operation . Parameters . Where ( p => p . In == ParameterLocation . Query ) . ToList ( ) ) . ToArray ( ) ,
49
50
headers = CreateTemplateParameters ( operation . Parameters . Where ( p => p . In == ParameterLocation . Header ) . ToList ( ) ) . ToArray ( ) ,
50
-
51
- //unfinished
52
- representations = null
51
+ representations = operation . RequestBody != null ? CreateRepresentations ( operation . RequestBody . Content ) . ToArray ( ) : null
53
52
} ;
54
53
return request ;
55
54
}
@@ -64,14 +63,38 @@ public List<OperationsTemplateResponse> CreateOperationResponses(OpenApiResponse
64
63
statusCode = response . Key ,
65
64
description = response . Value . Description ,
66
65
headers = CreateResponseHeaders ( response . Value . Headers ) . ToArray ( ) ,
67
-
68
- //unfinished
69
- representations = null
66
+ representations = CreateRepresentations ( response . Value . Content ) . ToArray ( )
70
67
} ;
71
68
}
72
69
return responses ;
73
70
}
74
71
72
+ public List < OperationTemplateRepresentation > CreateRepresentations ( IDictionary < string , OpenApiMediaType > content )
73
+ {
74
+ List < OperationTemplateRepresentation > representations = new List < OperationTemplateRepresentation > ( ) ;
75
+ foreach ( KeyValuePair < string , OpenApiMediaType > pair in content )
76
+ {
77
+ OpenApiParameterHeaderIntersection param = new OpenApiParameterHeaderIntersection ( )
78
+ {
79
+ Example = pair . Value . Example ,
80
+ Examples = pair . Value . Examples
81
+ } ;
82
+ OperationTemplateRepresentation representation = new OperationTemplateRepresentation ( )
83
+ {
84
+ contentType = pair . Key ,
85
+ sample = JsonConvert . SerializeObject ( CreateParameterDefaultValue ( param ) ) ,
86
+ // schema has not yet been created, id is null
87
+ schemaId = null ,
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
+ formParameters = null
91
+ } ;
92
+ representations . Add ( representation ) ;
93
+ }
94
+ return representations ;
95
+
96
+ }
97
+
75
98
public List < OperationTemplateParameter > CreateResponseHeaders ( IDictionary < string , OpenApiHeader > headerPairs )
76
99
{
77
100
List < OperationTemplateParameter > headers = new List < OperationTemplateParameter > ( ) ;
0 commit comments