Skip to content

Commit

Permalink
Support overriding constructor parameter ordering
Browse files Browse the repository at this point in the history
This functionality is necessary to ensure that code generation does not break any existing dependencies
  • Loading branch information
jdtzmn committed Mar 26, 2021
1 parent f86a70d commit c0c2b8c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/client/v2/algod/models/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,17 +502,17 @@ export class Asset extends BaseModel {
export class ApplicationStateSchema extends BaseModel {
/**
* Creates a new `ApplicationStateSchema` object.
* @param numByteSlice \[nbs\] num of byte slices.
* @param numUint \[nui\] num of uints.
* @param numByteSlice \[nbs\] num of byte slices.
*/
constructor(public numByteSlice: number, public numUint: number) {
constructor(public numUint: number, public numByteSlice: number) {
super();
this.numByteSlice = numByteSlice;
this.numUint = numUint;
this.numByteSlice = numByteSlice;

this.attribute_map = {
numByteSlice: 'num-byte-slice',
numUint: 'num-uint',
numByteSlice: 'num-byte-slice',
};
}
}
Expand Down Expand Up @@ -579,28 +579,28 @@ export class ApplicationLocalState extends BaseModel {
export class DryrunSource extends BaseModel {
/**
* Creates a new `DryrunSource` object.
* @param appIndex
* @param fieldName FieldName is what kind of sources this is. If lsig then it goes into the transactions[this.TxnIndex].LogicSig. If approv or clearp it goes into the Approval Program or Clear State Program of application[this.AppIndex].
* @param source
* @param txnIndex
* @param appIndex
*/
constructor(
public appIndex: number,
public fieldName: string,
public source: string,
public txnIndex: number
public txnIndex: number,
public appIndex: number
) {
super();
this.appIndex = appIndex;
this.fieldName = fieldName;
this.source = source;
this.txnIndex = txnIndex;
this.appIndex = appIndex;

this.attribute_map = {
appIndex: 'app-index',
fieldName: 'field-name',
source: 'source',
txnIndex: 'txn-index',
appIndex: 'app-index',
};
}
}
Expand Down Expand Up @@ -1182,19 +1182,19 @@ export class SupplyResponse extends BaseModel {
export class TealValue extends BaseModel {
/**
* Creates a new `TealValue` object.
* @param bytes \[tb\] bytes value.
* @param type \[tt\] value type.
* @param bytes \[tb\] bytes value.
* @param uint \[ui\] uint value.
*/
constructor(public bytes: string, public type: number, public uint: number) {
constructor(public type: number, public bytes: string, public uint: number) {
super();
this.bytes = bytes;
this.type = type;
this.bytes = bytes;
this.uint = uint;

this.attribute_map = {
bytes: 'bytes',
type: 'type',
bytes: 'bytes',
uint: 'uint',
};
}
Expand Down
8 changes: 8 additions & 0 deletions templates/model.vm
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ $unknown.type ## force a template failure with an unknown type
#set( $new = "
" )
#set( $object_gt = $propFile.use_object_params_if_greater_than )
#set( $reorder = $propFile.override_order_of_structs.split(",") )
#set( $Integer = 0 )
/**
* NOTICE: This file was generated. Editing this file manually is not recommended.
Expand All @@ -64,6 +65,13 @@ import BlockHeader from '../../../../types/blockHeader';
#foreach( $modelEntry in $models.entrySet() )
#set( $def = $modelEntry.key )
#set( $props = $def.propertiesSortedByRequired )
#if ( $reorder.contains($def.name) )
#set( $d = "$" )
#set( $override_variable_name = "${d}propFile.override_${def.name}_order" )
#set( $preferred_order_str = "#evaluate($override_variable_name)" )
#set( $preferred_order = $preferred_order_str.split(",") )
#set( $props = $order.propertiesWithOrdering($props, $preferred_order) )
#end
#set( $use_object_params = $props.size() > $Integer.parseInt($object_gt) )
#if ($def.doc)
/**
Expand Down
15 changes: 15 additions & 0 deletions templates/parameter_order_overrides.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Comma separated list of structs for which the order should be overriden
override_order_of_structs = DryrunSource,Application,ApplicationStateSchema,ApplicationLocalStates, \
ApplicationLocalState,TealKeyValue,TealValue,AssetHolding,Asset


# List of the new order for each respective override listed above
override_DryrunSource_order = field-name,source,txn-index,app-index
override_Application_order = id,params
override_ApplicationStateSchema_order = num-uint,num-byte-slice
override_ApplicationLocalStates_order = id,state
override_ApplicationLocalState_order = schema,key-value
override_TealKeyValue_order = key,value
override_TealValue_order = type,bytes,uint
override_AssetHolding_order = amount,asset-id,creator,is-frozen
override_Asset_order = index,params

0 comments on commit c0c2b8c

Please sign in to comment.