Skip to content

Commit

Permalink
array types
Browse files Browse the repository at this point in the history
  • Loading branch information
pyramation committed Apr 19, 2024
1 parent c9fac2d commit 7745695
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 68 deletions.
34 changes: 17 additions & 17 deletions __fixtures__/output/contract.camel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface Cw20ReceiveMsg {
export type Decimal = string;
export interface FeeInfo {
devFeePercent: number;
developerAddr?: Addr | any;
developerAddr?: Addr | null;
protocolFeePercent: number;
totalFeeBps: number;
}
Expand Down Expand Up @@ -55,8 +55,8 @@ export interface SingleSwapRequest {
amount: Uint128;
assetIn: AssetInfo;
assetOut: AssetInfo;
beliefPrice?: Decimal | any;
maxSpread?: Decimal | any;
beliefPrice?: Decimal | null;
maxSpread?: Decimal | null;
poolId: Uint128;
swapType: SwapType;
}
Expand All @@ -76,14 +76,14 @@ export type ExecuteMsg = {
receive: Cw20ReceiveMsg;
} | {
updateConfig: {
feeCollector?: any;
generatorAddress?: any;
lpTokenCodeId?: any;
feeCollector?: string | null;
generatorAddress?: string | null;
lpTokenCodeId?: number | null;
};
} | {
updatePoolConfig: {
isDisabled?: any;
newFeeInfo?: FeeInfo | any;
isDisabled?: boolean | null;
newFeeInfo?: FeeInfo | null;
poolType: PoolType;
};
} | {
Expand All @@ -93,23 +93,23 @@ export type ExecuteMsg = {
} | {
createPoolInstance: {
assetInfos: AssetInfo[];
initParams?: Binary | any;
lpTokenName?: any;
lpTokenSymbol?: any;
initParams?: Binary | null;
lpTokenName?: string | null;
lpTokenSymbol?: string | null;
poolType: PoolType;
};
} | {
joinPool: {
assets?: any;
autoStake?: any;
lpToMint?: Uint128 | any;
assets?: Asset[] | null;
autoStake?: boolean | null;
lpToMint?: Uint128 | null;
poolId: Uint128;
recipient?: any;
slippageTolerance?: Decimal | any;
recipient?: string | null;
slippageTolerance?: Decimal | null;
};
} | {
swap: {
recipient?: any;
recipient?: string | null;
swapRequest: SingleSwapRequest;
};
} | {
Expand Down
34 changes: 17 additions & 17 deletions __fixtures__/output/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface Cw20ReceiveMsg {
export type Decimal = string;
export interface FeeInfo {
dev_fee_percent: number;
developer_addr?: Addr | any;
developer_addr?: Addr | null;
protocol_fee_percent: number;
total_fee_bps: number;
}
Expand Down Expand Up @@ -55,8 +55,8 @@ export interface SingleSwapRequest {
amount: Uint128;
asset_in: AssetInfo;
asset_out: AssetInfo;
belief_price?: Decimal | any;
max_spread?: Decimal | any;
belief_price?: Decimal | null;
max_spread?: Decimal | null;
pool_id: Uint128;
swap_type: SwapType;
}
Expand All @@ -76,14 +76,14 @@ export type ExecuteMsg = {
receive: Cw20ReceiveMsg;
} | {
update_config: {
fee_collector?: any;
generator_address?: any;
lp_token_code_id?: any;
fee_collector?: string | null;
generator_address?: string | null;
lp_token_code_id?: number | null;
};
} | {
update_pool_config: {
is_disabled?: any;
new_fee_info?: FeeInfo | any;
is_disabled?: boolean | null;
new_fee_info?: FeeInfo | null;
pool_type: PoolType;
};
} | {
Expand All @@ -93,23 +93,23 @@ export type ExecuteMsg = {
} | {
create_pool_instance: {
asset_infos: AssetInfo[];
init_params?: Binary | any;
lp_token_name?: any;
lp_token_symbol?: any;
init_params?: Binary | null;
lp_token_name?: string | null;
lp_token_symbol?: string | null;
pool_type: PoolType;
};
} | {
join_pool: {
assets?: any;
auto_stake?: any;
lp_to_mint?: Uint128 | any;
assets?: Asset[] | null;
auto_stake?: boolean | null;
lp_to_mint?: Uint128 | null;
pool_id: Uint128;
recipient?: any;
slippage_tolerance?: Decimal | any;
recipient?: string | null;
slippage_tolerance?: Decimal | null;
};
} | {
swap: {
recipient?: any;
recipient?: string | null;
swap_request: SingleSwapRequest;
};
} | {
Expand Down
68 changes: 34 additions & 34 deletions __tests__/__snapshots__/contract.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface Cw20ReceiveMsg {
export type Decimal = string;
export interface FeeInfo {
dev_fee_percent: number;
developer_addr?: Addr | any;
developer_addr?: Addr | null;
protocol_fee_percent: number;
total_fee_bps: number;
}
Expand Down Expand Up @@ -58,8 +58,8 @@ export interface SingleSwapRequest {
amount: Uint128;
asset_in: AssetInfo;
asset_out: AssetInfo;
belief_price?: Decimal | any;
max_spread?: Decimal | any;
belief_price?: Decimal | null;
max_spread?: Decimal | null;
pool_id: Uint128;
swap_type: SwapType;
}
Expand All @@ -79,14 +79,14 @@ export type ExecuteMsg = {
receive: Cw20ReceiveMsg;
} | {
update_config: {
fee_collector?: any;
generator_address?: any;
lp_token_code_id?: any;
fee_collector?: string | null;
generator_address?: string | null;
lp_token_code_id?: number | null;
};
} | {
update_pool_config: {
is_disabled?: any;
new_fee_info?: FeeInfo | any;
is_disabled?: boolean | null;
new_fee_info?: FeeInfo | null;
pool_type: PoolType;
};
} | {
Expand All @@ -96,23 +96,23 @@ export type ExecuteMsg = {
} | {
create_pool_instance: {
asset_infos: AssetInfo[];
init_params?: Binary | any;
lp_token_name?: any;
lp_token_symbol?: any;
init_params?: Binary | null;
lp_token_name?: string | null;
lp_token_symbol?: string | null;
pool_type: PoolType;
};
} | {
join_pool: {
assets?: any;
auto_stake?: any;
lp_to_mint?: Uint128 | any;
assets?: Asset[] | null;
auto_stake?: boolean | null;
lp_to_mint?: Uint128 | null;
pool_id: Uint128;
recipient?: any;
slippage_tolerance?: Decimal | any;
recipient?: string | null;
slippage_tolerance?: Decimal | null;
};
} | {
swap: {
recipient?: any;
recipient?: string | null;
swap_request: SingleSwapRequest;
};
} | {
Expand Down Expand Up @@ -155,7 +155,7 @@ export interface Cw20ReceiveMsg {
export type Decimal = string;
export interface FeeInfo {
devFeePercent: number;
developerAddr?: Addr | any;
developerAddr?: Addr | null;
protocolFeePercent: number;
totalFeeBps: number;
}
Expand Down Expand Up @@ -189,8 +189,8 @@ export interface SingleSwapRequest {
amount: Uint128;
assetIn: AssetInfo;
assetOut: AssetInfo;
beliefPrice?: Decimal | any;
maxSpread?: Decimal | any;
beliefPrice?: Decimal | null;
maxSpread?: Decimal | null;
poolId: Uint128;
swapType: SwapType;
}
Expand All @@ -210,14 +210,14 @@ export type ExecuteMsg = {
receive: Cw20ReceiveMsg;
} | {
updateConfig: {
feeCollector?: any;
generatorAddress?: any;
lpTokenCodeId?: any;
feeCollector?: string | null;
generatorAddress?: string | null;
lpTokenCodeId?: number | null;
};
} | {
updatePoolConfig: {
isDisabled?: any;
newFeeInfo?: FeeInfo | any;
isDisabled?: boolean | null;
newFeeInfo?: FeeInfo | null;
poolType: PoolType;
};
} | {
Expand All @@ -227,23 +227,23 @@ export type ExecuteMsg = {
} | {
createPoolInstance: {
assetInfos: AssetInfo[];
initParams?: Binary | any;
lpTokenName?: any;
lpTokenSymbol?: any;
initParams?: Binary | null;
lpTokenName?: string | null;
lpTokenSymbol?: string | null;
poolType: PoolType;
};
} | {
joinPool: {
assets?: any;
autoStake?: any;
lpToMint?: Uint128 | any;
assets?: Asset[] | null;
autoStake?: boolean | null;
lpToMint?: Uint128 | null;
poolId: Uint128;
recipient?: any;
slippageTolerance?: Decimal | any;
recipient?: string | null;
slippageTolerance?: Decimal | null;
};
} | {
swap: {
recipient?: any;
recipient?: string | null;
swapRequest: SingleSwapRequest;
};
} | {
Expand Down
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ function getTypeForProp(ctx: SchemaTSContext, prop: JSONSchema, required: string
}

if (prop.type) {
if (Array.isArray(prop.type)) {
const arrayType = prop.type.map(type => getTypeForProp(ctx, {type, items: prop.items}, [], schema));
return t.tsUnionType(arrayType);
}

switch (prop.type) {
case 'string':
return t.tsStringKeyword();
Expand All @@ -158,6 +163,8 @@ function getTypeForProp(ctx: SchemaTSContext, prop: JSONSchema, required: string
return t.tsNumberKeyword();
case 'boolean':
return t.tsBooleanKeyword();
case 'null':
return t.tsNullKeyword();
case 'array':
if (prop.items) {
return t.tsArrayType(getTypeForProp(ctx, prop.items, required, schema));
Expand Down

0 comments on commit 7745695

Please sign in to comment.