cue icon indicating copy to clipboard operation
cue copied to clipboard

Using cue to generate deterministic example data that satisfies constraints

Open cueckoo opened this issue 4 years ago • 1 comments

Originally opened by @taras in https://github.com/cuelang/cue/issues/717

Is your feature request related to a problem? Please describe.

I want to be able to create a bunch of fixture data from a cue configuration.

Describe the solution you'd like

if I have a configuration like this,

msg:   "Hello \(place)!"
place: "World" | "Earth" | "Toronto"

I would like to be able to execute some command that automatically chooses one of the options in some deterministic fashion.

cue generate myscript.cue

msg: "Hello Earth"
place: "Earth"

Describe alternatives you've considered

I can imagine that I could write some Golang code that would do this. I wanted to check if there is a way to do this out of the box.

Additional context

I'm trying to see if I could use cue to generate objects from something like factories in ORM. There are tools like Faker.js that have constraints but they are very limited. Also, they require writing JavaScript which can be unattractive to some opinionated developers who're not JavaScript users. CueLang seems like a good neutral alternative for a cross-platform API.

cueckoo avatar Jul 03 '21 10:07 cueckoo

Original reply by @mpvl in https://github.com/cuelang/cue/issues/717#issuecomment-778442195

This would also be useful for fuzzing.

cueckoo avatar Jul 03 '21 10:07 cueckoo