Skip to content

Commit

Permalink
fix: add nested prop for array type any and enum for union (#110)
Browse files Browse the repository at this point in the history
* fix: add nested prop for array type any and enum for union

* fix: refactor
  • Loading branch information
akashrpo authored Jan 10, 2025
1 parent dfa0942 commit 55c22c1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/generators/android/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions src/generators/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
3 changes: 2 additions & 1 deletion src/generators/gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Type,
PrimitiveTypeSchema,
getTraitsSchema,
UnionTypeSchema,
} from './ast.js';
import { javascript } from './javascript/index.js';
import { objc } from './objc/index.js';
Expand Down Expand Up @@ -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<P>;
Expand Down
12 changes: 8 additions & 4 deletions src/generators/javascript/javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 55c22c1

Please sign in to comment.