Skip to content

Commit dfa076a

Browse files
authoredMar 1, 2024
fix(core): distinguish the value when it is blank only in interface (#1228)
1 parent cf66f3f commit dfa076a

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed
 

‎packages/core/src/generators/interface.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ export const generateInterface = ({
4646
scalar.type === 'object' &&
4747
!context?.output.override?.useTypeOverInterfaces
4848
) {
49-
model += `export interface ${name} ${scalar.value}\n`;
49+
// If `scalar.value` is 'unknown', replace it with `{}` to avoid type error
50+
const blankInterfaceValue =
51+
scalar.value === 'unknown' ? '{}' : scalar.value;
52+
53+
model += `export interface ${name} ${blankInterfaceValue}\n`;
5054
} else {
5155
model += `export type ${name} = ${scalar.value};\n`;
5256
}

‎packages/core/src/getters/object.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -202,16 +202,10 @@ export const getObject = ({
202202
};
203203
}
204204

205-
const useTypeOverInterfaces = context?.output.override?.useTypeOverInterfaces;
206-
const blankValue =
207-
item.type === 'object'
208-
? '{ [key: string]: any }'
209-
: useTypeOverInterfaces
210-
? 'unknown'
211-
: '{}';
212-
213205
return {
214-
value: blankValue + nullable,
206+
value:
207+
(item.type === 'object' ? '{ [key: string]: any }' : 'unknown') +
208+
nullable,
215209
imports: [],
216210
schemas: [],
217211
isEnum: false,

‎tests/specifications/regressions.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ components:
1919
items:
2020
type: string
2121
nullable: true
22+
BlankSchema: {}
23+
NotDifinedType:
24+
properties:
25+
id:
26+
description: not defined type schema
2227
paths:
2328
/endpointA:
2429
get:

0 commit comments

Comments
 (0)
Please sign in to comment.