Skip to content

Commit

Permalink
fix(core): distinguish the value when it is blank only in interface (
Browse files Browse the repository at this point in the history
  • Loading branch information
soartec-lab authored Mar 1, 2024
1 parent cf66f3f commit dfa076a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
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

0 comments on commit dfa076a

Please sign in to comment.