Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default values are not generated for "root" schemas/entities #243

Closed
Fresa opened this issue Sep 12, 2023 · 2 comments · Fixed by #245
Closed

Default values are not generated for "root" schemas/entities #243

Fresa opened this issue Sep 12, 2023 · 2 comments · Fixed by #245
Assignees
Labels
review This issue needs review. The goal is unclear or disputed.

Comments

@Fresa
Copy link

Fresa commented Sep 12, 2023

Schema entities that has properties (sub-schemas) defined with the default annotation will include a *.Defaults.cs file including the default values of those properties. This does not seem to be the case when the entity it self contains a default value.

Schema example:

{
  "type": "string",
  "default": "foo"
}

This schema will not generate a type that includes the defined default value.

Corvus.Json.CodeGeneration.202012: 1.0.17

@mwadams mwadams self-assigned this Sep 13, 2023
@mwadams mwadams added the review This issue needs review. The goal is unclear or disputed. label Sep 13, 2023
@mwadams
Copy link
Contributor

mwadams commented Sep 13, 2023

This is a (design) bug.

We should be setting the default values as statics on the schema type and then using them in the helpers for default property value retrieval on an object.

A fix will be non-breaking.

@mwadams mwadams linked a pull request Sep 14, 2023 that will close this issue
@Fresa
Copy link
Author

Fresa commented Sep 15, 2023

Great stuff, you are fast! :)

Entities that are generated from schemas that describes objects does not get it's DefaultInstance set with the default values of it's properties, wouldn't that be nice?

Example:

foo:
  type: object
  properties:
    bar:
      type: string
      default: dolor sit amet
    fee:
      type: string
      default: lorem ipsus
  required:
  - bar
  - fee

Expectation:

var foo = Foo.DefaultInstance;
Console.WriteLine(foo.Bar); // "dolor sit amet"
Console.WriteLine(foo.Fee); // "lorem ipsus"

Currently it instantiates Foo with nothing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review This issue needs review. The goal is unclear or disputed.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants