-
-
Notifications
You must be signed in to change notification settings - Fork 292
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
enum type without specifying values #340
Comments
I think that what you want could be accomplished via the Alternatively, you can just dynamically generate the schema based on the current table contents, which would be a workable solution right now. |
I want to use the schema to generate a scaffolding for my front and back end code and possibly to define some of my database objects. So the schema will come first, and then the database after. |
@swamikevala, I like your schema-first approach! I have the same philosophy (although I'm not a huge fan of scaffolding). Anyway, I don't think there is a good answer to your particular problem. Ideally, you probably want to be able to do something like the following where "/countries" is an endpoint that points to an array of enum options. That URI doesn't have to point anything real. It's just a hint for your scaffolding generator. {
"country": {
"enum": { "$ref": "/countries" }
}
} This would allow you to indicate that you expect an enum while differing defining the values of that enum. Unfortunately, you can only {
"country": { "$ref": "/countries" }
} Then have "/countries" be a schema that defines an enum. But, that doesn't solve your problem because you lose any indication that this will be an enum one day. The {
"country": {
"enum": { "$data": "/countries" }
}
} I think that would solve your problem. Unfortunately, So, I think your only option is to introduce a custom keyword to solve your problem. Or, maybe there is another way to design your solution where something like this isn't needed. |
@jdesrosiers, thanks for the detailed response. I had considered all those options. I would like to be able to use the first option. i.e. Allow $ref to point to arbitrary json data (not necessarily a json schema). In my opinion that would be the simplest and clearest approach. Do you think this could be something we could request for the next version of the spec, or is there a good reason for not allowing this? I guess we'll go with our custom "x-enums" keyword. This also will give us more flexibility (e.g. for hierarchical enums)
|
This is another proposal to achieve it: https://github.com/json-schema-org/json-schema-spec/issues/322 |
You can always start the conversation. But, I think it's unlikely to be accepted considering that we just decided to go the other direction on this topic. Until the most recent version of the spec (draft-06), it was not made explicit that Your use case (scaffolding generation) is outside the scope of what JSON Schema was designed for. In any normal use case that I have seen or can think of, using |
I think that restricting It makes sense to use allow referencing certain coherent units that are hard to manage otherwise- the array nature of the Whether this issue brings up another good use case I'm not sure- I haven't thought it through yet. But I would encourage looking at #322 as @epoberezkin suggests as the more an idea picks up use cases from multiple people, the more likely it is to be considered. Both |
|
This topic is more comprehensively tracked under #855, where we have consolidated several closely related ideas. |
I want to define a property as an enum. But I don't want to enter the enum values in the schema. The values will be fetched from a database and will be dynamic in nature.
I want to do something like this:
"TAG": { "type": "enum" }
The schema will be used to auto-generate api code and database queries. (So I need to know that it is an enum property - so the generated code will query the constants table in the db). What is the best way to do this?
I'm currenty followung the openAPI spec, so I'm doing this right now (using a custom extension) :
The text was updated successfully, but these errors were encountered: