Giter Site home page Giter Site logo

No types for generate about openapi-ts HOT 4 CLOSED

hey-api avatar hey-api commented on May 24, 2024
No types for generate

from openapi-ts.

Comments (4)

mrlubos avatar mrlubos commented on May 24, 2024 1

@Birkbjo this is fixed in v0.27.33 🎉

I added a section on programmatic setup to README – https://github.com/nicolas-chaulet/openapi-typescript-codegen?tab=readme-ov-file#installation

Here's how I use it

import { createClient } from '@nicolas-chaulet/openapi-typescript-codegen'

const client = await createClient()

You can pass config to createClient(), but it also tries to read config from a file so it's optional.

I need to do some quite specific transformations of the resulting types, like resolve refs (I see that this now includes this, but I dont think it will work for me because the schema im working doesn't directly reference the component...), and some renames etc

We can discuss this more if you want, I think there's some potential to unlock. I am now returning client from createClient() as opposed to not returning anything previously. I don't recommend using it as that's an internal API, but it's a good start as now you can have access to the same information openapi-ts has when generating your client. In theory, you could even run const client = await createClient({ write: false }) to skip writing any files and re-implement the write operation yourself!

from openapi-ts.

mrlubos avatar mrlubos commented on May 24, 2024

@Birkbjo oh yes, you're correct, I changed that. Before I add the types back, can I ask why you're generating types programatically?

You're also correct on the ESM modules, are you able to share what kind of error message(s) you're seeing?

from openapi-ts.

mrlubos avatar mrlubos commented on May 24, 2024

@Birkbjo I just tried it and it works for me in a foo.ts file, but I am also using "type": "module" in my package.json

import { generate } from '@nicolas-chaulet/openapi-typescript-codegen'

generate()

I executed it with npx tsx foo.ts. I will fix the missing types, thanks for flagging! Let me know more details about your execution if you need help with that too

from openapi-ts.

Birkbjo avatar Birkbjo commented on May 24, 2024

Thanks for the quick resolution!

I started looking into migrating to txs as well, need to cleanup my tsconfig etc.

As for the use-case - I use the codegen in a wrapper tool that is used to clean the results. I need to do some quite specific transformations of the resulting types, like resolve refs (I see that this now includes this, but I dont think it will work for me because the schema im working doesn't directly reference the component...), and some renames etc. Most of this is because the schema I'm working with isn't really ideal.

I couldve of course ran this in cli, but its quite convenient to just calll generate from node when I already need a script anyways.

My project is here if you're interested https://github.com/Birkbjo/dhis2-open-api-ts

from openapi-ts.

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.