Skip to content

Commit

Permalink
fix: openapi client gen chokes on nullable string types
Browse files Browse the repository at this point in the history
  • Loading branch information
zone117x committed Nov 20, 2020
1 parent aac121d commit d59c55b
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 42 deletions.
50 changes: 37 additions & 13 deletions client/src/generated/models/AddressBalanceResponseStx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,55 @@ export interface AddressBalanceResponseStx {
* @type {string}
* @memberof AddressBalanceResponseStx
*/
locked: string;
total_sent: string;
/**
*
* @type {number}
* @type {string}
* @memberof AddressBalanceResponseStx
*/
unlock_height: number;
total_received: string;
/**
*
* @type {string}
* @memberof AddressBalanceResponseStx
*/
total_sent: string;
total_fees_sent: string;
/**
*
* @type {string}
* @memberof AddressBalanceResponseStx
*/
total_received: string;
total_miner_rewards_received: string;
/**
*
* The transaction where the lock event occurred. Empty if no tokens are locked.
* @type {string}
* @memberof AddressBalanceResponseStx
*/
total_fees_sent: string;
lock_tx_id: string;
/**
*
* The amount of locked STX, as string quoted micro-STX. Zero if no tokens are locked.
* @type {string}
* @memberof AddressBalanceResponseStx
*/
total_miner_rewards_received: string;
locked: string;
/**
* The STX chain block height of when the lock event occurred. Zero if no tokens are locked.
* @type {number}
* @memberof AddressBalanceResponseStx
*/
lock_height: number;
/**
* The burnchain block height of when the lock event occurred. Zero if no tokens are locked.
* @type {number}
* @memberof AddressBalanceResponseStx
*/
burnchain_lock_height: number;
/**
* The burnchain block height of when the tokens unlock. Zero if no tokens are locked.
* @type {number}
* @memberof AddressBalanceResponseStx
*/
burnchain_unlock_height: number;
}

export function AddressBalanceResponseStxFromJSON(json: any): AddressBalanceResponseStx {
Expand All @@ -74,12 +92,15 @@ export function AddressBalanceResponseStxFromJSONTyped(json: any, ignoreDiscrimi
return {

'balance': json['balance'],
'locked': json['locked'],
'unlock_height': json['unlock_height'],
'total_sent': json['total_sent'],
'total_received': json['total_received'],
'total_fees_sent': json['total_fees_sent'],
'total_miner_rewards_received': json['total_miner_rewards_received'],
'lock_tx_id': json['lock_tx_id'],
'locked': json['locked'],
'lock_height': json['lock_height'],
'burnchain_lock_height': json['burnchain_lock_height'],
'burnchain_unlock_height': json['burnchain_unlock_height'],
};
}

Expand All @@ -93,12 +114,15 @@ export function AddressBalanceResponseStxToJSON(value?: AddressBalanceResponseSt
return {

'balance': value.balance,
'locked': value.locked,
'unlock_height': value.unlock_height,
'total_sent': value.total_sent,
'total_received': value.total_received,
'total_fees_sent': value.total_fees_sent,
'total_miner_rewards_received': value.total_miner_rewards_received,
'lock_tx_id': value.lock_tx_id,
'locked': value.locked,
'lock_height': value.lock_height,
'burnchain_lock_height': value.burnchain_lock_height,
'burnchain_unlock_height': value.burnchain_unlock_height,
};
}

Expand Down
50 changes: 37 additions & 13 deletions client/src/generated/models/AddressStxBalanceResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,55 @@ export interface AddressStxBalanceResponse {
* @type {string}
* @memberof AddressStxBalanceResponse
*/
locked: string;
total_sent: string;
/**
*
* @type {number}
* @type {string}
* @memberof AddressStxBalanceResponse
*/
unlock_height: number;
total_received: string;
/**
*
* @type {string}
* @memberof AddressStxBalanceResponse
*/
total_sent: string;
total_fees_sent: string;
/**
*
* @type {string}
* @memberof AddressStxBalanceResponse
*/
total_received: string;
total_miner_rewards_received: string;
/**
*
* The transaction where the lock event occurred. Empty if no tokens are locked.
* @type {string}
* @memberof AddressStxBalanceResponse
*/
total_fees_sent: string;
lock_tx_id: string;
/**
*
* The amount of locked STX, as string quoted micro-STX. Zero if no tokens are locked.
* @type {string}
* @memberof AddressStxBalanceResponse
*/
total_miner_rewards_received: string;
locked: string;
/**
* The STX chain block height of when the lock event occurred. Zero if no tokens are locked.
* @type {number}
* @memberof AddressStxBalanceResponse
*/
lock_height: number;
/**
* The burnchain block height of when the lock event occurred. Zero if no tokens are locked.
* @type {number}
* @memberof AddressStxBalanceResponse
*/
burnchain_lock_height: number;
/**
* The burnchain block height of when the tokens unlock. Zero if no tokens are locked.
* @type {number}
* @memberof AddressStxBalanceResponse
*/
burnchain_unlock_height: number;
}

export function AddressStxBalanceResponseFromJSON(json: any): AddressStxBalanceResponse {
Expand All @@ -74,12 +92,15 @@ export function AddressStxBalanceResponseFromJSONTyped(json: any, ignoreDiscrimi
return {

'balance': json['balance'],
'locked': json['locked'],
'unlock_height': json['unlock_height'],
'total_sent': json['total_sent'],
'total_received': json['total_received'],
'total_fees_sent': json['total_fees_sent'],
'total_miner_rewards_received': json['total_miner_rewards_received'],
'lock_tx_id': json['lock_tx_id'],
'locked': json['locked'],
'lock_height': json['lock_height'],
'burnchain_lock_height': json['burnchain_lock_height'],
'burnchain_unlock_height': json['burnchain_unlock_height'],
};
}

Expand All @@ -93,12 +114,15 @@ export function AddressStxBalanceResponseToJSON(value?: AddressStxBalanceRespons
return {

'balance': value.balance,
'locked': value.locked,
'unlock_height': value.unlock_height,
'total_sent': value.total_sent,
'total_received': value.total_received,
'total_fees_sent': value.total_fees_sent,
'total_miner_rewards_received': value.total_miner_rewards_received,
'lock_tx_id': value.lock_tx_id,
'locked': value.locked,
'lock_height': value.lock_height,
'burnchain_lock_height': value.burnchain_lock_height,
'burnchain_unlock_height': value.burnchain_unlock_height,
};
}

Expand Down
17 changes: 14 additions & 3 deletions docs/entities/balance/stx-balance.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@
"description": "StxBalance",
"type": "object",
"additionalProperties": false,
"required": ["balance", "total_sent", "total_received", "total_fees_sent", "total_miner_rewards_received", "lock_tx_id", "locked", "lock_height", "burnchain_lock_height", "burnchain_unlock_height"],
"required": [
"balance",
"total_sent",
"total_received",
"total_fees_sent",
"total_miner_rewards_received",
"lock_tx_id",
"locked",
"lock_height",
"burnchain_lock_height",
"burnchain_unlock_height"
],
"properties": {
"balance": {
"type": "string"
Expand All @@ -21,8 +32,8 @@
"type": "string"
},
"lock_tx_id": {
"type": [ "string", "null" ],
"description": "The transaction where the lock event occurred. Null if no tokens are locked."
"type": "string",
"description": "The transaction where the lock event occurred. Empty if no tokens are locked."
},
"locked": {
"type": "string",
Expand Down
8 changes: 4 additions & 4 deletions docs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export interface AddressBalanceResponse {
total_fees_sent: string;
total_miner_rewards_received: string;
/**
* The transaction where the lock event occurred. Null if no tokens are locked.
* The transaction where the lock event occurred. Empty if no tokens are locked.
*/
lock_tx_id: string | null;
lock_tx_id: string;
/**
* The amount of locked STX, as string quoted micro-STX. Zero if no tokens are locked.
*/
Expand Down Expand Up @@ -86,9 +86,9 @@ export interface AddressStxBalanceResponse {
total_fees_sent: string;
total_miner_rewards_received: string;
/**
* The transaction where the lock event occurred. Null if no tokens are locked.
* The transaction where the lock event occurred. Empty if no tokens are locked.
*/
lock_tx_id: string | null;
lock_tx_id: string;
/**
* The amount of locked STX, as string quoted micro-STX. Zero if no tokens are locked.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/datastore/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export interface DbStxBalance {
totalReceived: bigint;
totalFeesSent: bigint;
totalMinerRewardsReceived: bigint;
lockTxId: string | null;
lockTxId: string;
locked: bigint;
lockHeight: number;
burnchainLockHeight: number;
Expand Down
4 changes: 2 additions & 2 deletions src/datastore/postgres-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2023,7 +2023,7 @@ export class PgDataStore extends (EventEmitter as { new (): DataStoreEventEmitte
`,
[stxAddress, currentBlockHeight, currentBurnBlockHeight]
);
let lockTxId: string | null = null;
let lockTxId: string = '';
let locked: bigint = 0n;
let lockHeight = 0;
let burnchainLockHeight = 0;
Expand Down Expand Up @@ -2126,7 +2126,7 @@ export class PgDataStore extends (EventEmitter as { new (): DataStoreEventEmitte
`,
[stxAddress, blockHeight, burnchainBlockHeight]
);
let lockTxId: string | null = null;
let lockTxId: string = '';
let locked: bigint = 0n;
let lockHeight = 0;
let burnchainLockHeight = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/tests/api-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,7 @@ describe('api tests', () => {
burnchain_lock_height: 0,
burnchain_unlock_height: 0,
lock_height: 0,
lock_tx_id: null,
lock_tx_id: '',
locked: '0',
},
fungible_tokens: {
Expand Down Expand Up @@ -1276,7 +1276,7 @@ describe('api tests', () => {
burnchain_lock_height: 0,
burnchain_unlock_height: 0,
lock_height: 0,
lock_tx_id: null,
lock_tx_id: '',
locked: '0',
},
fungible_tokens: {
Expand Down Expand Up @@ -1304,7 +1304,7 @@ describe('api tests', () => {
burnchain_lock_height: 0,
burnchain_unlock_height: 0,
lock_height: 0,
lock_tx_id: null,
lock_tx_id: '',
locked: '0',
};
expect(JSON.parse(fetchAddrStxBalance1.text)).toEqual(expectedStxResp1);
Expand Down
6 changes: 3 additions & 3 deletions src/tests/datastore-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ describe('postgres datastore', () => {
burnchainLockHeight: 0,
burnchainUnlockHeight: 0,
lockHeight: 0,
lockTxId: null,
lockTxId: '',
locked: 0n,
});
expect(addrCResult).toEqual({
Expand All @@ -232,7 +232,7 @@ describe('postgres datastore', () => {
burnchainLockHeight: 0,
burnchainUnlockHeight: 0,
lockHeight: 0,
lockTxId: null,
lockTxId: '',
locked: 0n,
});
expect(addrDResult).toEqual({
Expand All @@ -244,7 +244,7 @@ describe('postgres datastore', () => {
burnchainLockHeight: 0,
burnchainUnlockHeight: 0,
lockHeight: 0,
lockTxId: null,
lockTxId: '',
locked: 0n,
});
});
Expand Down

0 comments on commit d59c55b

Please sign in to comment.