openapi-ts icon indicating copy to clipboard operation
openapi-ts copied to clipboard

How to generate interfaces instead of types

Open Carseason opened this issue 9 months ago • 8 comments

Description

Sorry, I can't find the configuration option.

export type DeviceEntry = {
}

I want the generated interface to be

export interface DeviceEntry = {
}

Carseason avatar Apr 25 '25 00:04 Carseason

Because it's not a feature! @Carseason what's prompting this request?

mrlubos avatar Apr 25 '25 00:04 mrlubos

I need to use declare modul when extending attributes

Carseason avatar Apr 25 '25 18:04 Carseason

Can you illustrate how this would help?

mrlubos avatar Apr 25 '25 18:04 mrlubos

Sorry my English is not very good, If it is an interface, I can easily add more properties to the model.

export declare module '~/generated/types' {
    interface DeviceEntry  {
        isMonopo?: boolean
    };
}

Carseason avatar Apr 25 '25 19:04 Carseason

中文也可以

Why are you looking to extend types? Why don't they have those properties you want to manually add?

mrlubos avatar Apr 25 '25 21:04 mrlubos

后端发布的文档,前端业务需要自定义一些字段参数

Carseason avatar Apr 26 '25 19:04 Carseason

Why can't backend make that change? I'm just gathering context for this feature so the more you can explain, the better I understand it

mrlubos avatar Apr 26 '25 20:04 mrlubos

  1. 因为后端增删字段需要发布新的版本,前端业务不一定有时间等待,后端也不一定愿意
  2. interface 实现可以增加一些自定义方法来使用
export interface DeviceEntry  {
    isLocal?:()=>boolean
}

3.在不修改swagger的情况下,typescript提供的 declare module 能很好的扩展的

Carseason avatar Apr 26 '25 21:04 Carseason