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(core): distinguish the value when it is blank only in interface #1228

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/core/src/generators/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ export const generateInterface = ({
scalar.type === 'object' &&
!context?.output.override?.useTypeOverInterfaces
) {
model += `export interface ${name} ${scalar.value}\n`;
// If `scalar.value` is 'unknown', replace it with `{}` to avoid type error
const blankIntefaceValue = scalar.value === 'unknown' ? '{}' : scalar.value;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
const blankIntefaceValue = scalar.value === 'unknown' ? '{}' : scalar.value;
const blankInterfaceValue = scalar.value === 'unknown' ? '{}' : scalar.value;

Copy link
Member Author

Choose a reason for hiding this comment

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

I fixed it

564dd8e


model += `export interface ${name} ${blankIntefaceValue}\n`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
model += `export interface ${name} ${blankIntefaceValue}\n`;
model += `export interface ${name} ${blankInterfaceValue}\n`;

Copy link
Member Author

Choose a reason for hiding this comment

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

I fixed it

564dd8e

} else {
model += `export type ${name} = ${scalar.value};\n`;
}
Expand Down
12 changes: 3 additions & 9 deletions packages/core/src/getters/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,10 @@ export const getObject = ({
};
}

const useTypeOverInterfaces = context?.output.override?.useTypeOverInterfaces;
const blankValue =
item.type === 'object'
? '{ [key: string]: any }'
: useTypeOverInterfaces
? 'unknown'
: '{}';

return {
value: blankValue + nullable,
value:
(item.type === 'object' ? '{ [key: string]: any }' : 'unknown') +
nullable,
imports: [],
schemas: [],
isEnum: false,
Expand Down