Skip to content

Commit

Permalink
feat: some slight normalization improvement (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomerAberbach authored Dec 26, 2024
1 parent c764f17 commit 6e97f88
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 0 additions & 1 deletion examples/openai-arbitraries.js
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,6 @@ export const OpenAI = {
model: fc.oneof(
fc.string(),
fc.constantFrom("text-moderation-latest", "text-moderation-stable"),
fc.constant("text-moderation-latest"),
),
},
{
Expand Down
8 changes: 6 additions & 2 deletions src/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,19 @@ const normalizeDictionaryArbitrary = ({
dictionaryArbitrary(normalizeArbitrary(key), normalizeArbitrary(value))

const normalizeUnionArbitrary = (arbitrary: UnionArbitrary): Arbitrary => {
const variants = new Set(
const variants = new Set<Arbitrary>(
arbitrary.variants.map(normalizeArbitrary).flatMap(variant => {
// eslint-disable-next-line typescript/switch-exhaustiveness-check
switch (variant.type) {
case `enum`:
// These will be re-collapsed below if necessary.
return variant.members.map(constantArbitrary)
case `union`:
return variant.variants
return variant.variants.flatMap(variant =>
variant.type === `enum`
? variant.members.map(constantArbitrary)
: [variant],
)
default:
return [variant]
}
Expand Down

0 comments on commit 6e97f88

Please sign in to comment.