GithubHelp home page GithubHelp logo

Comments (2)

DamienDeSousa avatar DamienDeSousa commented on September 25, 2024 1

Thank you for your answer !

I found the problem.

It was because I used Type.Required() in my schema.
Even if myAttr was set to optional, the Required set it to required in the json schema.

OK computer science is still computer science !

Ty for your time !

from typebox.

sinclairzx81 avatar sinclairzx81 commented on September 25, 2024

@DamienDeSousa Hi,

It might be helpful to provide a code example here. But just a couple of things to provision with:

  1. You SHOULD always set strict: true inside tsconfig.json (this is a TypeBox requirement)
  2. You SHOULD NOT use Type.Strict() (as this is a utility function that wouldn't contribute to this error)

So just make sure your project is setup with the above...


So, I'm not sure where the Technical error : Error: \"myAttr\" is required! would originate. It's not an error generated by TypeBox and it doesn't read like an error generated from Fastify. However, your code should be setup similar to the following.

TypeScript Link Here

import { Type, Static } from '@sinclair/typebox'
import Fastify from 'fastify'

const app = Fastify()

type Response200 = Static<typeof Response200>
const Response200 = Type.Object({
  myAttr: Type.Optional(Type.Object({
    x: Type.Number(),
    y: Type.Number(),
    z: Type.Number()
  }))
})

app.get<{ Reply: Response200 }>('/', {
  schema: {
    response: {
      200: Response200
    }
  }
}, (req, reply) => {
  reply.send({ myAttr: { x: 1, y: 2, z: 3 } })
})

This would be a standard TypeBox/Fastify setup. If you can test / compare the above code the code running your side, this might help provide a basis to resolve the issue. Alternatively, if you can provide me a reproduction of the issue you see (code + full TypeBox type), I may be able to offer additional assistance.

Let me know how you go
S

from typebox.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.