Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export const CustomFieldSchema = z.object({
}),
)
.optional(),
entityType: z.string(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Missing entity type rejects response

When listCustomFields() returns a field without entityType—for example from an older API response—the schema throws before the filter runs. Every getCustomFields() caller then fails instead of returning its custom-field data, so make this field optional or use the response field guaranteed by the API.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the api guarantees the entityType prop @greptile

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough — if the API contract guarantees entityType is always present, then a required field in the schema is the right call. It'll correctly reject any malformed response rather than silently passing through bad data. I'll withdraw the concern.

Tip: You can customize Greptile's behavior for this repo with .greptile/rules.md and .greptile/config.json.

});
export type CustomField = z.infer<typeof CustomFieldSchema>;
export const CustomFieldResponseSchema = z.object({
Expand Down
3 changes: 2 additions & 1 deletion src/utils/copilotApiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class CopilotAPI {
}

async getCustomFields(): Promise<CustomFieldResponse> {
return CustomFieldResponseSchema.parse(await this.copilot.listCustomFields());
const response = CustomFieldResponseSchema.parse(await this.copilot.listCustomFields());
return { ...response, data: response.data?.filter((field) => field.entityType === 'client') ?? [] };
}
}
Loading