Skip to content

Enhance Candid schema parser and codegen with validation support#187

Open
b3hr4d wants to merge 11 commits into
mainfrom
pr-186-candid-codec
Open

Enhance Candid schema parser and codegen with validation support#187
b3hr4d wants to merge 11 commits into
mainfrom
pr-186-candid-codec

Conversation

@b3hr4d

@b3hr4d b3hr4d commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator

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

  • Added shared default validation message templates for bounds such as minimum, maximum, minLength, and maxLength.
  • Wired parser-side validation normalization to use the same metadata rules as codegen.
  • Updated codec generation to consume normalized validation metadata consistently.
  • Added regression coverage for parser behavior around default validation messages.

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

  • Parser tests: passed
  • Codegen tests: passed

Comment thread packages/codegen/src/renderer.ts Fixed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread packages/parser/src/lib.rs Outdated
args: func
.args
.iter()
.map(|arg| type_to_schema(arg, None))

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 Badge 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 👍 / 👎.

Comment thread packages/codegen/src/renderer.ts Outdated
Comment on lines +436 to +438
return `, c.tuple([${method.returns
.map((returnType) => renderType(returnType, " ", options))
.join(", ")}])`

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 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant