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

Question re default keyword on objects #1558

Open
andye2004 opened this issue Aug 15, 2023 · 0 comments
Open

Question re default keyword on objects #1558

andye2004 opened this issue Aug 15, 2023 · 0 comments

Comments

@andye2004
Copy link

I'm wondering if there would be any appetite for adding a recognised value as a marker to instantiate an empty instance of an object, if the object is marked with the default keyword?

This is a fairly contrived example but consider the folowing foo-bar schema snippet:

{
  "title": "Foo Bar Schema",
  "type": "object",
  "properties": {
    "foo": {
      "title": "foo",
      "type": "object",
      "default": "instance",
      "properties": {
        "title": "bar",
        "type": "string",
        "default": "foobar"
      }
    },
    "bar": {
      "title": "bar",
      "type": "string",
      "default": "bar"
    }
  }
}

When the generate target is run we end up with two pojos, Foo.java and FooBar.java, with FooBar.java containing a foo property as follows:-

...
private Foo foo = null;
...

It would be good if, based on a known value being used as the default, e.g. "default": "instance", the following code could be generated instead:

...
private Foo foo = new Foo();
...

I've used the word instance in the example but the actual value could be made configurable to fit with different organisational requirements.

I'd be happy to provide a PR if it's something that would be accepted into the project.

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

No branches or pull requests

1 participant