Skip to content

Commit

Permalink
Add normalizer rules for $defs and const
Browse files Browse the repository at this point in the history
  • Loading branch information
awlayton committed Apr 9, 2020
1 parent 25f26c1 commit 10426f3
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/normalizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,20 @@ rules.set('Normalize schema.items', (schema, _rootSchema, _fileName, options) =>
return schema
})

rules.set('Transform $defs to definitions', schema => {
if (schema.$defs) {
schema.definitions = schema.$defs
delete schema.$defs
}
})

rules.set('Transform const to singleton enum', schema => {
if (schema.const) {
schema.enum = [schema.const]
delete schema.const
}
})

export function normalize(schema: JSONSchema, filename: string, options: Options): NormalizedJSONSchema {
const _schema = cloneDeep(schema) as NormalizedJSONSchema
rules.forEach((rule, key) => {
Expand Down

0 comments on commit 10426f3

Please sign in to comment.