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

fix: remove unnecessary empty item in case of null-only enum or empty enum (#1022) #1023

Merged
merged 1 commit into from
Nov 8, 2023

Conversation

bigen1925
Copy link
Contributor

Status

READY

Description

Remove unnecessary empty item in case of null-only enum or empty enum.

Close #1022

Related PRs

The issue in case of empty enum may exist before.

The issue in case of null-only enum is occured by this PR.

Because null is filtered, null-only enum is handled as empty enum.

branch PR
alanpoulain:fix/null-enum link

Todos

  • Tests
  • Documentation
  • Changelog Entry (unreleased)

Steps to Test or Reproduce

Added specification and confirmed generated type files.

@bigen1925 bigen1925 force-pushed the bugfix/null-only-enum branch from e729259 to b9199b2 Compare November 8, 2023 02:23
)
.filter(Boolean)
.join(`' | '`)}'`;
.join(` | `)}`;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid that null is quoted like 'null'

)
.filter(Boolean)
.join(`' | '`)}'`;
.join(` | `)}`;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code can not handle array enum, or object enum.

output is like

export const ObjectEnum = {
  '[object_Object]': [object Object],
} as const;

I didn't fix because not relevant the issue, but should I leave FIXME comment?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

up to you if you want to leave a FIXME but not necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@melloware thanks for your review, and sorry for late reply.

I don't think necessary while someone report an issue.

@@ -64,13 +64,6 @@ export default defineConfig({
target: '../generated/default/null-type-v3-0/endpoints.ts',
},
},
'nullable-enum': {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I migrated cases in nullable-enum to null-type-v3-0

@@ -1,66 +0,0 @@
openapi: 3.0.0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

migrated to null-type-v3-0.yaml

@bigen1925
Copy link
Contributor Author

bigen1925 commented Nov 8, 2023

Before

export type NullOnlyNumberEnum = typeof NullOnlyStringEnum[keyof typeof NullOnlyStringEnum] | null;

// eslint-disable-next-line @typescript-eslint/no-redeclare
export const NullOnlyStringEnum = {
  '': ,
} as const;

export type NullOnlyStringEnum = typeof NullOnlyStringEnum[keyof typeof NullOnlyStringEnum] | null;

// eslint-disable-next-line @typescript-eslint/no-redeclare
export const NullOnlyStringEnum = {
  '': '',
} as const;

export type EmptyEnum = typeof EmptyEnum[keyof typeof EmptyEnum];

// eslint-disable-next-line @typescript-eslint/no-redeclare
export const EmptyEnum = {
  '': '',
} as const;

After

export type NullOnlyNumberEnum = typeof NullOnlyStringEnum[keyof typeof NullOnlyStringEnum] | null;

// eslint-disable-next-line @typescript-eslint/no-redeclare
export const NullOnlyStringEnum = {
} as const;

export type NullOnlyStringEnum = typeof NullOnlyStringEnum[keyof typeof NullOnlyStringEnum] | null;

// eslint-disable-next-line @typescript-eslint/no-redeclare
export const NullOnlyStringEnum = {
} as const;

export type EmptyEnum = typeof EmptyEnum[keyof typeof EmptyEnum];

// eslint-disable-next-line @typescript-eslint/no-redeclare
export const EmptyEnum = {
} as const;

@bigen1925
Copy link
Contributor Author

Ideally, it is desirable that like this code is generated

export type NullOnlyNumberEnum = null;
export type NullOnlyStringEnum = null;
export type EmptyEnum = never;

, but I think program will get too complex considering combine schema.

Because this is never

const EmptyObject = {} as const
typeof EmptyObject [keyof typeof EmptyObject] // never

, so meaning is the same.

@melloware melloware merged commit f6f2d42 into orval-labs:master Nov 8, 2023
2 checks passed
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

Successfully merging this pull request may close these issues.

Invalid type files are generated with Null-only enum or Empty enum
2 participants