Shaddix / react-query-swagger

Generates react-query hooks based on Swagger API definitions
MIT License
122 stars 4 forks source link

Vue /minimal flag generates broken client #39

Closed realwoopee closed 7 months ago

realwoopee commented 7 months ago

Can be reproduced using pet-client-vue example using react-query-swagger 15.10.4 . Just add /minimal flag in the generate-axios script and run it.

ApiResponse class in axios-client.ts if not using /minimal flag:

export class ApiResponse  {
    code?: number | null;
    type?: string | null;
    message?: string | null;
    constructor(data?: IApiResponse) {
        if (data) {
            for (var property in data) {
                if (data.hasOwnProperty(property))
                    (<any>this)[property] = (<any>data)[property];
            }
        }
    }
    init(_data?: any) {
        if (_data) {
            this.code = _data["code"];
            this.type = _data["type"];
            this.message = _data["message"];
        }
    }
    static fromJS(data: any): ApiResponse {
        data = typeof data === 'object' ? data : {};
        let result = new ApiResponse();
        result.init(data);
        return result;
    }
    toJSON(data?: any) {
        data = typeof data === 'object' ? data : {};
        data["code"] = this.code;
        data["type"] = this.type;
        data["message"] = this.message;
        return data;
    }
}

ApiResponse class in axios-client.types.ts if using /minimal flag:

export class ApiResponse  {
    code?: number | null;
    type?: string | null;
    message?: string | null;
    constructor(data?: IApiResponse) {
        if (data) {
            for (var property in data) {
                if (data.hasOwnProperty(property))
                    (<any>this)[property] = (<any>data)[property];
            }
        }
    }
    init(_data?: any) {
        if (_data) {
            _data.code = _data["code"];
            _data.type = _data["type"];
            _data.message = _data["message"];
        }
    }
    static fromJS(data: any): ApiResponse {
        data = typeof data === 'object' ? data : {};
        let result = new ApiResponse();
        result.init(data);
        return result;
    }
    toJSON(data?: any) {
        data = typeof data === 'object' ? data : {};
        data["code"] = _data.code;
        data["type"] = _data.type;
        data["message"] = _data.message;
        return data;
    }
}

As you can see, init() and toJson() methods are broken

Shaddix commented 7 months ago

Fixed in 15.10.5

realwoopee commented 7 months ago

Now npm run generate-axios-minimal fails using "react-query-swagger": "15.10.6":



> pet-client-vue@0.0.0 generate-axios-minimal
> react-query-swagger /vue /minimal /input:https://petstore.swagger.io/v2/swagger.json /output:src/api/axios-client-minimal.ts /template:Axios /serviceHost:.

node:fs:3025
  binding.copyFile(
          ^

Error: ENOENT: no such file or directory, copyfile 'C:\Users\Woopee\Desktop\pet-client-vue\node_modules\react-query-swagger\templates_minimal_vue\modules\AxiosClient.liquid' -> 'C:\Users\Woopee\Desktop\pet-client-vue\node_modules\react-query-swagger\templates_minimal_vue\_AxiosClient.liquid'
    at copyFileSync (node:fs:3025:11)
    at Object.<anonymous> (C:\Users\Woopee\Desktop\pet-client-vue\node_modules\react-query-swagger\cli.js:138:1)
    at Module._compile (node:internal/modules/cjs/loader:1375:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1434:10)
    at Module.load (node:internal/modules/cjs/loader:1206:32)
    at Module._load (node:internal/modules/cjs/loader:1022:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:142:12)
    at node:internal/main/run_main_module:28:49 {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'copyfile',
  path: 'C:\\Users\\Woopee\\Desktop\\pet-client-vue\\node_modules\\react-query-swagger\\templates_minimal_vue\\modules\\AxiosClient.liquid',
  dest: 'C:\\Users\\Woopee\\Desktop\\pet-client-vue\\node_modules\\react-query-swagger\\templates_minimal_vue\\_AxiosClient.liquid'
}

Node.js v21.5.0
Shaddix commented 7 months ago

Should be better now in 15.10.7 (files were not included in the npm bundle)

realwoopee commented 7 months ago

Works now, thank you!