Giter Site home page Giter Site logo

Missing types in client gen about openapi-ts HOT 6 CLOSED

Stono avatar Stono commented on May 23, 2024
Missing types in client gen

from openapi-ts.

Comments (6)

Stono avatar Stono commented on May 23, 2024 1

@mrlubos just to maintain a well known name for the client, because our apps then do:

import { swaggerClient } from './swaggerClient'

It doesn't matter if it's called swaggerClient, so long as it's deterministic

from openapi-ts.

Stono avatar Stono commented on May 23, 2024

So looking at the templating:

{{#if @root.useOptions}}
import { mergeOpenApiConfig, OpenAPI } from '../core/OpenAPI';
import { request as __request } from '../core/request';
import type { TApiResponse, TConfig, TResult } from '../core/types';
{{else}}
import { OpenAPI } from '../core/OpenAPI';
import { request as __request } from '../core/request';
{{/if}}

We're using useOptions: true.

from openapi-ts.

mrlubos avatar mrlubos commented on May 23, 2024

@Stono oops, sorry for that. Can you share the full command you're using to generate the client? It seems you're not using exportCore, right?

from openapi-ts.

Stono avatar Stono commented on May 23, 2024

Hey,
I am using exportCore.

What we're doing is a bit interesting btw, we dont use the cli - instead i invoke it programatically:

  const openApi = require('@nicolas-chaulet/openapi-typescript-codegen/dist')
  await openApi.generate({
    input: tmpLocation,
    output: destinationLib,
    httpClient: 'fetch',
    exportCore: true,
    exportServices: true,
    exportModels: true,
    exportSchemas: false,
    postfixServices: '',
    postfixModels: '',
    clientName: 'swaggerClient',
    useOptions: true,
    useUnionTypes: true
  })

Core does look to be exported as i'd expect:

Screenshot 2024-03-04 at 12 11 32

The types just aren't being imported in the generated service

from openapi-ts.

mrlubos avatar mrlubos commented on May 23, 2024

@Stono got it, thanks! I will fix it today if you can give me one more pointer. I see this is because you use clientName, I didn't implement it with that field. Can you explain what's that field used for on your end? Do you implement anything custom?

from openapi-ts.

mrlubos avatar mrlubos commented on May 23, 2024

@Stono this is fixed in v0.27.19 🚀 Thanks for catching it!

I want to ask, however, more about the use of clientName. Personally I don't use it, so it may help me prevent similar mistakes in the future. clientName will generate a file in client/swaggerClient.ts – do you use this module? If so, how? I am still not clear what you get from this flag that you couldn't get by not using it and setting output to src/swaggerClient which would then be used elsewhere as import { Services } from 'swaggerClient'?

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.