-
-
Notifications
You must be signed in to change notification settings - Fork 325
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] [discussion] [help needed] Generating json object with random key #77
Comments
Hi @hellboy81, you can't do that in one step, I mean, json-schema-faker doesn't allow you to do such thing out of the box. But if you do need such feature, you might just divide generating above document into two steps:
There is very little chance we'd like to implement such feature into json schema faker. And that's because jsf is just a tiny superset of json-schema standard: we add very little to the standard, but provide big functionality. The more we stick to the standard, the more other javascript tools could integrate with jsf. The more we distance from the schema, the more difficult it'd be to integrate. Do you need something further? |
Or you can use {
"type": "object",
"patternProperties": {
"[A-Z\\d]{32}": {
"type": "string"
}
}
} As it follows the json-schema standards I think it would be enough? |
@pateketrueke didn't know about this feature. Now I have a question here - how can we make this dynamically generated attribute required? I've pasted your code into our demo and it randomly gets either the dynamic thing generated or whole being empty. |
I've missed it but using {
"type": "object",
"patternProperties": {
"[A-Z\\d]{32}": {
"type": "string"
}
},
"minProperties": 1
} |
@ducin OK, this is not a part of JSON-Schema specification draft-04 |
@hellboy81 ORLY? Look at this, the find (ctrl+f): @pateketrueke not sure what you mean: you missed it, like, you can't remind what was the right attribute to set, but it does exist? Or you don't know whether it exists or not? ;) the trick you wrote above works for simple cases, but it doesn't seem to scale, if you want to customize the object with required attributes and optional attributes and all the rest that json schema provides. |
@ducin yeah, sorry for that, I've missed that property in the given example. And yeah, is very difficult to ensure required After some research most people say that using min/max properties would be a solution. I didn't get a better idea and JSON-schema is not clear about that. |
Seems like @hellboy81 's question leads to a gap in json schema standard. @pateketrueke no worries! 🍻 |
How can I generate object with random key that has following schema:
Key should be generated on the basis of previous schema (random upper-cased string with length 32)
The text was updated successfully, but these errors were encountered: