Enhance Candid schema parser and codegen with validation support#187
Enhance Candid schema parser and codegen with validation support#187b3hr4d wants to merge 11 commits into
Conversation
…se renderer module.
…nder them instead of inline metadata
…alidation support to codegen and update playground samples
…add metadata rules support
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0c6b82fc1a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| args: func | ||
| .args | ||
| .iter() | ||
| .map(|arg| type_to_schema(arg, None)) |
There was a problem hiding this comment.
Preserve metadata for inline method records
When a service method uses an inline record/variant argument whose fields have doc comments or validation tags, this passes None into type_to_schema, so syntax_field_for never sees the corresponding TypeField.docs and the field metadata is dropped; named type declarations still work because their syntax type is supplied. The same pattern is used for returns below, so generated Cod for inline method payloads silently loses @format/@minLength validation.
Useful? React with 👍 / 👎.
| return `, c.tuple([${method.returns | ||
| .map((returnType) => renderType(returnType, " ", options)) | ||
| .join(", ")}])` |
There was a problem hiding this comment.
Do not encode multiple returns as a tuple
For methods declared -> (A, B), parseDid produces two entries in method.returns, but this renders a single c.tuple return codec. CandidServiceCodec later passes returnCodec.toIDL() as one element in IDL.Func's returns array, so the generated idlFactory describes -> (record { 0 : A; 1 : B }) rather than two return values and will not match canisters with multiple returns.
Useful? React with 👍 / 👎.
…ancing codec functionality
Summary
This PR improves validation metadata handling in the Candid codec generation pipeline by centralizing default validation messages and format rules in a shared metadata rules source.
What changed
Why
This reduces duplication between the parser and renderer, keeps validation defaults consistent across both layers, and makes future metadata rule changes easier to maintain.
Verification