Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Typebox isn't able to deref nested references #863

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

aberigle
Copy link

@aberigle aberigle commented Oct 4, 2024

references weren't being passed along to Clean when validating a response. So Typebox wasn't able to deref.

I've added the references in the cleaner, to be able to deref properly.

There is a new test case as an example also:

  it('validate nested references', async () => {
    const job = t.Object({
      name : t.String()
    }, { $id: "job" })

    const person = t.Object({
      name : t.String(),
      job  : t.Ref(job)
    })

    const app = new Elysia()
    .model({ job, person })
    .get('/', () => ({
      name : 'sucrose',
      job: { name: 'alchemist' }
    }), {
      response : person
    })

    const res = await app.handle(req('/'))
    expect(res.status).toBe(200)
  })

@aberigle
Copy link
Author

Hi @SaltyAom, sorry to tag you 😅 , but any thoughts on this?

src/utils.ts Outdated
Comment on lines 719 to 721
if (Array.isArray(value)) value = Value.Clean(schema, value)
else value = Value.Clean(schema, value)
if (Array.isArray(value)) value = Value.Clean(schema, references || [], value)
else value = Value.Clean(schema, references || [], value)
Copy link
Contributor

Choose a reason for hiding this comment

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

Would suggest adhering to @SaltyAom's convention of using tabs for indentation 🙂

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.

2 participants