diff --git a/src/generators/android/android.ts b/src/generators/android/android.ts index 02dc7302..6a0a3845 100644 --- a/src/generators/android/android.ts +++ b/src/generators/android/android.ts @@ -111,7 +111,7 @@ export const android: Generator< }, generateUnion: async (client, schema, _, parentPath) => { // TODO: support unions - return defaultPropertyContext(client, schema, 'Object', parentPath); + return defaultPropertyContext(client, schema, 'Object', parentPath, !!schema.enum); }, generateTrackCall: async (_client, schema, functionName, propertiesObject) => { const { properties } = getPropertiesSchema(schema); diff --git a/src/generators/ast.ts b/src/generators/ast.ts index 169cd0db..34416621 100644 --- a/src/generators/ast.ts +++ b/src/generators/ast.ts @@ -208,6 +208,14 @@ function parseTypeSpecificFields(raw: JSONSchema7, type: Type): TypeSpecificFiel if (schemas.length === 1) { const schema = schemas[0]; + + if ( + schema.properties && + Object.keys(schema.properties).length > 0 && + schema.type === undefined + ) { + schema.type = ['array', 'object']; + } fields.items = parseTypeSpecificFields(schema, getType(schema)); } else if (schemas.length > 1) { fields.items = { diff --git a/src/generators/gen.ts b/src/generators/gen.ts index 35a2e99c..a53e8608 100644 --- a/src/generators/gen.ts +++ b/src/generators/gen.ts @@ -6,6 +6,7 @@ import { Type, PrimitiveTypeSchema, getTraitsSchema, + UnionTypeSchema, } from './ast.js'; import { javascript } from './javascript/index.js'; import { objc } from './objc/index.js'; @@ -162,7 +163,7 @@ export declare type Generator< ) => Promise<{ property: P; object?: O }>; generateUnion: ( client: GeneratorClient, - schema: Schema, + schema: UnionTypeSchema, types: (P & BasePropertyContext)[], parentPath: string, ) => Promise

; diff --git a/src/generators/javascript/javascript.ts b/src/generators/javascript/javascript.ts index 4dc260a7..3d0354e4 100644 --- a/src/generators/javascript/javascript.ts +++ b/src/generators/javascript/javascript.ts @@ -151,10 +151,14 @@ export const javascript: Generator< } }, generateUnion: async (client, schema, types) => - conditionallyNullable(schema, { - name: client.namer.escapeString(schema.name), - type: types.map((t) => t.type).join(' | '), - }), + conditionallyNullable( + schema, + { + name: client.namer.escapeString(schema.name), + type: types.map((t) => t.type).join(' | '), + }, + !!schema.enum, + ), generateTrackCall: async (client, _schema, functionName, propertiesObject) => ({ functionName: functionName, propertiesType: propertiesObject.type,