Default values support in codegen
See original GitHub issueSupport for default values were introduced in version 8.0.2 for schema generation, meaning that a class such as this:
public class MyRecord
{
[DefaultValue(null)]
public int? Value { get; set; }
}
Produces this schema, with the expected "default": null
property:
{
"type": "record",
"name": "MyRecord",
"fields": [
{
"name": "Value",
"type": [
"null",
"int"
],
"default": null
}
]
}
What would be great is to also have the opposite. Given schema above, have the generated code include a [DefaultValue]
attribute to match the schema. At the moment, here’s what the generated class looks like for the schema above when running dotnet avro generate
:
public class MyRecord
{
public int? Value { get; set; }
}
This is a problem, because any producer who uses that class will now produce a new schema which no longer includes the default value, and potentially start creating compatibility problems in the schema registry.
Could the dotnet avro generate
command be updated to support default values from the schemas?
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Handling of default values · Issue #138 · deepmap/oapi- ...
Hi, do we have any update on this default value handling? It seems the current version still cannot set the parameter to default...
Read more >how to put parameter default value into generated code in ...
the rcAppKey is null,but i want it be the default value "abc",like: String rcAppKey = "abc"; Common response = api. refresh(rcAppKey); the ......
Read more >codegen - MATLAB Coder
The code generator uses these example values to determine that the first input ... codegen generates C library and supporting files in the...
Read more >Codegen Options - The rustc book
Supported values for this option are: tiny - Tiny code model. small - Small code model. This is the default model for majority...
Read more >Using the GNU Compiler Collection (GCC): Code Gen Options
The default value is ' all '. The option is needed when the program extends the lifetime of a scoped local variable or...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sorry for the late reply, I’ve been sidetracked away from Avro these last few days. I’ve got 2 possible suggestions:
null
of a scalar, generate the[DefaultValue]
attribute correctly. If we’re not in a supported scenario, issue a warning and don’t produce anything.[DefaultSchemaValueJson]
, which reproduce the default value as it is defined in the originating schema, and is used when producing the schema from the record class.Option 1 would be good enough for most cases, and would be enough to ensure we have a good story when one team generate a schema from C# code, and another team wants to produce a C# class from that same schema. The 2nd team would be able to used that class without new, potentially incompatible schemas being published to the registry.
Option 2 would even push this further by allowing a producer to handle schemas that don’t come from a generated C# class.
Yeah, the schema would just be the JSON string, but
DefaultSchemaValueJsonAttribute
would have to live somewhere.