Skip to content

Commit

Permalink
correct isSchema type guard for type lists
Browse files Browse the repository at this point in the history
  • Loading branch information
fulpm committed Oct 3, 2024
1 parent 17177a7 commit 7ce8298
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 19 deletions.
2 changes: 1 addition & 1 deletion codegen/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export function isSchema(value: SchemaType | Schema | Ref | null | undefined): v
if (value == null || Array.isArray(value) || typeof value === "string") {
return false;
}
return !isRef(value) && "type" in value && typeof value.type === "string";
return !isRef(value) && "type" in value && (typeof value.type === "string" || Array.isArray(value.type));
}

export function isSchemaOrRef(value: SchemaType | Schema | Ref | boolean | null | undefined): value is Schema | Ref {
Expand Down
32 changes: 21 additions & 11 deletions codegen/filters/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,34 @@ export function isArray(value: any) {
return Array.isArray(value);
}

export function convertType(value: SchemaType) {
switch (value) {
export function convertType(schema: SchemaType) {
let value: string;
switch (schema) {
case "assoc":
return "object";
value = "Record<string, any>";
break;
case "list":
return "any[]";
value = "any[]";
break;
case "string":
return "string";
value = "string";
break;
case "boolean":
return "boolean";
value = "boolean";
break;
case "number":
return "number";
value = "number";
break;
case "null":
return "null";
value = "null";
break;
case "any":
return "any";
value = "any";
break;
default:
console.warn(`Unexpected type received: ${value}`);
return "any";
console.warn(`Unexpected type received: ${schema}`);
value = "any";
}

return this.env.filters.safe(value);
}
2 changes: 1 addition & 1 deletion src/types/schemas/BuiltInFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type BuiltInFeatures = {
/**
* The list of features that have been imputed for the case.
*/
".imputed"?: any[] | null;
".imputed"?: string[] | null;
/**
* The normalized influence of a case on a prediction.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/types/schemas/CopySubtrainee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ export type CopySubtraineeRequest = {
/**
* Name of new copied trainee
*/
target_trainee: string | any[];
target_trainee: string | string[];
};
2 changes: 1 addition & 1 deletion src/types/schemas/CreateSubtrainee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type CreateSubtraineeRequest = {
* Name of trainee to create
* @default ""
*/
trainee?: string | any[];
trainee?: string | string[];

/**
* Unique id for trainee
Expand Down
2 changes: 1 addition & 1 deletion src/types/schemas/DeleteSubtrainee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ export type DeleteSubtraineeRequest = {
/**
* Name path of trainee
*/
trainee: string | any[];
trainee: string | string[];
};
2 changes: 1 addition & 1 deletion src/types/schemas/LoadSubtrainee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ export type LoadSubtraineeRequest = {
* Name path of trainee to load
* @default ""
*/
trainee?: string | any[];
trainee?: string | string[];
};
2 changes: 1 addition & 1 deletion src/types/schemas/SaveSubtrainee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type SaveSubtraineeRequest = {
* Trainee instance name path to store
* @default ""
*/
trainee?: string | any[];
trainee?: string | string[];

/**
* Unique id for trainee. must be provided if trainee does not have one already specified.
Expand Down
2 changes: 1 addition & 1 deletion src/types/schemas/SetMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ export type SetMetadataRequest = {
/**
* Arbitary map of metadata to store in a trainee
*/
metadata: object | null;
metadata: Record<string, any> | null;
};

0 comments on commit 7ce8298

Please sign in to comment.