Skip to content

fix(codegen): preserve optional on scalar properties in Avro, GraphQL, Protobuf and Rust - #313

Closed
ItsAbir005 wants to merge 1 commit into
accordproject:mainfrom
ItsAbir005:abir
Closed

ItsAbir005 wants to merge 1 commit into
accordproject:mainfrom
ItsAbir005:abir

Conversation

@ItsAbir005

Copy link
Copy Markdown

Closes #306

Optional properties with a scalar type (for example o SSN taxId optional) were generated as required in the Avro, GraphQL, Protobuf and Rust visitors. This PR fixes that, so they now match an o String taxId optional property.

Changes

  • Field.getScalarField() in concerto-core builds a new field that copies name and array but not optional, so visitField treated scalar-typed properties as required.
  • visit() now passes thing.isOptional() into visitField as an optional isOptional argument. It defaults to field.isOptional(), so other callers behave as before.
  • Protobuf's concertoToProto3FieldRule gets the same optional isOptional argument.
  • In the APAP protocol Protobuf fixture, Function.responseType, Logic.stateType, Agreement.state, PdfConversionOptions.styles and TriggerResponse.result are now optional. They were already optional in apapProtocol.cto.
  • types/*.d.ts is regenerated, because concertoToProto3FieldRule is public and its signature changed.
  • Added a unit test per visitor (Avro, GraphQL, Protobuf, Rust) using the model from the issue.

Generated output for o SSN taxId optional:

Target Before After
Avro string taxId; union { null, string } taxId;
GraphQL taxId: String! taxId: String
Protobuf string taxId = 3; optional string taxId = 3;
Rust pub tax_id: String, pub tax_id: Option<String>, with skip_serializing_if

Flags

  • Rust's visitField is also called with a plain { name: '$class', type: 'String' } object, so its default is field.isOptional?.(). Relationship handling in the Rust visitor is unchanged.
  • I edited the APAP Protobuf fixture by hand. Its test downloads models, so I couldn't run it. Please check it in CI.
  • I ran npx eslint lib test (clean) and the full mocha suite (693 passing, 24 failing). The same 24 fail without this change, because they need protoc, xmllint, avro-tools and network access that my environment lacks.
  • I did not run the real-tool verification (protoc, cargo check).
  • npm run test:updateSnapshots produced no snapshot changes.
  • I haven't audited the other visitors that call getScalarField(). TypeScript was fixed in fix(typescript): propagate optional modifier for scalar fields #195, and the C# and JSON Schema visitors already read isOptional() from the property.

Screenshots or Video

N/A

Related Issues

Author Checklist

  • Ensure you provide a DCO sign-off for your commits using the --signoff option of git commit.
  • Vital features and changes captured in unit and/or integration tests
  • Commits messages follow AP format
  • Extend the documentation, if necessary
  • Merging to main from fork:branchname

🤖 Generated with Claude Code

https://claude.ai/code/session_01HLiXZ9jMJ2WD3FmLRKWnsi

…, Protobuf and Rust

Field.getScalarField() builds a new field that copies name and array but
not optional, so visitField treated `o SSN taxId optional` as required.

Pass thing.isOptional() from visit() into visitField as an optional
isOptional argument (defaulting to field.isOptional()), and use it
wherever visitField checked optionality. Protobuf's
concertoToProto3FieldRule gets the same optional argument.

Also marks Function.responseType, Logic.stateType, Agreement.state,
PdfConversionOptions.styles and TriggerResponse.result as optional in
the APAP protocol Protobuf fixture, and regenerates the type
declarations.

Closes #306

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HLiXZ9jMJ2WD3FmLRKWnsi
Signed-off-by: Abir Maity <abirmaity44@gmail.com>
Copilot AI balanced review requested due to automatic review settings November 2, 2026 13:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@ItsAbir005 ItsAbir005 closed this by deleting the head repository Nov 2, 2026
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.

bug: optional properties with a scalar type are generated as required in Avro, GraphQL, Protobuf and Rust

2 participants