File tree Expand file tree Collapse file tree 1 file changed +23
-1
lines changed
packages/openapi-generator/src Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change 11import { combineComments } from './comments' ;
2- import { isPrimitive , type Primitive , type Schema } from './ir' ;
2+ import { isPrimitive , type CombinedType , type Primitive , type Schema } from './ir' ;
33
44export type OptimizeFn = ( schema : Schema ) => Schema ;
55
@@ -29,6 +29,28 @@ export function foldIntersection(schema: Schema, optimize: OptimizeFn): Schema {
2929 }
3030 } ) ;
3131
32+ // If the combined object is empty (no properties) and result is an intersection,
33+ // we can simplify by removing the empty object
34+ const hasProperties = Object . keys ( combinedObject . properties ) . length > 0 ;
35+
36+ if ( ! hasProperties && result !== combinedObject ) {
37+ // At this point, result must be an intersection since it was reassigned
38+ const intersectionResult = result as unknown as CombinedType ;
39+
40+ // Remove the empty object from the intersection
41+ const nonEmptySchemas = intersectionResult . schemas . filter (
42+ ( s : Schema ) => ! ( s . type === 'object' && Object . keys ( s . properties ) . length === 0 ) ,
43+ ) ;
44+
45+ if ( nonEmptySchemas . length === 0 ) {
46+ return combinedObject ;
47+ } else if ( nonEmptySchemas . length === 1 ) {
48+ return nonEmptySchemas [ 0 ] ! ;
49+ } else {
50+ return { type : 'intersection' , schemas : nonEmptySchemas } ;
51+ }
52+ }
53+
3254 return result ;
3355}
3456
You can’t perform that action at this time.
0 commit comments