Skip to content

Commit

Permalink
(fix, csharp): map<string, unknown> values are nullable (#4153)
Browse files Browse the repository at this point in the history
  • Loading branch information
amckinney authored Jul 30, 2024
1 parent 03b84d2 commit 173e2d4
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 18 deletions.
14 changes: 9 additions & 5 deletions generators/csharp/codegen/src/context/CsharpTypeMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,15 @@ export class CsharpTypeMapper {
switch (container.type) {
case "list":
return Type.list(this.convert({ reference: container.list, unboxOptionals: true }));
case "map":
return Type.map(
this.convert({ reference: container.keyType }),
this.convert({ reference: container.valueType })
);
case "map": {
const key = this.convert({ reference: container.keyType });
const value = this.convert({ reference: container.valueType });
if (value.internalType.type === "object") {
// object map values should be nullable.
return Type.map(key, csharp.Type.optional(value));
}
return Type.map(key, value);
}
case "set":
return Type.set(this.convert({ reference: container.set, unboxOptionals: true }));
case "optional":
Expand Down
6 changes: 6 additions & 0 deletions generators/csharp/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

- Improvement: `map<string, unknown>` types are now generated as `Dictionary<string, object?>` types so they
can support explicit `null` values. Note that this does _not_ affect every `unknown` type to be an `object?`
since it would otherwise alter its required/optional characteristics.

## [0.3.4 - 2024-07-30]

- Improvement: Make datetime deserialization more lenient, and include milliseconds in datetime serialization.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion seed/csharp-model/examples/src/SeedExamples/Types/Movie.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion seed/csharp-model/trace/src/SeedTrace/Submission/Scope.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 173e2d4

Please sign in to comment.