Skip to content
This repository was archived by the owner on Oct 25, 2023. It is now read-only.
This repository was archived by the owner on Oct 25, 2023. It is now read-only.

drf-spectacular generates NullEnum which throws an error #6

Open
@wvffle

Description

@wvffle

Thanks for providing a fork that fixes some stuff and updates dependencies, great work!

In a project I'm currently working on, we're using drf-spectacular to generate schema.yml.

In the schema, there's a NullEnum generated:

NullEnum:
  enum:
    - null

And by default swagger-typescript-api-nextgen generates this as the NullEnum with the typescript error added:

export enum NullEnum {
  null = null, // Only numeric enums can have computed members, but this expression has type 'null'. If you do not need exhaustiveness checks, consider using an object literal instead. ts(18033)
}

But when used with --union-enums, it throws an exception:

☄️    start generating your typescript api
⚠️    wrong name of the model name null
SyntaxError: ';' expected. (1062:8)
  1060 | export type NullEnum = 
  1061 |
> 1062 | export interface PaginatedAPIMutationList {
       |        ^
  1063 |   
  1064 |   /** @example 123 */
  1065 |   count?: number;
    at Ve (/workspace/funkwhale/front/node_modules/prettier/parser-typescript.js:1:15607)
    at vz (/workspace/funkwhale/front/node_modules/prettier/parser-typescript.js:280:5919)
    at Object.yz [as parse] (/workspace/funkwhale/front/node_modules/prettier/parser-typescript.js:280:6242)
    at Object.parse (/workspace/funkwhale/front/node_modules/prettier/index.js:7334:23)
    at coreFormat (/workspace/funkwhale/front/node_modules/prettier/index.js:8645:18)
    at formatWithCursor2 (/workspace/funkwhale/front/node_modules/prettier/index.js:8837:18)
    at /workspace/funkwhale/front/node_modules/prettier/index.js:37229:12
    at Object.format (/workspace/funkwhale/front/node_modules/prettier/index.js:37243:12)
    at prettierFormat (/workspace/funkwhale/front/node_modules/swagger-typescript-api-nextgen/src/formatFileContent.js:68:19)
    at /workspace/funkwhale/front/node_modules/swagger-typescript-api-nextgen/src/formatFileContent.js:74:50 {
  loc: { start: { line: 1062, column: 8 } },
  codeFrame: '\x1B[0m \x1B[90m 1060 |\x1B[39m \x1B[36mexport\x1B[39m type \x1B[33mNullEnum\x1B[39m \x1B[33m=\x1B[39m \x1B[0m\n' +
    '\x1B[0m \x1B[90m 1061 |\x1B[39m\x1B[0m\n' +
    '\x1B[0m\x1B[31m\x1B[1m>\x1B[22m\x1B[39m\x1B[90m 1062 |\x1B[39m \x1B[36mexport\x1B[39m \x1B[36minterface\x1B[39m \x1B[33mPaginatedAPIMutationList\x1B[39m {\x1B[0m\n' +
    '\x1B[0m \x1B[90m      |\x1B[39m        \x1B[31m\x1B[1m^\x1B[22m\x1B[39m\x1B[0m\n' +
    '\x1B[0m \x1B[90m 1063 |\x1B[39m   \x1B[0m\n' +
    '\x1B[0m \x1B[90m 1064 |\x1B[39m   \x1B[90m/** @example 123 */\x1B[39m\x1B[0m\n' +
    '\x1B[0m \x1B[90m 1065 |\x1B[39m   count\x1B[33m?\x1B[39m\x1B[33m:\x1B[39m number\x1B[33m;\x1B[39m\x1B[0m'
}
error Command failed with exit code 1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions