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

JSON schema enum value description #1339

Open
Chaoses-Ib opened this issue Sep 28, 2024 · 2 comments
Open

JSON schema enum value description #1339

Chaoses-Ib opened this issue Sep 28, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@Chaoses-Ib
Copy link

Is it possible to specify description for enum values? I tried the following code but it doesn't work:

enum A {
    A1 = 1,
    A2 = 2,
    A3 = 3
};

template <>
struct glz::json_schema<A>
{
   schema A1{.description = "a1 desc"};
   schema A2{.description = "a2 desc"};
   schema A3{.description = "a3 desc"};
};
@Chaoses-Ib
Copy link
Author

Oh, I just found it's not officially supported by JSON Schema: json-schema-org/json-schema-vocabularies#47. Though there is a workaround:

{
  "docHint": "enum",
  "anyOf": [
    { "const": "a", "description": "A" },
    { "const": "b", "description": "B" },
    { "const": "c", "description": "C" }
  ]
}

@stephenberry
Copy link
Owner

I'll have to come back to this, but note that Glaze does not automatically reflect your enum. Meaning it will treat your enum values as integers by default.

Use a glz::meta for your enum and the enumerate function to list out your enum values (which can be reflected there). I expect this might then work with your json schema description in Glaze.

@stephenberry stephenberry added the enhancement New feature or request label Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants