Giter Site home page Giter Site logo

Comments (14)

paambaati avatar paambaati commented on July 20, 2024 1

This is with asClass: true?

@mrlubos Correct.

import { defineConfig } from '@hey-api/openapi-ts';
import { config } from './package.json';

export default defineConfig({
  input: config.neonOpenApiSpec,
  output: './generated/',
  client: 'fetch',
  services: {
    asClass: true,
  }
});

from openapi-ts.

paambaati avatar paambaati commented on July 20, 2024 1

@mrlubos In my case, the main class (Test in your Stackblitz example) is not being generated!

Please look at paambaati/neon-js-sdk@e709690 (#63) – I've hardcoded some example code to show that the expected NeonClient is missing!

from openapi-ts.

mrlubos avatar mrlubos commented on July 20, 2024 1

@paambaati there might be some confusion around the usage. 0.46.0 should not be introducing any breaking changes to your existing workflow, as long as you define asClass: true (which you did). You still need to define name: 'NeonClient' in your config to generate a client instance. Without it, there will be no custom class, that's why it's not generated.

The longer term recommended solution is to stop relying on the name config option as it's deprecated. Omitting it will not generate a separate NeonClient.ts file as you already know. Depending on how you're using this package, this may or may not matter, but you will likely need to change code in other places where you'd have previously used the client instance. For that, I think we could move this into discussions to see what needs to get updated, what (if anything) breaks, and anything else preventing you from retiring the usage of name. Does that make sense?

tl;dr add name: 'NeonClient' to your config and things should continue working as before

from openapi-ts.

paambaati avatar paambaati commented on July 20, 2024 1

@mrlubos Thanks, using name fixes the issue. I had recently started skipping it because the TSDoc said it was deprecated.

I will create a discussion so we can figure out a future migration path without the use of name.

from openapi-ts.

paambaati avatar paambaati commented on July 20, 2024 1

Related discussion here – #619

from openapi-ts.

paambaati avatar paambaati commented on July 20, 2024

Can confirm that the behaviour is still broken in other ways when services.asClass is set to true.

from openapi-ts.

mrlubos avatar mrlubos commented on July 20, 2024

Thanks! Looks like the import should be changed to wildcard? Can you describe what issues you're seeing if you set asClass to true?

from openapi-ts.

mrlubos avatar mrlubos commented on July 20, 2024

@paambaati I looked into adding tree-shakeable services for custom clients, it's not a quick fix, so my suggestion would be to use services.asClass: true to preserve the old behaviour. You said there are other issues, I can look at that once you provide more details. Generating a test client from sample script didn't produce any errors so I will need your assistance.

from openapi-ts.

paambaati avatar paambaati commented on July 20, 2024

@mrlubos Thanks for looking at this. With services.asClass: true, I notice 1 problem –

  1. There is no way for me to declare the API token in any of the class methods when using the fetch client.

Everything else does seem to work, albeit with code changes. This is a breaking change and I was surprised this landed in a minor release.

from openapi-ts.

mrlubos avatar mrlubos commented on July 20, 2024

@paambaati Can you point me to what's missing? To be clear, you're talking about the generated Fetch API client, not the new one, right?

Minor releases are actually breaking quite often if you look at the migrating docs. Until we reach v1, that's how it's going to be. Also note that --name is deprecated and will be removed prior to v1, so I'd like to understand what's missing in order for you to migrate. However, it should've continued to work as before if you simply upgraded to v0.46.0 and set asClass to true. I'd like to fix that if you can point out the difference

from openapi-ts.

paambaati avatar paambaati commented on July 20, 2024

@mrlubos Yes, this is using the native fetch client.

Here's an example –

With openapi-typescript-codegen, I could have generated code like this –

const neonClient = new NeonClient({
    TOKEN: '<INSERT NEON API KEY HERE>',
});

const projects = await neonClient.project.listProjects();
console.log(projects);

However, with the latest set of changes in @hey-api/openapi-ts, this code has to be written as –

import * as NeonClient from './services.gen'
const response = await NeonClient.ProjectService.listProjects();
console.log(projects);

There's no clear way to define the token authorization header.

from openapi-ts.

mrlubos avatar mrlubos commented on July 20, 2024

@paambaati This is with asClass: true?

from openapi-ts.

mrlubos avatar mrlubos commented on July 20, 2024

@paambaati I tried reproducing this and was unable to, see https://stackblitz.com/edit/hey-api-client-fetch-example-6uxsro?file=src%2FApp.tsx, both 0.45.0 and 0.46.0 appear to work the same way. Feel free to reopen if I am missing something

from openapi-ts.

mrlubos avatar mrlubos commented on July 20, 2024

Yeah totally feel free to keep using it for now, I'm just not supporting it for new features since I know it will be going away. Same with the other deprecated parameters

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.