You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add dsl.Randomiser that lets you pass your own example randomiser (goadesign#3191)
* Add dsl.Randomiser that lets you pass your own example randomiser
1. Rename `expr.Random` to `expr.FakerRandom`
2. Add an interface `expr.Randomiser` that covers the methods we need
3. Split out `expr.ExampleGenerator` that handles the 'do we already
have an example for this' logic from the 'generate examples' stuff
4. Change `(expr.APIExpr).random` to `(expr.APIExpr).ExampleGenerator`,
and initialise it with a faker-based random example generator
5. Add `dsl.Randomiser` which overrides `(expr.APIExpr).ExampleGenerator` with
whatever randomiser you want to pass in, wrapped in the
non-customisable 'only generate one example for each thing' logic.
I've also added an `ArrayLength` method to the randomiser interface, and
updated places that previously would call `r.Int()` to generate an array
length to use that.
The motivation for this PR is that we have a large design and many
people working on it, and the diffs we get on OpenAPI schema files can
be quite hard to read with most of the changes coming from changes to
the random examples due to the order of example generation when we add
new types (for example).
We'd therefore like to disable all random example generation and use
hard-coded default examples, and define manual examples with
`dsl.Example` where we'd like them.
* Randomiser -> Randomizer
* NewRandom -> NewFakerRandomizer and NewRandomExampleGenerator -> NewRandom
to maintain the existing interface
* Reorder the expr/random.go file to be clearer
* Rename FakerRandom -> FakerRandomizer
It implements `Randomizer`, so should really have that in its name
* Add DeterministicRandomizer, which returns hard-coded values
* Try to match the old randomization logic exactly
* Fix the openapi v2 tests
* remove spew
* Actually use `ArrayLength()`
I over-did it a bit in my effort to fix tests.
* Sort out the examples
0 commit comments