Skip to content

fillEmptyResponses does not work for 204 responses that return a content type #448

@zbyte64

Description

@zbyte64

Describe the bug
Unable to use an OpenAPI endpoint that has no return type.

To Reproduce
Steps to reproduce the behavior:

  1. Define a swagger schema that contains a schema-less response,
  2. Server has a schema-less endpoint that responds with a 204 and application/json as the content type
  3. Use createGraphQLSchema to export a graphql executor with the option fillEmptyResponses: true
  4. Execute a query or mutation against endpoint
  5. Observe that the operation gets executed but that the endpoint returns with an error.

Expected behavior

Either for the operation to return successfully with text or undefined return type OR for createGraphQLSchema to fail early if responseContentType is undefined

Screenshots

Server will respond with:

{
    "stacktrace": [
        "TypeError: Cannot read property 'includes' of undefined",
        "    at /code/node_modules/dist/openapi-to-graphql/src/resolver_builder.js:472:38",
        "    at processTicksAndRejections (internal/process/task_queues.js:95:5)"
    ]
}

If it's swagger schema looks like:

"put": {
        "description": "Update a building type",
        "operationId": "update_building_type",
        "parameters": [
          {
            "in": "body",
            "name": "building_type",
            "schema": {
              "$ref": "#/definitions/BuildingType"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Success."
          },
          "401": {
            "$ref": "#/responses/UnauthorizedError"
          },
          "403": {
            "$ref": "#/responses/ForbiddenError"
          },
          "default": {
            "$ref": "#/responses/GenericError"
          }
        },

Additional context
From what I've seen this happens when we call responseContentType.includes and responseContentType is undefined. This appears to happen when the source schema does not define a ref or schema.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions