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

Consider adding support of EnumNames or Enum: Object #8

Closed
bruno-f-cruz opened this issue Oct 26, 2023 · 3 comments
Closed

Consider adding support of EnumNames or Enum: Object #8

bruno-f-cruz opened this issue Oct 26, 2023 · 3 comments

Comments

@bruno-f-cruz
Copy link
Contributor

json-schemas seems to allow enums to be defined as arrays of objects, eg:

{
  "object": {
    "title": "object_title",
    "description": "desc",
    "enum": [
      {
        "name": "name1",
        "attr": "attr_value1"
      },
      {
        "name": "name2",
        "attr": "attr_value2"
      }
    ]
  }
}

Moreover, additional support from some standards have also added a way to use enumNames to refer to these enum entries:

{
  "object": {
    "title": "object_title",
    "description": "desc",
    "enum": [
      {
        "name": "name1",
        "attr": "attr_value1"
      },
      {
        "name": "name2",
        "attr": "attr_value2"
      }
    ],
    "enumNames": ["name1", "name2"]
  }
}

Since csharp Enum only allow for numeric values, it would be great to implement a way to instantiate the enum name with the enumNames but still try to support the serialization/deserialization somehow.

@glopesdev
Copy link
Member

@bruno-f-cruz This seems to be related to #11. I was checking some more examples of enum-like declarations in JSON-schema and to be honest they seem to be all over the place. As an example you can check the OpenAPI specification approach to labeled enums: OAI/OpenAPI-Specification#348 (comment) where at least three different approaches to enum declaration are discussed and proposed.

If these patterns are something that NJsonSchema recognizes and can generate C# code for, then we can definitely modify and adapt the underlying model data structures. Otherwise I feel we should probably restrict ourselves to support only constructs that are compatible out-of-the-box with NJsonSchema, as we won't have the resources to diverge and maintain the foundations for a full-blown standards compliant parser/generator ourselves.

@bruno-f-cruz
Copy link
Contributor Author

I completely agree, NJsonSchema already recognizes some of these patterns (e.g. https://github.com/RicoSuter/NJsonSchema/wiki/Enums). I would probably leave it "as is" if it is not too much work and if it doesn't break anything. We can think if we want to leverage a different behavior in the future. I would also agree with your general comment of being careful to not veer too far off from the NJsonSchema.

@glopesdev
Copy link
Member

@bruno-f-cruz can you test if the modifications in #20 are acceptable to close this?

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

2 participants