Skip to content

Commit d637fc0

Browse files
authored
Set explode = false and style = form for OData query options (#275)
* Set properties explode to false and style to form for all OData query options * Update v3 integration files * Remove unnecessary parentheses
1 parent a1e77a7 commit d637fc0

File tree

10 files changed

+182
-6
lines changed

10 files changed

+182
-6
lines changed

src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiParameterGenerator.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,9 @@ private static OpenApiParameter CreateTop(int topExample)
656656
Type = "integer",
657657
Minimum = 0,
658658
},
659-
Example = new OpenApiInteger(topExample)
659+
Example = new OpenApiInteger(topExample),
660+
Style = ParameterStyle.Form,
661+
Explode = false
660662
};
661663
}
662664

@@ -672,7 +674,9 @@ private static OpenApiParameter CreateSkip()
672674
{
673675
Type = "integer",
674676
Minimum = 0,
675-
}
677+
},
678+
Style = ParameterStyle.Form,
679+
Explode = false
676680
};
677681
}
678682

@@ -687,7 +691,9 @@ private static OpenApiParameter CreateCount()
687691
Schema = new OpenApiSchema
688692
{
689693
Type = "boolean"
690-
}
694+
},
695+
Style = ParameterStyle.Form,
696+
Explode = false
691697
};
692698
}
693699

@@ -702,7 +708,9 @@ private static OpenApiParameter CreateFilter()
702708
Schema = new OpenApiSchema
703709
{
704710
Type = "string"
705-
}
711+
},
712+
Style = ParameterStyle.Form,
713+
Explode = false
706714
};
707715
}
708716

@@ -717,7 +725,9 @@ private static OpenApiParameter CreateSearch()
717725
Schema = new OpenApiSchema
718726
{
719727
Type = "string"
720-
}
728+
},
729+
Style = ParameterStyle.Form,
730+
Explode = false
721731
};
722732
}
723733
}

test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiParameterGeneratorTests.cs

Lines changed: 87 additions & 1 deletion
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
// ------------------------------------------------------------
@@ -45,6 +45,90 @@ public void CreateParametersReturnsCreatedParameters()
4545
Assert.Equal(5, parameters.Count);
4646
Assert.Equal(new[] { "top", "skip", "count", "filter", "search" },
4747
parameters.Select(p => p.Key));
48+
Assert.Collection(parameters,
49+
item => // $top
50+
{
51+
string json = item.Value.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);
52+
string expected = @"{
53+
""name"": ""$top"",
54+
""in"": ""query"",
55+
""description"": ""Show only the first n items"",
56+
""style"": ""form"",
57+
""explode"": false,
58+
""schema"": {
59+
""minimum"": 0,
60+
""type"": ""integer""
61+
},
62+
""example"": 50
63+
}";
64+
65+
Assert.Equal(expected.ChangeLineBreaks(), json);
66+
},
67+
item => // $skip
68+
{
69+
string json = item.Value.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);
70+
string expected = @"{
71+
""name"": ""$skip"",
72+
""in"": ""query"",
73+
""description"": ""Skip the first n items"",
74+
""style"": ""form"",
75+
""explode"": false,
76+
""schema"": {
77+
""minimum"": 0,
78+
""type"": ""integer""
79+
}
80+
}";
81+
82+
Assert.Equal(expected.ChangeLineBreaks(), json);
83+
},
84+
item => // $count
85+
{
86+
string json = item.Value.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);
87+
string expected = @"{
88+
""name"": ""$count"",
89+
""in"": ""query"",
90+
""description"": ""Include count of items"",
91+
""style"": ""form"",
92+
""explode"": false,
93+
""schema"": {
94+
""type"": ""boolean""
95+
}
96+
}";
97+
98+
Assert.Equal(expected.ChangeLineBreaks(), json);
99+
},
100+
item => // $filter
101+
{
102+
string json = item.Value.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);
103+
string expected = @"{
104+
""name"": ""$filter"",
105+
""in"": ""query"",
106+
""description"": ""Filter items by property values"",
107+
""style"": ""form"",
108+
""explode"": false,
109+
""schema"": {
110+
""type"": ""string""
111+
}
112+
}";
113+
114+
Assert.Equal(expected.ChangeLineBreaks(), json);
115+
},
116+
item => // $search
117+
{
118+
string json = item.Value.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);
119+
string expected = @"{
120+
""name"": ""$search"",
121+
""in"": ""query"",
122+
""description"": ""Search items by search phrases"",
123+
""style"": ""form"",
124+
""explode"": false,
125+
""schema"": {
126+
""type"": ""string""
127+
}
128+
}";
129+
130+
Assert.Equal(expected.ChangeLineBreaks(), json);
131+
});
48132
}
49133

50134
[Fact]
@@ -66,6 +150,8 @@ public void CanSeralizeAsYamlFromTheCreatedParameters()
66150
@"name: $skip
67151
in: query
68152
description: Skip the first n items
153+
style: form
154+
explode: false
69155
schema:
70156
minimum: 0
71157
type: integer

test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/Basic.OpenApi.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,8 @@
12871287
"name": "$top",
12881288
"in": "query",
12891289
"description": "Show only the first n items",
1290+
"style": "form",
1291+
"explode": false,
12901292
"schema": {
12911293
"minimum": 0,
12921294
"type": "integer"
@@ -1297,6 +1299,8 @@
12971299
"name": "$skip",
12981300
"in": "query",
12991301
"description": "Skip the first n items",
1302+
"style": "form",
1303+
"explode": false,
13001304
"schema": {
13011305
"minimum": 0,
13021306
"type": "integer"
@@ -1306,6 +1310,8 @@
13061310
"name": "$count",
13071311
"in": "query",
13081312
"description": "Include count of items",
1313+
"style": "form",
1314+
"explode": false,
13091315
"schema": {
13101316
"type": "boolean"
13111317
}
@@ -1314,6 +1320,8 @@
13141320
"name": "$filter",
13151321
"in": "query",
13161322
"description": "Filter items by property values",
1323+
"style": "form",
1324+
"explode": false,
13171325
"schema": {
13181326
"type": "string"
13191327
}
@@ -1322,6 +1330,8 @@
13221330
"name": "$search",
13231331
"in": "query",
13241332
"description": "Search items by search phrases",
1333+
"style": "form",
1334+
"explode": false,
13251335
"schema": {
13261336
"type": "string"
13271337
}

test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/Basic.OpenApi.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,8 @@ components:
850850
name: $top
851851
in: query
852852
description: Show only the first n items
853+
style: form
854+
explode: false
853855
schema:
854856
minimum: 0
855857
type: integer
@@ -858,25 +860,33 @@ components:
858860
name: $skip
859861
in: query
860862
description: Skip the first n items
863+
style: form
864+
explode: false
861865
schema:
862866
minimum: 0
863867
type: integer
864868
count:
865869
name: $count
866870
in: query
867871
description: Include count of items
872+
style: form
873+
explode: false
868874
schema:
869875
type: boolean
870876
filter:
871877
name: $filter
872878
in: query
873879
description: Filter items by property values
880+
style: form
881+
explode: false
874882
schema:
875883
type: string
876884
search:
877885
name: $search
878886
in: query
879887
description: Search items by search phrases
888+
style: form
889+
explode: false
880890
schema:
881891
type: string
882892
examples:

test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/Empty.OpenApi.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@
130130
"name": "$top",
131131
"in": "query",
132132
"description": "Show only the first n items",
133+
"style": "form",
134+
"explode": false,
133135
"schema": {
134136
"minimum": 0,
135137
"type": "integer"
@@ -140,6 +142,8 @@
140142
"name": "$skip",
141143
"in": "query",
142144
"description": "Skip the first n items",
145+
"style": "form",
146+
"explode": false,
143147
"schema": {
144148
"minimum": 0,
145149
"type": "integer"
@@ -149,6 +153,8 @@
149153
"name": "$count",
150154
"in": "query",
151155
"description": "Include count of items",
156+
"style": "form",
157+
"explode": false,
152158
"schema": {
153159
"type": "boolean"
154160
}
@@ -157,6 +163,8 @@
157163
"name": "$filter",
158164
"in": "query",
159165
"description": "Filter items by property values",
166+
"style": "form",
167+
"explode": false,
160168
"schema": {
161169
"type": "string"
162170
}
@@ -165,6 +173,8 @@
165173
"name": "$search",
166174
"in": "query",
167175
"description": "Search items by search phrases",
176+
"style": "form",
177+
"explode": false,
168178
"schema": {
169179
"type": "string"
170180
}

test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/Empty.OpenApi.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ components:
8686
name: $top
8787
in: query
8888
description: Show only the first n items
89+
style: form
90+
explode: false
8991
schema:
9092
minimum: 0
9193
type: integer
@@ -94,25 +96,33 @@ components:
9496
name: $skip
9597
in: query
9698
description: Skip the first n items
99+
style: form
100+
explode: false
97101
schema:
98102
minimum: 0
99103
type: integer
100104
count:
101105
name: $count
102106
in: query
103107
description: Include count of items
108+
style: form
109+
explode: false
104110
schema:
105111
type: boolean
106112
filter:
107113
name: $filter
108114
in: query
109115
description: Filter items by property values
116+
style: form
117+
explode: false
110118
schema:
111119
type: string
112120
search:
113121
name: $search
114122
in: query
115123
description: Search items by search phrases
124+
style: form
125+
explode: false
116126
schema:
117127
type: string
118128
requestBodies:

test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/Multiple.Schema.OpenApi.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6732,6 +6732,8 @@
67326732
"name": "$top",
67336733
"in": "query",
67346734
"description": "Show only the first n items",
6735+
"style": "form",
6736+
"explode": false,
67356737
"schema": {
67366738
"minimum": 0,
67376739
"type": "integer"
@@ -6742,6 +6744,8 @@
67426744
"name": "$skip",
67436745
"in": "query",
67446746
"description": "Skip the first n items",
6747+
"style": "form",
6748+
"explode": false,
67456749
"schema": {
67466750
"minimum": 0,
67476751
"type": "integer"
@@ -6751,6 +6755,8 @@
67516755
"name": "$count",
67526756
"in": "query",
67536757
"description": "Include count of items",
6758+
"style": "form",
6759+
"explode": false,
67546760
"schema": {
67556761
"type": "boolean"
67566762
}
@@ -6759,6 +6765,8 @@
67596765
"name": "$filter",
67606766
"in": "query",
67616767
"description": "Filter items by property values",
6768+
"style": "form",
6769+
"explode": false,
67626770
"schema": {
67636771
"type": "string"
67646772
}
@@ -6767,6 +6775,8 @@
67676775
"name": "$search",
67686776
"in": "query",
67696777
"description": "Search items by search phrases",
6778+
"style": "form",
6779+
"explode": false,
67706780
"schema": {
67716781
"type": "string"
67726782
}

0 commit comments

Comments
 (0)