Skip to content

Commit f5594fb

Browse files
author
Daniel A. White
authored
fix(oas2): allow for unspecified type query params (#232)
1 parent b8f6017 commit f5594fb

7 files changed

Lines changed: 34 additions & 22 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"dependencies": {
7676
"@stoplight/json": "^3.18.1",
7777
"@stoplight/json-schema-generator": "1.0.2",
78-
"@stoplight/types": "^13.14.0",
78+
"@stoplight/types": "^13.15.0",
7979
"@types/json-schema": "7.0.11",
8080
"@types/swagger-schema-official": "~2.0.22",
8181
"@types/type-is": "^1.6.3",

src/oas/__tests__/__snapshots__/operation.test.ts.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ Array [
232232
"id": "schema-http_query-abc-skip-",
233233
},
234234
},
235-
"style": "commaDelimited",
235+
"style": "unspecified",
236236
},
237237
Object {
238238
"id": "http_query-abc-limit",
@@ -244,7 +244,7 @@ Array [
244244
"id": "schema-http_query-abc-limit-",
245245
},
246246
},
247-
"style": "commaDelimited",
247+
"style": "unspecified",
248248
},
249249
],
250250
},
@@ -307,7 +307,7 @@ Array [
307307
"id": "schema-http_query-abc-skip-",
308308
},
309309
},
310-
"style": "commaDelimited",
310+
"style": "unspecified",
311311
},
312312
Object {
313313
"id": "http_query-abc-limit",
@@ -319,7 +319,7 @@ Array [
319319
"id": "schema-http_query-abc-limit-",
320320
},
321321
},
322-
"style": "commaDelimited",
322+
"style": "unspecified",
323323
},
324324
],
325325
},

src/oas2/__tests__/__fixtures__/id/bundled.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export default {
164164
// hash('http_query-http_operation-service_abc-get-/users/{}-summaryOnly')
165165
id: 'http_query-http_operation-service_abc-get-/users/{}-summaryOnly',
166166
name: 'summaryOnly',
167-
style: 'commaDelimited',
167+
style: 'unspecified',
168168
schema: {
169169
$schema: 'http://json-schema.org/draft-07/schema#',
170170
'x-stoplight': {

src/oas2/transformers/__tests__/__snapshots__/request.test.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Object {
9090
Object {
9191
"id": Any<String>,
9292
"name": "param",
93-
"style": "commaDelimited",
93+
"style": "unspecified",
9494
},
9595
],
9696
}
@@ -136,7 +136,7 @@ Object {
136136
Object {
137137
"id": Any<String>,
138138
"name": "param",
139-
"style": "commaDelimited",
139+
"style": "unspecified",
140140
},
141141
],
142142
}
@@ -175,7 +175,7 @@ Object {
175175
Object {
176176
"id": Any<String>,
177177
"name": "param",
178-
"style": "commaDelimited",
178+
"style": "unspecified",
179179
},
180180
],
181181
}

src/oas2/transformers/__tests__/params.test.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -423,16 +423,23 @@ describe('params.translator', () => {
423423
};
424424

425425
it.each([
426-
{ oasStyle: 'pipes', expected: { style: HttpParamStyles.PipeDelimited } },
427-
{ oasStyle: 'ssv', expected: { style: HttpParamStyles.SpaceDelimited } },
428-
{ oasStyle: 'csv', expected: { style: HttpParamStyles.CommaDelimited } },
429-
{ oasStyle: 'tsv', expected: { style: HttpParamStyles.TabDelimited } },
430-
{ oasStyle: 'pipes', expected: { style: HttpParamStyles.PipeDelimited } },
431-
{ oasStyle: 'multi', expected: { style: HttpParamStyles.Form, explode: true } },
432-
{ oasStyle: 'invalidStyleValue', expected: { style: HttpParamStyles.CommaDelimited } },
433-
])('translate style: %o', ({ oasStyle, expected }) => {
426+
{ type: 'string', oasStyle: 'pipes', expected: { style: HttpParamStyles.Unspecified } },
427+
{ type: 'string', oasStyle: 'ssv', expected: { style: HttpParamStyles.Unspecified } },
428+
{ type: 'string', oasStyle: 'csv', expected: { style: HttpParamStyles.Unspecified } },
429+
{ type: 'string', oasStyle: 'tsv', expected: { style: HttpParamStyles.Unspecified } },
430+
{ type: 'string', oasStyle: 'pipes', expected: { style: HttpParamStyles.Unspecified } },
431+
{ type: 'string', oasStyle: 'multi', expected: { style: HttpParamStyles.Unspecified } },
432+
{ type: 'string', oasStyle: 'invalidStyleValue', expected: { style: HttpParamStyles.Unspecified } },
433+
{ type: 'array', oasStyle: 'pipes', expected: { style: HttpParamStyles.PipeDelimited } },
434+
{ type: 'array', oasStyle: 'ssv', expected: { style: HttpParamStyles.SpaceDelimited } },
435+
{ type: 'array', oasStyle: 'csv', expected: { style: HttpParamStyles.CommaDelimited } },
436+
{ type: 'array', oasStyle: 'tsv', expected: { style: HttpParamStyles.TabDelimited } },
437+
{ type: 'array', oasStyle: 'pipes', expected: { style: HttpParamStyles.PipeDelimited } },
438+
{ type: 'array', oasStyle: 'multi', expected: { style: HttpParamStyles.Form, explode: true } },
439+
{ type: 'array', oasStyle: 'invalidStyleValue', expected: { style: HttpParamStyles.CommaDelimited } },
440+
])('translate style: %o', ({ type, oasStyle, expected }) => {
434441
expect(
435-
translateToQueryParameter({}, { ...parameter, collectionFormat: oasStyle } as QueryParameter),
442+
translateToQueryParameter({}, { ...parameter, type, collectionFormat: oasStyle } as QueryParameter),
436443
).toMatchObject(expected);
437444
});
438445

src/oas2/transformers/params.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { Oas2TranslateFunction } from '../types';
3838

3939
type QueryParameterStyle = {
4040
style:
41+
| HttpParamStyles.Unspecified
4142
| HttpParamStyles.Form
4243
| HttpParamStyles.CommaDelimited
4344
| HttpParamStyles.SpaceDelimited
@@ -47,6 +48,10 @@ type QueryParameterStyle = {
4748
};
4849

4950
function chooseQueryParameterStyle(parameter: DeepPartial<QueryParameter>): QueryParameterStyle {
51+
if (parameter.type !== 'array') {
52+
return { style: HttpParamStyles.Unspecified };
53+
}
54+
5055
switch (parameter.collectionFormat) {
5156
case 'csv':
5257
return { style: HttpParamStyles.CommaDelimited };

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,10 +1491,10 @@
14911491
"@types/json-schema" "^7.0.4"
14921492
utility-types "^3.10.0"
14931493

1494-
"@stoplight/types@^13.14.0":
1495-
version "13.14.0"
1496-
resolved "https://registry.yarnpkg.com/@stoplight/types/-/types-13.14.0.tgz#7842b116d28a6d1cb65227aad9a93f5f0484d2ed"
1497-
integrity sha512-RqF5Cyl5227fRPIaWa5ptMvAtNUIM4yCzSUoERUXAarxpTcOrjMJ52p9lV9XrQtpLhLNMrWn08+h0ap10R22ig==
1494+
"@stoplight/types@^13.15.0":
1495+
version "13.15.0"
1496+
resolved "https://registry.yarnpkg.com/@stoplight/types/-/types-13.15.0.tgz#d2db6820d92e5085193d03c3057d15c40a70e34f"
1497+
integrity sha512-pBLjVRrWGVd+KzTbL3qrmufSKIEp0UfziDBdt/nrTHPKrlrtVwaHdrrQMcpM23yJDU1Wcg4cHvhIuGtKCT5OmA==
14981498
dependencies:
14991499
"@types/json-schema" "^7.0.4"
15001500
utility-types "^3.10.0"

0 commit comments

Comments
 (0)