Repository navigation
fix: keep the optional modifier of scalar fields in Avro, GraphQL, Protobuf and Rust - #309
Open
NopeCharon wants to merge 1 commit into
Open
NopeCharon wants to merge 1 commit into
NopeCharon wants to merge 1 commit into
Conversation
…otobuf and Rust
These visitors dispatch fields with a scalar type to
visitField(thing.getScalarField(), parameters). The field built by
getScalarField() comes from the scalar declaration. It keeps the
property name and array flag but not the optional modifier, so
`o SSN taxId optional` was generated as a required field:
- Avro: `string taxId;` instead of `union { null, string } taxId;`
- GraphQL: `taxId: String!` instead of `taxId: String`
- Protobuf: `string taxId` instead of `optional string taxId`
- Rust: `String` instead of `Option<String>`, so valid JSON without the
property failed to deserialize
Pass thing.isOptional() into visitField as an optional isOptional
argument that defaults to field.isOptional(), and use it in place of
field.isOptional() in visitField and, for Protobuf, in
concertoToProto3FieldRule. TypeScript had the same bug (accordproject#194), and
CSharpVisitor already passes the property's optional modifier
explicitly.
The expected Protobuf output for the APAP protocol model is updated:
responseType, stateType, state, styles and result are optional in
apapProtocol.cto.
Closes accordproject#306
Signed-off-by: NopeCharon <115794254+NopeCharon@users.noreply.github.com>
|
Thanks for your contribution, and for opening #306 with the details alongside this PR. The CI workflows need a maintainer's approval because this is a first contribution; that has been requested and the checks should start shortly. After that, the PR waits for review from the Concerto maintainers. If you push more changes, the checks will run again, and it helps if the commits are signed off (DCO). Drafted by an Accord Project agent, reviewed by a maintainer. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #306
Optional properties with a scalar type (
o SSN taxId optional) are now generated as optional in Avro, GraphQL, Protobuf and Rust. Before this change they were generated as required.Changes
visit(), passthing.isOptional()with the field returned bygetScalarField(). That field is built from the scalar declaration and does not carry the property'soptionalmodifier.visitFieldtakes an optionalisOptionalargument that defaults tofield.isOptional(), and uses it everywhere it readfield.isOptional()before. In Protobuf,concertoToProto3FieldRuletakes the same optional argument.DateTimeand optional array scalar properties.org.accordproject.protocol.v1_0_0-expected.proto:responseType,stateType,state,stylesandresultareoptionalinapapProtocol.cto, but the expected output had them as required.Flags
CSharpVisitor.writeFieldalso passes the property's optional modifier explicitly. Java and Go don't express optionality, and OData'sNullablealready defaults to true, so those visitors are unchanged.main.Screenshots or Video
N/A
Related Issues
Author Checklist
--signoffoption of git commit.mainfromfork:branchname