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

OpenAPI3 response parsing discards schema format #437

Open
mryellow opened this issue Apr 12, 2021 · 0 comments
Open

OpenAPI3 response parsing discards schema format #437

mryellow opened this issue Apr 12, 2021 · 0 comments

Comments

@mryellow
Copy link

As per documented example and specification responses schema may include a format along with type: 'string'. In this case they're returning a PDF file with a format: 'binary'.

https://swagger.io/docs/specification/describing-responses/

https://spec.openapis.org/oas/v3.0.3.html#schema-object

paths:
  /report:
    get:
      summary: Returns the report in the PDF format
      responses:
        '200':
          description: A PDF file
          content:
            application/pdf:
              schema:
                type: string
                format: binary

The following loop is going through all defined response content-type and picking out only schema.type without any reference to format.

widdershins/lib/openapi3.js

Lines 446 to 449 in b08e4a3

if (contentType.schema) {
entry.type = contentType.schema.type;
entry.schema = data.translations.schemaInline;
}

Subsequently this line then stomps on anything set above when not either array or object.

widdershins/lib/openapi3.js

Lines 455 to 459 in b08e4a3

else {
if (contentType.schema && contentType.schema.type && (contentType.schema.type !== 'object') && (contentType.schema.type !== 'array')) {
entry.schema = contentType.schema.type;
}
}

The resulting output from getResponses thus completely misinterprets the type of response.

[
	{
		"status": "200",
		"meaning": "OK",
		"description": "Doc output or data object depending on req.body.operation",
		"schema": "string",
		"type": "string",
		"content": {
			"application/pdf": {
				"schema": {
					"type": "string",
					"format": "binary"
				}
			}
		}
	}
]

Expected behavior

Output multiple response content-type's with the correct schema.

#436

Versions:

  • Node: v14.15.1
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

1 participant