Skip to content

Commit

Permalink
feat: replace uuid with internal counter (#661)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak authored Nov 12, 2023
1 parent 14338e2 commit 4f6f7b8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

const merge = require('@fastify/deepmerge')()
const clone = require('rfdc')({ proto: true })
const { randomUUID } = require('crypto')
const { RefResolver } = require('json-schema-ref-resolver')

const validate = require('./lib/schema-validator')
Expand All @@ -31,6 +30,8 @@ const validLargeArrayMechanisms = [

const addComma = '!addComma && (addComma = true) || (json += \',\')'

let schemaIdCounter = 0

function isValidSchema (schema, name) {
if (!validate(schema)) {
if (name) {
Expand Down Expand Up @@ -86,7 +87,7 @@ function build (schema, options) {
options,
wrapObjects: true,
refResolver: new RefResolver(),
rootSchemaId: schema.$id || randomUUID(),
rootSchemaId: schema.$id || `__fjs_root_${schemaIdCounter++}`,
validatorSchemasIds: new Set()
}

Expand Down Expand Up @@ -500,7 +501,7 @@ function mergeAllOfSchema (context, location, schema, mergedSchema) {
}
delete mergedSchema.allOf

mergedSchema.$id = `merged_${randomUUID()}`
mergedSchema.$id = `__fjs_merged_${schemaIdCounter++}`
context.refResolver.addSchema(mergedSchema)
location.addMergedSchema(mergedSchema, mergedSchema.$id)
}
Expand Down

0 comments on commit 4f6f7b8

Please sign in to comment.