Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversion results wrong for array schemas in formData parameters with application/x-www-form-urlencoded content type #198

Open
2 tasks done
ghost opened this issue Sep 4, 2019 · 0 comments

Comments

@ghost
Copy link

ghost commented Sep 4, 2019

When in an OpenAPIv2 file, an operation contains a parameter in: formData that has an array schema and the request's body is specified to have Content-Type: application/x-www-form-urlencoded, the Mermade produced OpenAPIv3 equivalent is wrong in the following cases:

  • no collectionFormat specified,
  • collectionFormat: csv,
  • collectionFormat: ssv,
  • collectionFormat: pipes.
    The result is only correct when collectionFormat: multi is specified.

Checklist

  • Conversion: I have checked my source definition is valid OpenAPI 2.0
  • Conversion: On valid OpenAPI 2.0 input, the conversion looks wrong

Detailed Description

Assume an operation with Content-Type: application/x-www-form-urlencoded.

In OpenAPIv2 the serialization of parameters that have an array schema is guided by the collectionFormat property.

In OpenAPIv3, on the other hand, such parameters are first-level properties in the schema of the mediaType of the content of the requestBody.
The important sections here in the OpenAPIv3 spec https://github.com/OAI/OpenAPI-Specification/blob/676b48d8385244d5b02a9cfe40059d4a41f329cc/versions/3.0.2.md are:

In particular, the serialization is specified through an encoding object outside the schema object, and in this object the properties style and explode have the same meaning as for query parameters. Namely:

  • collectionFormat:csv (or absent collectionFormat) corresponds to style:form explode:false.
  • collectionFormat:ssv corresponds to style:spaceDelimited.
  • collectionFormat:pipes corresponds to style:pipeDelimited.
  • collectionFormat:multi corresponds to style:form explode:true.

Additionally, note that the default style is form, and for style: form, default explode is true.

I have prepared 5 test cases.

$ swagger2openapi -o form-url-parameter-array-of-strings-default.v3m.json form-url-parameter-array-of-strings-default.v2.json

Here the correct result is form-url-parameter-array-of-strings-default.v3.json. 'style:form' may be omitted, but 'explode:false' is essential.

$ swagger2openapi -o form-url-parameter-array-of-strings-csv.v3m.json form-url-parameter-array-of-strings-csv.v2.json

Here the correct result is form-url-parameter-array-of-strings-csv.v3.json. 'style:form' may be omitted, but 'explode:false' is essential.

$ swagger2openapi -o form-url-parameter-array-of-strings-ssv.v3m.json form-url-parameter-array-of-strings-ssv.v2.json
{ S2OError: collectionFormat:ssv is no longer supported except for in:query parameters
    at throwError (/openapi/node_modules/swagger2openapi/index.js:39:15)
    at throwOrWarn (/openapi/node_modules/swagger2openapi/index.js:54:9)
    at processParameter (/openapi/node_modules/swagger2openapi/index.js:564:21)
    at processPaths (/openapi/node_modules/swagger2openapi/index.js:936:30)
    at main (/openapi/node_modules/swagger2openapi/index.js:1170:5)
    at /openapi/node_modules/swagger2openapi/index.js:1505:13 name: 'S2OError' }

Here no error should be signalled. The correct result is form-url-parameter-array-of-strings-ssv.v3.json. 'style:spaceDelimited' is essential.

$ swagger2openapi -o form-url-parameter-array-of-strings-pipes.v3m.json form-url-parameter-array-of-strings-pipes.v2.json
{ S2OError: collectionFormat:pipes is no longer supported except for in:query parameters
    at throwError (/openapi/node_modules/swagger2openapi/index.js:39:15)
    at throwOrWarn (/openapi/node_modules/swagger2openapi/index.js:54:9)
    at processParameter (/openapi/node_modules/swagger2openapi/index.js:572:21)
    at processPaths (/openapi/node_modules/swagger2openapi/index.js:936:30)
    at main (/openapi/node_modules/swagger2openapi/index.js:1170:5)
    at /openapi/node_modules/swagger2openapi/index.js:1505:13 name: 'S2OError' }

Here no error should be signalled. The correct result is form-url-parameter-array-of-strings-pipes.v3.json. 'style:pipeDelimited' is essential.

$ swagger2openapi -o form-url-parameter-array-of-strings-multi.v3m.json form-url-parameter-array-of-strings-multi.v2.json

Here the result is correct; it is equivalent to form-url-parameter-array-of-strings-multi.v3.json.

Other stuff

Version: swagger2openapi-5.3.0

form-url-parameter-array-of-strings-default.v2.json.gz
form-url-parameter-array-of-strings-default.v3.json.gz
form-url-parameter-array-of-strings-csv.v2.json.gz
form-url-parameter-array-of-strings-csv.v3.json.gz
form-url-parameter-array-of-strings-ssv.v2.json.gz
form-url-parameter-array-of-strings-ssv.v3.json.gz
form-url-parameter-array-of-strings-pipes.v2.json.gz
form-url-parameter-array-of-strings-pipes.v3.json.gz
form-url-parameter-array-of-strings-multi.v2.json.gz
form-url-parameter-array-of-strings-multi.v3.json.gz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants