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 all 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
6 changes: 5 additions & 1 deletion packages/core/src/generators/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ 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 blankInterfaceValue =
scalar.value === 'unknown' ? '{}' : scalar.value;

model += `export interface ${name} ${blankInterfaceValue}\n`;
} 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
5 changes: 5 additions & 0 deletions tests/specifications/regressions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ components:
items:
type: string
nullable: true
BlankSchema: {}
NotDifinedType:
properties:
id:
description: not defined type schema
paths:
/endpointA:
get:
Expand Down