Skip to content

Commit

Permalink
clean up types for isSchemaLike
Browse files Browse the repository at this point in the history
  • Loading branch information
bcherny committed Jun 26, 2024
1 parent 6fc74b3 commit e0a822f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,12 @@ export function appendToDescription(existingDescription: string | undefined, ...
return values.join('\n')
}

export function isSchemaLike(schema: LinkedJSONSchema) {
export function isSchemaLike(schema: any): schema is LinkedJSONSchema {
if (!isPlainObject(schema)) {
return false
}

// top-level schema
const parent = schema[Parent]
if (parent === null) {
return true
Expand Down
9 changes: 4 additions & 5 deletions test/testUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import test from 'ava'
import {link} from '../src/linker'
import {LinkedJSONSchema} from '../src/types/JSONSchema'
import {pathTransform, generateName, isSchemaLike} from '../src/utils'

export function run() {
Expand Down Expand Up @@ -38,10 +37,10 @@ export function run() {
required: ['firstName', 'lastName'],
})
t.is(isSchemaLike(schema), true)
t.is(isSchemaLike([] as any as LinkedJSONSchema), false)
t.is(isSchemaLike(schema.properties as LinkedJSONSchema), false)
t.is(isSchemaLike(schema.required as any as LinkedJSONSchema), false)
t.is(isSchemaLike(schema.title as any as LinkedJSONSchema), false)
t.is(isSchemaLike([]), false)
t.is(isSchemaLike(schema.properties), false)
t.is(isSchemaLike(schema.required), false)
t.is(isSchemaLike(schema.title), false)
t.is(isSchemaLike(schema.properties!.firstName), true)
t.is(isSchemaLike(schema.properties!.lastName), true)
})
Expand Down

0 comments on commit e0a822f

Please sign in to comment.