Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/utils/getSchemaType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ export function getSchemaType(node: SchemaNode, data: unknown): SchemaType | und

// nothing found yet check dynamic properties for a type
if (node.if) {
return getSchemaType(node.if, data);
return getSchemaType(node.if.getNode("#").node ?? node.if, data);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is out of scope of this merge request. I am wondering, why are you adding ref-resolution here?

If we were to add this:

  • getNode would need data as second argument to fully use its api
  • I would prefer to use node.if.resolveRef here to be explicit

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the short story here is that first I realised that types of getSchemaType are off, so I fixed them and created this PR, later while working on my product I've seen that the function is also not working correctly on oneOf nodes with refs, so I thought this PR is close enough to include this as well... If you prefer I can split this into two PRs (or we can keep it as single one if that's ok)

as for node.if.resolveRef - I think it should work... I pushed the changes about that, are those ok?
and if you won't mind - what's the real benefit of using resolveRef here? I think that getNode looks to be way more generic way of "get me whatever there is underneath" right? under the hood it's also looks to handle more edge cases than resolveRef 🤔

}

if (node.allOf) {
for (let i = 0; i < node.allOf.length; i += 1) {
const type = getSchemaType(node.allOf[i], data);
const type = getSchemaType(node.allOf[i].getNode("#").node ?? node.allOf[i], data);
if (type) {
return type;
}
Expand All @@ -120,7 +120,7 @@ export function getSchemaType(node: SchemaNode, data: unknown): SchemaType | und

if (node.oneOf) {
for (let i = 0; i < node.oneOf.length; i += 1) {
const type = getSchemaType(node.oneOf[i], data);
const type = getSchemaType(node.oneOf[i].getNode("#").node ?? node.oneOf[i], data);
if (type) {
return type;
}
Expand All @@ -129,7 +129,7 @@ export function getSchemaType(node: SchemaNode, data: unknown): SchemaType | und

if (node.anyOf) {
for (let i = 0; i < node.anyOf.length; i += 1) {
const type = getSchemaType(node.anyOf[i], data);
const type = getSchemaType(node.anyOf[i].getNode("#").node ?? node.anyOf[i], data);
if (type) {
return type;
}
Expand Down