Skip to content

Commit

Permalink
add normalizer step to simplify intersection+schema types
Browse files Browse the repository at this point in the history
bcherny committed Jun 24, 2024
1 parent 1252285 commit bcbbbd1
Showing 3 changed files with 561 additions and 197 deletions.
21 changes: 21 additions & 0 deletions src/normalizer.ts
Original file line number Diff line number Diff line change
@@ -222,6 +222,27 @@ rules.set('Transform const to singleton enum', schema => {
}
})

rules.set('Simplify intersection+schemas to intersection', schema => {
if (schema.allOf && (schema.properties || schema.patternProperties || schema.required || schema.type === 'object')) {
const newCase: LinkedJSONSchema = {
[Parent]: schema,
properties: schema.properties,
additionalProperties: schema.additionalProperties,
patternProperties: schema.patternProperties,
required: schema.required,
}
if (schema.type === 'object') {
newCase.type = 'object'
delete schema.type
}
schema.allOf.push(newCase)
delete schema.properties
delete schema.patternProperties
delete schema.required
// leave additionalProperties as-is
}
})

export function normalize(
rootSchema: LinkedJSONSchema,
dereferencedPaths: DereferencedPaths,
Loading

0 comments on commit bcbbbd1

Please sign in to comment.