question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

openapi-to-graphql fails when definitions contains enum

See original GitHub issue

I get this error message:

OpenAPI-to-GraphQL creation event error: str.split is not a function

When I run this command:

openapi-to-graphql v1-split.json --save split.graphql

Here are the contents of v1-split.json:

{
  "swagger": "2.0",
  "info": {
    "version": "v1",
    "title": "Test.API"
  },
  "host": "localhost:5234",
  "schemes": [
    "http"
  ],
  "paths": {
    "/api/v1/email/send": {
      "post": {
        "tags": [
          "Email"
        ],
        "summary": "Sends the given email via SendGrid",
        "description": "Sends the given email via SendGrid",
        "operationId": "Email_SendEmailAsync",
        "consumes": [
        ],
        "produces": [
          "application/json"
        ],
        "parameters": [
          {
            "name": "emailData",
            "in": "body",
            "description": "",
            "required": true,
            "schema": {
              "$ref": "#/definitions/SendEmailData"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "schema": {
              "$ref": "#/definitions/SendEmailResult"
            }
          }
        }
      }
    }
    },
  "definitions": {
    "SendEmailData": {
      "type": "object",
      "properties": {
        "EmailQueueId": {
          "format": "int32",
          "type": "integer"
        },
        "FromAddress": {
          "type": "string"
        },
        "FromName": {
          "type": "string"
        },
        "ReplyTo": {
          "type": "string"
        },
        "ToAddress": {
          "type": "string"
        },
        "Subject": {
          "type": "string"
        },
        "PlainTextContent": {
          "type": "string"
        },
        "HtmlContent": {
          "type": "string"
        }
      }
    },
    "SendEmailResult": {
      "type": "object",
      "properties": {
        "StatusCode": {
          "format": "int32",
          "enum": [
            100,
            101,
            200,
            201,
            202,
            203,
            204,
            205,
            206,
            300,
            300,
            301,
            301,
            302,
            302,
            303,
            303,
            304,
            305,
            306,
            307,
            307,
            400,
            401,
            402,
            403,
            404,
            405,
            406,
            407,
            408,
            409,
            410,
            411,
            412,
            413,
            414,
            415,
            416,
            417,
            426,
            500,
            501,
            502,
            503,
            504,
            505
          ],
          "type": "integer"
        },
        "ErrorJson": {
          "type": "string"
        }
      }
    }
    },
  "securityDefinitions": {
    "oauth2": {
      "type": "oauth2",
      "description": "OAuth2 Implicit Grant",
      "flow": "implicit",
      "authorizationUrl": "http://localhost:5897/core/connect/authorize",
      "tokenUrl": "http://localhost:5297/core/connect/token",
      "scopes": {
        "swagger": "Swagger UI"
      }
    }
  }
}

The operation succeeds when I remove the enum from the definition. Let me know if you need any other info.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
Alan-Chacommented, Aug 14, 2019

Sorry for the delay! Fixed after accepting PR #218

1reaction
foldingcommented, Aug 1, 2019

@Alan-Cha, adding quotes around each enum did allow it to generate successfully. Like so:

...
"SendEmailResult": {
      "type": "object",
      "properties": {
        "StatusCode": {
          "format": "int32",
          "enum": [
            "100",
            "101",
            "200",
            "201",
            "202",
...
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to define an enum in OpenAPI (Swagger)? - Stack Overflow
"enum" works like this in OpenAPI 2.0: ... there's a query parameter called sample of type string, and has an enum stating two...
Read more >
What you need to know about GraphQL enums
Learn how GraphQL enums can help you build more robust and discoverable APIs, create simple interfaces, maintain slim resolvers, and more.
Read more >
Enumeration declaration - cppreference.com
An enumeration is a distinct type whose value is restricted to a range of values (see below for details), which may include several ......
Read more >
Handbook - Enums - TypeScript
Enums are one of the few features TypeScript has which is not a type-level extension of JavaScript. Enums allow a developer to define...
Read more >
PHP 8.1: Enums
An Enumeration, or an Enum for short, is an enumerated type that has a fixed ... Fatal error: Non-enum class FakeEnum cannot implement...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found