Skip to content

Commit 4c685b5

Browse files
irvinesundaythewahomexuzhg
authored
Fix: Removes example property in path parameter objects (#92)
* Remove example property in Parameters This helps in avoiding duplication with examples property. They are mutually exclusive. DocumentationURL prop. which used to be set in example property is now set within descriptions property. * Update src/Microsoft.OpenApi.OData.Reader/Operation/OperationHandler.cs Co-authored-by: Charles Wahome <[email protected]> * Remove duplicate variable declaration * Minor refactoring To help trigger build Co-authored-by: Irvine Sunday <[email protected]> Co-authored-by: Charles Wahome <[email protected]> Co-authored-by: Sam Xu <[email protected]>
1 parent 32e673e commit 4c685b5

File tree

2 files changed

+82
-10
lines changed

2 files changed

+82
-10
lines changed

src/Microsoft.OpenApi.OData.Reader/Operation/OperationHandler.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// ------------------------------------------------------------
1+
// ------------------------------------------------------------
22
// Copyright (c) Microsoft Corporation. All rights reserved.
33
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
44
// ------------------------------------------------------------
@@ -186,23 +186,28 @@ protected static void AppendCustomParameters(OpenApiOperation operation, IList<C
186186
{
187187
foreach (var param in customParameters)
188188
{
189-
OpenApiParameter parameter = new OpenApiParameter
189+
string documentationUrl = null;
190+
if (param.DocumentationURL != null)
191+
{
192+
documentationUrl = $" Documentation URL: {param.DocumentationURL}";
193+
}
194+
195+
// DocumentationURL value is to be appended to
196+
// the parameter Description property
197+
string paramDescription = (param.Description == null) ? documentationUrl?.Remove(0, 1) : param.Description + documentationUrl;
198+
199+
OpenApiParameter parameter = new()
190200
{
191201
In = location,
192202
Name = param.Name,
193-
Description = param.Description,
203+
Description = paramDescription,
194204
Schema = new OpenApiSchema
195205
{
196206
Type = "string"
197207
},
198208
Required = param.Required ?? false
199209
};
200210

201-
if (param.DocumentationURL != null)
202-
{
203-
parameter.Example = new OpenApiString(param.DocumentationURL ?? "N/A");
204-
}
205-
206211
if (param.ExampleValues != null)
207212
{
208213
parameter.Examples = new Dictionary<string, OpenApiExample>();

test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EdmFunctionImportOperationHandlerTests.cs

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,31 @@ public void OperationRestrictionsTermWorksToCreateOperationForEdmFunctionImport(
173173
<PropertyValue Property=""Name"" String=""myhead1"" />
174174
<PropertyValue Property=""Required"" Bool=""true"" />
175175
</Record>
176-
</Collection>
176+
<Record>
177+
<PropertyValue Property=""Name"" String=""myhead2"" />
178+
<PropertyValue Property = ""Description"" String = ""This is the description for myhead2."" />
179+
<PropertyValue Property = ""Required"" Bool = ""false"" />
180+
</Record>
181+
<Record>
182+
<PropertyValue Property=""Name"" String=""myhead3"" />
183+
<PropertyValue Property = ""DocumentationURL"" String = ""https://foo.bar.com/myhead3"" />
184+
<PropertyValue Property = ""Required"" Bool = ""false"" />
185+
</Record>
186+
<Record>
187+
<PropertyValue Property=""Name"" String=""myhead4"" />
188+
<PropertyValue Property = ""Description"" String = ""This is the description for myhead4."" />
189+
<PropertyValue Property = ""DocumentationURL"" String = ""https://foo.bar.com/myhead4"" />
190+
<PropertyValue Property = ""Required"" Bool = ""false"" />
191+
<PropertyValue Property = ""ExampleValues"" >
192+
<Collection>
193+
<Record>
194+
<PropertyValue Property = ""Value"" String = ""sample"" />
195+
<PropertyValue Property = ""Description"" String = ""The sample description."" />
196+
</Record>
197+
</Collection>
198+
</PropertyValue>
199+
</Record>
200+
</Collection>
177201
</PropertyValue>
178202
<PropertyValue Property=""Permissions"">
179203
<Collection>
@@ -262,11 +286,54 @@ public void OperationRestrictionsTermWorksToCreateOperationForEdmFunctionImport(
262286
}
263287
}
264288
".ChangeLineBreaks(), json);
289+
290+
// Assert with no DocumentationURL value
291+
Assert.Contains(@"
292+
{
293+
""name"": ""myhead2"",
294+
""in"": ""header"",
295+
""description"": ""This is the description for myhead2."",
296+
""schema"": {
297+
""type"": ""string""
298+
}
299+
}
300+
".ChangeLineBreaks(), json);
301+
302+
// Assert with no Description value
303+
Assert.Contains(@"
304+
{
305+
""name"": ""myhead3"",
306+
""in"": ""header"",
307+
""description"": ""Documentation URL: https://foo.bar.com/myhead3"",
308+
""schema"": {
309+
""type"": ""string""
310+
}
311+
}
312+
".ChangeLineBreaks(), json);
313+
314+
// Assert with both DocumentationURL and Description values
315+
Assert.Contains(@"
316+
{
317+
""name"": ""myhead4"",
318+
""in"": ""header"",
319+
""description"": ""This is the description for myhead4. Documentation URL: https://foo.bar.com/myhead4"",
320+
""schema"": {
321+
""type"": ""string""
322+
},
323+
""examples"": {
324+
""example-1"": {
325+
""description"": ""The sample description."",
326+
""value"": ""sample""
327+
}
328+
}
329+
}
330+
".ChangeLineBreaks(), json);
331+
265332
}
266333
else
267334
{
268335
Assert.Empty(operation.Security);
269336
}
270337
}
271338
}
272-
}
339+
}

0 commit comments

Comments
 (0)