Skip to content

fix: handle multi-type schemas in node type inference#347

Open
itvi-1234 wants to merge 1 commit into
ioflux-org:mainfrom
itvi-1234:feature/multi-type-schema-support
Open

fix: handle multi-type schemas in node type inference#347
itvi-1234 wants to merge 1 commit into
ioflux-org:mainfrom
itvi-1234:feature/multi-type-schema-support

Conversation

@itvi-1234

@itvi-1234 itvi-1234 commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR fixes an issue where multi-type schemas (e.g., ["string", "null"] or ["integer", "number"]) were failing type inference. Previously, the logic only accounted for primitive string types, causing multi-type nodes to fall through and render with the default "others" (gray) styling.

What Changed

  • src/utils/inferSchemaType.ts: Updated the type inference logic to properly check if the type property is an array. When an array of types is encountered, it selects the first non-null type as the primaryType (e.g., extracting "integer" from ["integer", "null"]). This ensures the node receives the correct semantic coloring based on its primary data type.

##Closes #339

Testing

Test with the following schema to verify the nodes render with their correct semantic colors and display the array values properly:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "name": { "type": "string" },
    "age": { "type": ["integer", "null"] },
    "score": { "type": ["number", "string", "null"] }
  }
}
  • age should render with neon mint coloring (for integer).
  • score should render with neon mint coloring (for number).
image image

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Preview Deployed!

Item Status
Latest Deploy Visit Preview
Environment Preview (PR-347)
Action View Logs

Last updated at 2026-06-30T06:31:36Z

@itvi-1234

Copy link
Copy Markdown
Contributor Author

hi @AgniveshChaubey , @jagpreetrahi , Please review the PR whenever have some time , I have tried and tested it with many schemas , Lemme know if any changes required 🚀

@jagpreetrahi jagpreetrahi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hey Sumit , I've suggest some changes you can have a look into it.

Comment thread src/utils/inferSchemaType.ts Outdated
}

if (Array.isArray(typeValue)) {
const primaryType = (typeValue as string[]).find((t) => t !== "null") ?? "others";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hey sumit,
I would like to suggest one thing as instead of using .find() function for getting a primary Type, can we use the for..of loop. The reason to say it because .find() function must look at every elements sequentially until it find a match and that gives O(n) time complexity in worst case scenario. So, for that concern I looked for alternative one to replaced it.
What I was thinking as we can used for..of loop that optimizes the hidden performance cost called as constant factor that .find()suffer from it.

By doing this we have following advantages as - No callback function overhead : for .find() - JS engine execute its callback for every single element in an array , but in loop, there are no function being constantly called.

Immediate memory allocation : while .find() runs , a new arrow function closure is allocated in the memory, loop allocates exactly zero functions. It has no memory allocation footprint.

However, both these approaches takes O(n) in the worst case, but loop approaches will save us from above mentioned points.

Thanks

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Happy to hear out what do you think on this? Agnivesh.

@jagpreetrahi jagpreetrahi Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hey @sumit, have you explored about a suggestion?? ,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hey @jagpreetrahi , I didn't get notified that you have reviewd the PR . Am sorry for that , Now , I have the full context

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

and looking for the suggestions to improve complexity

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi @jagpreetrahi, thank you for the detailed explanation and for pointing this out! 😊

I wanted to share a thought — in this specific case, the type array in a JSON Schema will always be quite small (typically 1–2 elements, e.g., ["string", "null"]). Given that constraint, the O(n) complexity and the callback overhead of .find() would be practically negligible here.

However, I completely understand the value of consistency and avoiding even micro-overhead as a habit. I'm happy to go ahead with the for...of approach if you'd prefer it — just let me know and I'll update it! 🙌

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yeah, I agreed on that about the size of an array as slightly small in the context of JSON Schema.
So I think we need to see what Agnivesh think about it and will move on.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi @AgniveshChaubey , Could you please provide some directions regarding it

@itvi-1234

Copy link
Copy Markdown
Contributor Author

Hi @AgniveshChaubey and @jagpreetrahi , could you please review this PR whenever have some time

@AgniveshChaubey

Copy link
Copy Markdown
Member
image

The type element's color looks too punchy... I think we should make it a bit light (maybe making it transparent would work).

image

Also, in light mode, text is not quite readable.

Signed-off-by: itvi-1234 <rjsumit71@gmail.com>
@itvi-1234

Copy link
Copy Markdown
Contributor Author

Hi @AgniveshChaubey & @jagpreetrahi ,I have made the background a bit light , could you please review this PR whenever have some time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Distinct visualization of multi-type schema

3 participants