Skip to content

Commit 441530f

Browse files
Copilotabraham
andcommitted
Fix nullable handling for oneOf structures in entity attributes
Co-authored-by: abraham <3341+abraham@users.noreply.github.com>
1 parent 05853b0 commit 441530f

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

dist/schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37219,6 +37219,9 @@
3721937219
},
3722037220
{
3722137221
"$ref": "#/components/schemas/ShallowQuote"
37222+
},
37223+
{
37224+
"type": "null"
3722237225
}
3722337226
]
3722437227
},

src/__tests__/integration/status-quote-oneOf.test.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ describe('Status Quote Attribute Integration Test', () => {
2525
JSON.stringify(quoteProperty, null, 2)
2626
);
2727

28-
// Check that the quote property has a oneOf structure with both Quote and ShallowQuote
29-
// Note: nullable handling for oneOf structures is handled differently than simple $ref
28+
// Check that the quote property has a oneOf structure with both Quote and ShallowQuote plus null
3029
if (quoteProperty.oneOf) {
31-
// Check if it's directly oneOf with Quote and ShallowQuote
30+
// Check if it's directly oneOf with Quote and ShallowQuote plus null
3231
const refs = quoteProperty.oneOf
3332
.filter((item: any) => item.$ref)
3433
.map((item: any) => item.$ref);
@@ -37,14 +36,17 @@ describe('Status Quote Attribute Integration Test', () => {
3736
const hasShallowQuote = refs.includes(
3837
'#/components/schemas/ShallowQuote'
3938
);
39+
const hasNull = quoteProperty.oneOf.some(
40+
(item: any) => item.type === 'null'
41+
);
4042

4143
expect(hasQuote).toBe(true);
4244
expect(hasShallowQuote).toBe(true);
45+
expect(hasNull).toBe(true);
4346

44-
console.log('✓ Found both Quote and ShallowQuote references in oneOf');
45-
46-
// Note: The nullable handling for oneOf structures could be improved in the future
47-
// but the main issue (missing ShallowQuote) is now fixed
47+
console.log(
48+
'✓ Found both Quote and ShallowQuote references plus null in oneOf'
49+
);
4850
} else {
4951
// If there's a nested structure due to nullable handling, check it
5052
console.log('Quote property structure:', quoteProperty);
@@ -54,9 +56,10 @@ describe('Status Quote Attribute Integration Test', () => {
5456
const jsonStr = JSON.stringify(quoteProperty);
5557
expect(jsonStr).toContain('#/components/schemas/Quote');
5658
expect(jsonStr).toContain('#/components/schemas/ShallowQuote');
59+
expect(jsonStr).toContain('"type":"null"');
5760

5861
console.log(
59-
'✓ Found both Quote and ShallowQuote references in the structure'
62+
'✓ Found both Quote and ShallowQuote references and null in the structure'
6063
);
6164
}
6265
}

src/generators/EntityConverter.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,9 @@ class EntityConverter {
459459
oneOf: [{ $ref: property.$ref }, { type: 'null' }],
460460
...(property.deprecated && { deprecated: true }),
461461
};
462+
} else if (property.oneOf) {
463+
// For properties that already have oneOf (e.g., multiple entity references), add null to the oneOf array
464+
property.oneOf.push({ type: 'null' });
462465
} else if (property.type && typeof property.type === 'string') {
463466
// For regular type properties, convert type to an array that includes null
464467
property.type = [property.type, 'null'];

0 commit comments

Comments
 (0)