@xen-orchestra/rest-api 0.34.0 → 0.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,10 +11,17 @@ export function buildOpenApiSchema(def) {
11
11
  property.type = 'string';
12
12
  property.enum = field.enum;
13
13
  }
14
+ else if (field.type === 'object') {
15
+ property.type = 'object';
16
+ const nested = buildOpenApiSchema(field.fields);
17
+ property.properties = nested.properties;
18
+ if (nested.required?.length)
19
+ property.required = nested.required;
20
+ }
14
21
  else {
15
22
  property.type = field.type;
16
23
  }
17
- if (field.example !== undefined) {
24
+ if ('example' in field && field.example !== undefined) {
18
25
  property.example = field.example;
19
26
  }
20
27
  schema.properties[key] = property;
@@ -203,10 +203,13 @@ function buildZodSchema(def) {
203
203
  case 'enum':
204
204
  schema = z.enum(field.enum);
205
205
  break;
206
+ case 'object':
207
+ schema = buildZodSchema(field.fields);
208
+ break;
206
209
  default:
207
210
  throw new Error(`Unsupported type: ${field.type}`);
208
211
  }
209
- if (field.example)
212
+ if ('example' in field && field.example !== undefined)
210
213
  schema = schema.meta({ example: field.example });
211
214
  if (field.optional)
212
215
  schema = schema.optional();