Closed azakordonets closed 4 years ago
@azakordonets First, I am also testing local lib with yarn link, see this. And then, can you provide your testing repo on github.
Well, that's the problem - i just forked your project and was trying to test it out locally generation - https://github.com/azakordonets/swagger-axios-codegen . It didn't work for me. I created a dummy project - https://github.com/azakordonets/test-axios-codegen and there you can see a result in src/service
folder. Swagger file is taken from your example. in package.json
there's a file reference to https://github.com/azakordonets/swagger-axios-codegen
with no changes. When i run code generation agains local version - i see failed generated file like you can see in demo repo under src/service
. If i generate the same file but with library from npm - everything works fine.
@azakordonets
use yarn build
or yarn watch
on bash.
I already did that. In my local copy of https://github.com/azakordonets/swagger-axios-codegen i did yarn build
and then in the test project https://github.com/azakordonets/test-axios-codegen i did yarn add {path-to-swagger-axios-codegen-repo}
. After that in the https://github.com/azakordonets/test-axios-codegen repo i do next :
test_axios_generator on master [✘!?] is 📦 v1.0.0 via ⬢ v10.0.0 using ☁️ new10-dev at ☸️ minikube took 7s
➜ node -v
v10.0.0
test_axios_generator on master [✘!?] is 📦 v1.0.0 via ⬢ v10.0.0 using ☁️ new10-dev at ☸️ minikube
➜ yarn -v
1.22.4
test_axios_generator on master [✘!?] is 📦 v1.0.0 via ⬢ v10.0.0 using ☁️ new10-dev at ☸️ minikube
➜ node src/index.js
openApi version: 2.0
finish: 237.416ms
test_axios_generator on master [✘!?] is 📦 v1.0.0 via ⬢ v10.0.0 using ☁️ new10-dev at ☸️ minikube
➜ cat service/service.index.ts
function serviceHeader(options, basePath) {
const classTransformerImport = options.useClassTransformer
? `import { Expose, Transform, Type, plainToClass } from 'class-transformer';
`
: '';
return `/** Generate by swagger-axios-codegen */
// tslint:disable
/* eslint-disable */
import axiosStatic, { AxiosInstance } from 'axios';
const basePath = '${utils_1.trimString(basePath, '/', 'right')}'
${classTransformerImport}
export interface IRequestOptions {
headers?: any;
baseURL?: string;
responseType?: string;
}
export interface IRequestConfig {
method?: any;
headers?: any;
url?: any;
data?: any;
params?: any;
}
// Add options interface
export interface ServiceOptions {
axios?: AxiosInstance,
}
${requestHeader()}
`;
}
export interface IList<T> extends Array<T> {}
export interface List<T> extends Array<T> {}
export interface IDictionary<TValue> {
[key: string]: TValue;
}
export interface Dictionary<TValue> extends IDictionary<TValue> {}
export interface IListResult<T> {
items?: T[];
}
export class ListResultDto<T> implements IListResult<T> {
items?: T[];
}
export interface IPagedResult<T> extends IListResult<T> {
totalCount: number;
}
export class PagedResultDto<T> implements IPagedResult<T> {
totalCount!: number;
}
// customer definition
// empty
export class MappersService {
/**
*
*/
updateMapper(
params: {
/** */
mapperId: string;
} = {} as any,
options: IRequestOptions = {}
): Promise<string> {
return new Promise((resolve, reject) => {
let url = '/crawler/v1/mapper/{mapper.id}';
url = url.replace('{mapper.id}', params['mapperId'] + '');
const configs: IRequestConfig = getConfigs('put', 'application/json', url, options);
let data = null;
configs.data = data;
axios(configs, resolve, reject);
});
}
}
export class AuditLogService {
/**
*
*/
getAuditLogs(
params: {
/** */
startDate?: string;
} = {} as any,
options: IRequestOptions = {}
): Promise<IPagedResult<AuditLogListDto>> {
return new Promise((resolve, reject) => {
let url = '/api/services/app/AuditLog/GetAuditLogs';
const configs: IRequestConfig = getConfigs('get', 'application/json', url, options);
configs.params = { StartDate: params['startDate'] };
let data = null;
configs.data = data;
axios(configs, resolve, reject);
});
}
}
export class YmTicketTypicalService {
/**
* 新增或编辑标准票, 需走审批流程
*/
addOrUpdateTicketTypical(options: IRequestOptions = {}): Promise<JsonResult_Guid> {
return new Promise((resolve, reject) => {
let url = '/api/services/app/YmTicketTypical/AddOrUpdateTicketTypical';
const configs: IRequestConfig = getConfigs('post', 'application/json', url, options);
let data = null;
configs.data = data;
axios(configs, resolve, reject);
});
}
}
export class DeviceService {
/**
* 分页上传设备地理坐标信息, 参数list的值为 List<DeviceLngLat>, 返回Result对象
*/
uploadLngLatUsingPost(
params: {
/** */
clientId?: string;
/** 设备地理坐标信息集合 */
list?: List<AuditLogListDto>;
/** */
xToken?: string;
} = {} as any,
options: IRequestOptions = {}
): Promise<any> {
return new Promise((resolve, reject) => {
let url = '/dev/uploadLngLat';
const configs: IRequestConfig = getConfigs('post', 'application/json', url, options);
let data = params['list'];
configs.data = data;
axios(configs, resolve, reject);
});
}
}
export interface Product {
/** Unique identifier representing a specific product for a given latitude & longitude. For example, uberX in San Francisco will have a different product_id than uberX in Los Angeles. */
product_id: string;
/** Description of product. */
description: string;
/** Display name of product. */
display_name: string;
/** Capacity of product. For example, 4 people. */
capacity: string;
/** Image URL representing the product. */
image: string;
}
export interface PriceEstimate {
/** Unique identifier representing a specific product for a given latitude & longitude. For example, uberX in San Francisco will have a different product_id than uberX in Los Angeles */
product_id: string;
/** [ISO 4217](http://en.wikipedia.org/wiki/ISO_4217) currency code. */
currency_code: string;
/** Display name of product. */
display_name: string;
/** Formatted string of estimate in local currency of the start location. Estimate could be a range, a single number (flat rate) or "Metered" for TAXI. */
estimate: string;
/** Lower bound of the estimated price. */
low_estimate: number;
/** Upper bound of the estimated price. */
high_estimate: number;
/** Expected surge multiplier. Surge is active if surge_multiplier is greater than 1. Price estimate already factors in the surge multiplier. */
surge_multiplier: number;
}
export interface Profile {
/** First name of the Uber user. */
first_name: string;
/** Last name of the Uber user. */
last_name: string;
/** Email address of the Uber user */
email: string;
/** Image URL of the Uber user. */
picture: string;
/** Promo code of the Uber user. */
promo_code: string;
/** */
role: RoleType;
}
export interface Activity {
/** Unique identifier for the activity */
uuid: string;
}
export interface Activities {
/** Position in pagination. */
offset: number;
/** Number of items to retrieve (100 max). */
limit: number;
/** Total number of items available. */
count: number;
/** */
history: Activity[];
}
export interface CreateOrUpdateUserInput {
/** 用户ID(ID来自User表) */
userId: number;
/** 用户权限 */
userRights: EnumCreateOrUpdateUserInputUserRights[];
}
export interface Abc {
/** */
id: string;
/** */
isLow: boolean;
}
export interface NumberArrayEnumModel {
/** */
foo: INumberArrayEnumModelFoo[];
/** */
bar: INumberArrayEnumModelBar[];
}
export interface Error {
/** */
code: number;
/** */
message: string;
/** */
fields: string;
}
export interface AuditLogListDto {
/** */
userId: number;
/** */
id: number;
}
export interface JsonResult_Guid {
/** 结果 */
result: boolean;
/** 代码 */
code: EnumJsonResult_GuidCode;
/** 数据 */
data: string;
/** 消息 */
message: string;
}
export enum RoleType {
'Admin' = 'Admin',
'User' = 'User',
'SetSms' = 'SetSms'
}
export enum EnumCreateOrUpdateUserInputUserRights {
'View' = 'View',
'Operate' = 'Operate',
'Auth' = 'Auth',
'Search' = 'Search',
'Delete' = 'Delete',
'UserManage' = 'UserManage',
'UserConfig' = 'UserConfig',
'SetTime' = 'SetTime',
'SetNetwork' = 'SetNetwork',
'SetSms' = 'SetSms',
'SystemManage' = 'SystemManage'
}
type INumberArrayEnumModelFoo = 0 | 1 | 2 | 4 | 8;
type INumberArrayEnumModelBar = 0 | 1 | 2 | 3;
export enum EnumJsonResult_GuidCode {
'Success' = 'Success',
'Timeout' = 'Timeout',
'Fail' = 'Fail',
'Expired' = 'Expired',
'Error' = 'Error',
'InternalServerError' = 'InternalServerError',
'InvalidAnonymousAccess' = 'InvalidAnonymousAccess',
'UserSessionExpired' = 'UserSessionExpired',
'UserIsBinded' = 'UserIsBinded'
}
How do you usually test your local changes of the library ? Do you run code generation in the same project, or you use separate project for this testing ?
A bit more about my setup :
tsc -v
Version 3.9.7
node 10
yarn 1.22.4
@azakordonets Hi, see in https://github.com/Manweill/swagger-axios-codegen/blob/master/CONTRIBUTING.md
Thanks for keeping helping me!. Unfortunately it didn't help me. I even tried to run this in docker :
docker run -it --volume $(pwd):/app sandrokeil/typescript node src/index.js; cat service/service.index.ts
openApi version: 2.0
finish: 291.027ms
function serviceHeader(options, basePath) {
const classTransformerImport = options.useClassTransformer
? `import { Expose, Transform, Type, plainToClass } from 'class-transformer';
`
: '';
return `/** Generate by swagger-axios-codegen */
// tslint:disable
/* eslint-disable */
import axiosStatic, { AxiosInstance } from 'axios';
const basePath = '${utils_1.trimString(basePath, '/', 'right')}'
${classTransformerImport}
export interface IRequestOptions {
headers?: any;
baseURL?: string;
responseType?: string;
}
export interface IRequestConfig {
method?: any;
headers?: any;
url?: any;
data?: any;
params?: any;
}
// Add options interface
export interface ServiceOptions {
axios?: AxiosInstance,
}
${requestHeader()}
`;
}
export interface IList<T> extends Array<T> {}
export interface List<T> extends Array<T> {}
export interface IDictionary<TValue> {
[key: string]: TValue;
}
export interface Dictionary<TValue> extends IDictionary<TValue> {}
.....
The project i'm using is https://github.com/azakordonets/test-axios-codegen . test-swagger-axios-codegen
is local copy (unmodified!) of https://github.com/Manweill/swagger-axios-codegen
i did not get it, what happen with you. If you don't understand the yarn link command, you can see this
if you use npm
then please refer to npm link
command described here: https://stackoverflow.com/a/18778516/1143349
I was linking the swagger-axios-codegen
module to my project locally some time ago to debug some functionality. Everything was working so far.
I tried that all already and something is not right. I have updated my test project - https://github.com/azakordonets/test-axios-codegen . It contains both your library and test project where i try to generate client. This project had Dockerfile which contains clear steps. If you will clone this repo and then will run docker build -t axios-codegen-test .
- you will see at the end code of generated client with a problem. Can you please try clone it and give it a try ? I'm banging my head here and can't figure out what is wrong with my setup.
@Manweill any chance you can spot the problem ?
I don't know much about docker. Can you try it on your local machine instead of using docker.
Well, my initial problem was that locally i do get this error as well. I thought that maybe it's my environment setup, so i created repetitive isolated environment where this problem is 100% reproducible. So, it's not just my local environment, but something else. If you just run the command i have mentioned above - docker build -t axios-codegen-test .
you will see the error i was mentioning. Maybe you can share with me your local setup of yarn, node and other tools you use to build this lib ? So that i could isolate some discrepancies between your and mine environment ?
Sorry, i just realized that https://github.com/azakordonets/test-axios-codegen repo had no code in the folders. Some weird git error from my side. I have pushed things again to the repo.
Ok, i just took another laptop and tried to reproduce without docker :
Can you please confirm that you can reproduce the same steps and outcome on your machine ?
Did you add swagger-axios-codegen
package to your test-axios-codegen
in package.json? I cannot see it. I never played with docker as well. What error exactly you get? I am not sure 100% but when I was linking the local package I wasn't removing it from packages.
@fairking because when you run yarn link "swagger-axios-codegen"
then it creates a simlink in your node_modules
to local package :
ls -la test-axios-codegen/node_modules
total 8
drwxr-xr-x 4 andrew staff 128 Aug 5 10:11 .
drwxr-xr-x 8 andrew staff 256 Aug 5 10:09 ..
-rw-r--r-- 1 andrew staff 237 Aug 5 10:08 .yarn-integrity
lrwxr-xr-x 1 andrew staff 54 Aug 5 10:11 swagger-axios-codegen -> ../../../../../.config/yarn/link/swagger-axios-codegen
Yeah, but I assume the app needs to know threre is a package anyway. But I am using npm, so I am not sure.
@fairking package.json is to specify which packages to download to node_modules. Your code is using package code from node_modules
can you redo without test-axios-codegen repo?
What do you mean @Manweill ? test-axios-codegen repo is the simpliest repo i created to reproduce the problem. I need some repo where i can add local version of swagger-axios-codegen to test my changes to your repo. The problem is that even with no changes into your repo i got this problem while using local version. Can you please provide some steps on how should i redo without test-axios-codegen ?
There may be a problem with previous versions, you can try the latest swagger-axios-codegen source code.
@Manweill i was using master version - it's the latest one, right ? @Manweill , out of curiocity - can you reproduce the issue that i'm mentioning here ? Can you just follow the steps i wrote above and see if you will get the same result? If everything will work just fine on your machine, then it's clearly my setup issue. If you can reproduce this issue, then maybe you can also spot a problem that i'm missing ?
no, it is not the latest.
@Manweill which branch is the latest then ?
Manweill i would love to try the latest version, but i don't know which one is it?
I just saw that you changed something in your library 10 days ago and gave a try with latest master again and the problem seem to disappear. Thanks for updating the library :)
Hi, i'm trying to add a feature to your library that would allow to create multiple instances of the same service with different settings. However, i faced with some weird issues that i cannot figure out and i was hoping that you could help me. Here's a basic setup that doesn't want to work for me :
npm install {local-path-to-your-forked-library}
( i called ittest-swagger-axios-codegen
just to be able to easier to recognize)index.js
file :When i run this file using local version of the library, my service template has this broken part of the code :
export interface IList extends Array {}
export interface List extends Array {}
export interface IDictionary {
}
Am i missing something in my setup ? Tried to run this with node 14 and node 10 - same result.