-
Notifications
You must be signed in to change notification settings - Fork 117
Closed
Description
I have a schema like this
message Plan {
// The date of the plan. The timestamp will begin on the date in UTC.
google.protobuf.Timestamp date = 1 [(buf.validate.field).required = true];
}
message GetPlansRequest {}
message GetPlansResponse {
// The users current plans.
repeated Plan plans = 1;
}
The generated code does not generate GetPlansResponseValid
with plans: PlanValid[]
export type GetPlansResponse = Message<"frontendapi.GetPlansResponse"> & {
/**
* The users current plans.
*
* @generated from field: repeated frontendapi.Plan plans = 1;
*/
plans: Plan[];
};
export type GetPlansResponseValid = GetPlansResponse; // !!! Needs to be a valid type
/**
* Describes the message frontendapi.GetPlansResponse.
* Use `create(GetPlansResponseSchema)` to create a new message.
*/
export const GetPlansResponseSchema: GenMessage<GetPlansResponse, {validType: GetPlansResponseValid}> = /*@__PURE__*/
messageDesc(file_frontendapi_frontend, 22);
I suspect this is because GetPlansResponse
itself has no annotations so is getting ignored by the valid type generation. All of a message's message-type fields would need to be checked to see if a valid type should be generated.
My workaround is to validate the field
const plans = plansRes.plans
.map((p) => validator.validate(PlanSchema, p))
.filter((r) => r.kind === "valid")
.map((r) => r.message);
but I'd like to be able to validate the whole response as one, notably it makes handling an invalid result (which I don't do here since it becomes too awkward) much easier.
Metadata
Metadata
Assignees
Labels
No labels