Giter VIP home page Giter VIP logo

Comments (3)

drwpow avatar drwpow commented on June 7, 2024

That’s correct. A { "type": "object" } has no properties (Record<string, never>), and you didn’t declare additionalProperties explicitly. And the | null is correct. See the docs on this behavior.

openapi-typescript will never generate a any type because that’s basically not typechecking at all. In order to achieve that behavior, you’ll have to either make your OpenAPI schema more explicit (recommended), or override the type with the desired type (i.e. OpenAPI schema didn’t declare a descriptive type, therefore openapi-typescript couldn’t, so I’ll have to override it manually in TypeScript).

from openapi-typescript.

PythonCoderAS avatar PythonCoderAS commented on June 7, 2024

That’s correct. A { "type": "object" } has no properties (Record<string, never>), and you didn’t declare additionalProperties explicitly. And the | null is correct. See the docs on this behavior.

openapi-typescript will never generate a any type because that’s basically not typechecking at all. In order to achieve that behavior, you’ll have to either make your OpenAPI schema more explicit (recommended), or override the type with the desired type (i.e. OpenAPI schema didn’t declare a descriptive type, therefore openapi-typescript couldn’t, so I’ll have to override it manually in TypeScript).

What if it's intended that I can send something with whatever keys and values I want to the backend (for example, it's an extra field that's saved to the DB as a JSON type)? Is there a good way to represent that the type of the record doesn't matter?

from openapi-typescript.

drwpow avatar drwpow commented on June 7, 2024

Yes! That’s additionalProperties. You can give that a type, and be as descriptive as possible. It will let any arbitrary keys return the provided shape.

You can also set additionalProperties: true to generate Record<string, unknown>, but it’s always best to just pass a full Schema Object to additionalProperties ($refs work too)

from openapi-typescript.

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.