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.

Describe the bug Such an enum creates broken typescript

"ResponseEntity": {
      "type": "object",
      "properties": {
        "body": { "type": "object" },
        "statusCode": {
          "type": "string",
          "enum": [
            "100 CONTINUE",
            "101 SWITCHING_PROTOCOLS",
            "102 PROCESSING",
            "103 CHECKPOINT",
            "200 OK",
            "201 CREATED",
            "202 ACCEPTED",
            "203 NON_AUTHORITATIVE_INFORMATION",
            "204 NO_CONTENT",
            "205 RESET_CONTENT",
            "206 PARTIAL_CONTENT",
            "207 MULTI_STATUS",
            "208 ALREADY_REPORTED",
            "226 IM_USED",
            "300 MULTIPLE_CHOICES",
            "301 MOVED_PERMANENTLY",
            "302 FOUND",
            "302 MOVED_TEMPORARILY",
            "303 SEE_OTHER",
            "304 NOT_MODIFIED",
            "305 USE_PROXY",
            "307 TEMPORARY_REDIRECT",
            "308 PERMANENT_REDIRECT",
            "400 BAD_REQUEST",
            "401 UNAUTHORIZED",
            "402 PAYMENT_REQUIRED",
            "403 FORBIDDEN",
            "404 NOT_FOUND",
            "405 METHOD_NOT_ALLOWED",
            "406 NOT_ACCEPTABLE",
            "407 PROXY_AUTHENTICATION_REQUIRED",
            "408 REQUEST_TIMEOUT",
            "409 CONFLICT",
            "410 GONE",
            "411 LENGTH_REQUIRED",
            "412 PRECONDITION_FAILED",
            "413 PAYLOAD_TOO_LARGE",
            "413 REQUEST_ENTITY_TOO_LARGE",
            "414 URI_TOO_LONG",
            "414 REQUEST_URI_TOO_LONG",
            "415 UNSUPPORTED_MEDIA_TYPE",
            "416 REQUESTED_RANGE_NOT_SATISFIABLE",
            "417 EXPECTATION_FAILED",
            "418 I_AM_A_TEAPOT",
            "419 INSUFFICIENT_SPACE_ON_RESOURCE",
            "420 METHOD_FAILURE",
            "421 DESTINATION_LOCKED",
            "422 UNPROCESSABLE_ENTITY",
            "423 LOCKED",
            "424 FAILED_DEPENDENCY",
            "426 UPGRADE_REQUIRED",
            "428 PRECONDITION_REQUIRED",
            "429 TOO_MANY_REQUESTS",
            "431 REQUEST_HEADER_FIELDS_TOO_LARGE",
            "451 UNAVAILABLE_FOR_LEGAL_REASONS",
            "500 INTERNAL_SERVER_ERROR",
            "501 NOT_IMPLEMENTED",
            "502 BAD_GATEWAY",
            "503 SERVICE_UNAVAILABLE",
            "504 GATEWAY_TIMEOUT",
            "505 HTTP_VERSION_NOT_SUPPORTED",
            "506 VARIANT_ALSO_NEGOTIATES",
            "507 INSUFFICIENT_STORAGE",
            "508 LOOP_DETECTED",
            "509 BANDWIDTH_LIMIT_EXCEEDED",
            "510 NOT_EXTENDED",
            "511 NETWORK_AUTHENTICATION_REQUIRED"
          ]
        },
        "statusCodeValue": { "type": "integer", "format": "int32" }
      },
      "title": "ResponseEntity"
    },

Results in this TypeScript

export enum statusCode {
        100 CONTINUE = '100 CONTINUE',
        101 SWITCHING_PROTOCOLS = '101 SWITCHING_PROTOCOLS',
        102 PROCESSING = '102 PROCESSING',
        103 CHECKPOINT = '103 CHECKPOINT',
        200 OK = '200 OK',
        201 CREATED = '201 CREATED',
        202 ACCEPTED = '202 ACCEPTED',
        203 NON_AUTHORITATIVE_INFORMATION = '203 NON_AUTHORITATIVE_INFORMATION',
        204 NO_CONTENT = '204 NO_CONTENT',
        205 RESET_CONTENT = '205 RESET_CONTENT',
        206 PARTIAL_CONTENT = '206 PARTIAL_CONTENT',
        207 MULTI_STATUS = '207 MULTI_STATUS',
        208 ALREADY_REPORTED = '208 ALREADY_REPORTED',
        226 IM_USED = '226 IM_USED',
        300 MULTIPLE_CHOICES = '300 MULTIPLE_CHOICES',
        301 MOVED_PERMANENTLY = '301 MOVED_PERMANENTLY',
        302 FOUND = '302 FOUND',
        302 MOVED_TEMPORARILY = '302 MOVED_TEMPORARILY',
        303 SEE_OTHER = '303 SEE_OTHER',
        304 NOT_MODIFIED = '304 NOT_MODIFIED',
        305 USE_PROXY = '305 USE_PROXY',
        307 TEMPORARY_REDIRECT = '307 TEMPORARY_REDIRECT',
        308 PERMANENT_REDIRECT = '308 PERMANENT_REDIRECT',
        400 BAD_REQUEST = '400 BAD_REQUEST',
        401 UNAUTHORIZED = '401 UNAUTHORIZED',
        402 PAYMENT_REQUIRED = '402 PAYMENT_REQUIRED',
        403 FORBIDDEN = '403 FORBIDDEN',
        404 NOT_FOUND = '404 NOT_FOUND',
        405 METHOD_NOT_ALLOWED = '405 METHOD_NOT_ALLOWED',
        406 NOT_ACCEPTABLE = '406 NOT_ACCEPTABLE',
        407 PROXY_AUTHENTICATION_REQUIRED = '407 PROXY_AUTHENTICATION_REQUIRED',
        408 REQUEST_TIMEOUT = '408 REQUEST_TIMEOUT',
        409 CONFLICT = '409 CONFLICT',
        410 GONE = '410 GONE',
        411 LENGTH_REQUIRED = '411 LENGTH_REQUIRED',
        412 PRECONDITION_FAILED = '412 PRECONDITION_FAILED',
        413 PAYLOAD_TOO_LARGE = '413 PAYLOAD_TOO_LARGE',
        413 REQUEST_ENTITY_TOO_LARGE = '413 REQUEST_ENTITY_TOO_LARGE',
        414 URI_TOO_LONG = '414 URI_TOO_LONG',
        414 REQUEST_URI_TOO_LONG = '414 REQUEST_URI_TOO_LONG',
        415 UNSUPPORTED_MEDIA_TYPE = '415 UNSUPPORTED_MEDIA_TYPE',
        416 REQUESTED_RANGE_NOT_SATISFIABLE = '416 REQUESTED_RANGE_NOT_SATISFIABLE',
        417 EXPECTATION_FAILED = '417 EXPECTATION_FAILED',
        418 I_AM_A_TEAPOT = '418 I_AM_A_TEAPOT',
        419 INSUFFICIENT_SPACE_ON_RESOURCE = '419 INSUFFICIENT_SPACE_ON_RESOURCE',
        420 METHOD_FAILURE = '420 METHOD_FAILURE',
        421 DESTINATION_LOCKED = '421 DESTINATION_LOCKED',
        422 UNPROCESSABLE_ENTITY = '422 UNPROCESSABLE_ENTITY',
        423 LOCKED = '423 LOCKED',
        424 FAILED_DEPENDENCY = '424 FAILED_DEPENDENCY',
        426 UPGRADE_REQUIRED = '426 UPGRADE_REQUIRED',
        428 PRECONDITION_REQUIRED = '428 PRECONDITION_REQUIRED',
        429 TOO_MANY_REQUESTS = '429 TOO_MANY_REQUESTS',
        431 REQUEST_HEADER_FIELDS_TOO_LARGE = '431 REQUEST_HEADER_FIELDS_TOO_LARGE',
        451 UNAVAILABLE_FOR_LEGAL_REASONS = '451 UNAVAILABLE_FOR_LEGAL_REASONS',
        500 INTERNAL_SERVER_ERROR = '500 INTERNAL_SERVER_ERROR',
        501 NOT_IMPLEMENTED = '501 NOT_IMPLEMENTED',
        502 BAD_GATEWAY = '502 BAD_GATEWAY',
        503 SERVICE_UNAVAILABLE = '503 SERVICE_UNAVAILABLE',
        504 GATEWAY_TIMEOUT = '504 GATEWAY_TIMEOUT',
        505 HTTP_VERSION_NOT_SUPPORTED = '505 HTTP_VERSION_NOT_SUPPORTED',
        506 VARIANT_ALSO_NEGOTIATES = '506 VARIANT_ALSO_NEGOTIATES',
        507 INSUFFICIENT_STORAGE = '507 INSUFFICIENT_STORAGE',
        508 LOOP_DETECTED = '508 LOOP_DETECTED',
        509 BANDWIDTH_LIMIT_EXCEEDED = '509 BANDWIDTH_LIMIT_EXCEEDED',
        510 NOT_EXTENDED = '510 NOT_EXTENDED',
        511 NETWORK_AUTHENTICATION_REQUIRED = '511 NETWORK_AUTHENTICATION_REQUIRED',
    }

Which is not valid

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
ferdikoomencommented, May 23, 2020

@DaSchTour there is a fixed pushed in the master branch, will test this now and release a new version on NPM. There is however one small ‘issue’:

The following enum is not valid in Typescript/Javascript, since variable names cannot start with numbers:

export enum statusCode {
        100_CONTINUE = '100 CONTINUE'
}

I cannot remove the number, since the labels might not be unique. So now i prefix them:

export enum statusCode {
        _100_CONTINUE = '100 CONTINUE'
}

I check most other generators and they tend to do the same (at least the Java and current Typescript versions in the swagger-codegen).

0reactions
DaSchTourcommented, May 27, 2020

Thanks a lot for your work!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fixing 3rd Party Broken Enum class in JAR - Stack Overflow
I'm using a 3rd party JAR which is trying parse an enum field but the Enum class is missing out one of the...
Read more >
Broken code generation for empty enums · Issue #1253 - GitHub
We are working with a hasura-generated schema, which somehow contains empty enums like this one: enum my_empty_enum {} But when compiling ...
Read more >
ENUM - still broken? - MariaDB Knowledge Base
ENUM was broken in MySQL. Has it ever been fixed in MariaDB? I've been using PHP constants to avoid ENUM, but I'd like...
Read more >
Forward declaring enum class inner types within C++ class ...
If two "enum class" types are forward declared within a class in a module being compiled with /clr, the resulting assembly has broken...
Read more >
[#AVRO-1810] GenericDatumWriter broken with Enum - Apache
Description Using the GenericDatumWriter with either Generic OR SpecificRecord will break if an Enum is present. Steps To Reproduce I have ...
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