Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit 32636e0

Browse files
committed
add form parameters creation logic
1 parent 40c442d commit 32636e0

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/APIM_ARMTemplate/apimtemplate/TemplateCreators/OperationTemplateCreator.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,38 @@ public List<OperationTemplateRepresentation> CreateRepresentations(IDictionary<s
8686
// schema has not yet been created, id is null
8787
schemaId = null,
8888
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
9089
formParameters = null
9190
};
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+
};
9296
representations.Add(representation);
9397
}
9498
return representations;
9599

96100
}
97101

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+
98121
public List<OperationTemplateParameter> CreateResponseHeaders(IDictionary<string, OpenApiHeader> headerPairs)
99122
{
100123
List<OperationTemplateParameter> headers = new List<OperationTemplateParameter>();
@@ -180,4 +203,9 @@ public class OpenApiParameterHeaderIntersection {
180203
public IOpenApiAny Example { get; set; }
181204
public IDictionary<string, OpenApiExample> Examples { get; set; }
182205
}
206+
207+
public class OperationSchemaExample
208+
{
209+
public object Value { get; set; }
210+
}
183211
}

0 commit comments

Comments
 (0)