Skip to content

Commit 8ed1a76

Browse files
committed
handle null opaqueref for relation
1 parent 8cac7a7 commit 8ed1a76

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

@xen-orchestra/xapi-generator/src/generators/base.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ export const generateBase = () => {
55

66
const branded = 'export type Branded<TBrand extends string, TType = string> = TType & { [__brand]: TBrand }'
77

8-
return `${brand}\n\n${branded}\n`
8+
const opaqueRefEnum = "export const OPAQUE_REF = { EMPTY: 'OpaqueRef:NULL' } as const"
9+
10+
const opaqueRefType = "export type OPAQUE_REF_NULL = typeof OPAQUE_REF['EMPTY']"
11+
12+
return `${brand}\n\n${branded}\n\n${opaqueRefEnum}\n\n${opaqueRefType}\n`
913
}
1014

1115
const baseCommand = new Command('base').description('Generate base types').action(async () => {

@xen-orchestra/xapi-generator/src/generators/record.ts

+5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export const generateRecord = (item: XapiItem) => {
3838
t => t.transition === 'published' && VERSION_BY_CODE_NAME[t.release] === undefined
3939
)
4040
const isDeprecated = field.lifecycle.transitions.some(t => t.transition === 'deprecated')
41+
const isEmptyOpaqueRef =
42+
field.default === 'OpaqueRef:NULL' || (field.default === 'Null' && field.type.endsWith('ref'))
4143

4244
function isAlwaysExisting() {
4345
if (!isPublished || isPublishedAfterDundee) {
@@ -51,6 +53,9 @@ export const generateRecord = (item: XapiItem) => {
5153
// field.name === 'uuid' || field.type.endsWith(' set') || (isPublished && isFromRio && !isDeprecated && !isOptional)
5254

5355
const result = [` ${field.name}${isAlwaysExisting() ? '' : '?'}: ${toType(field.type)}`]
56+
if (isEmptyOpaqueRef) {
57+
result[0] = result[0].concat(' | OPAQUE_REF_NULL')
58+
}
5459

5560
if (isDeprecated) {
5661
result.unshift(' /** @deprecated */')

0 commit comments

Comments
 (0)