Skip to content

Commit 14d3f60

Browse files
author
Grégory Saive
authored
Merge pull request #173 from rg911/task/g96_merge_swagger_generated_classes
5 - Issue #96 Merged swagger generated classes
2 parents e037fb6 + b6edf2d commit 14d3f60

File tree

101 files changed

+8074
-918
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+8074
-918
lines changed

README.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,101 @@ Important versions listed below. Refer to the [Changelog](CHANGELOG.md) for a fu
7878
- [0.10.1-beta](CHANGELOG.md#v0101-beta) - **Alpaca compatible** 07.2018
7979
- [0.9.5](CHANGELOG.md#095-27-Jun-2018) - **Alpaca compatible** 07.2018
8080

81+
## Notes on generation of catapult-rest DTO and API client
82+
83+
Following command can be used to generate DTOs and Api clients for the [nem2-sdk-typescript-javascript](https://github.com/nemtech/nem2-sdk-typescript-javascript) :
84+
85+
1. Download latest NEM2 swagger definition
86+
```bash
87+
$ git clone git@github.com:nemtech/nem2-docs
88+
$ cd nem2-docs && mkdir sdks && cd sdks
89+
$ cp ../source/resources/collections/swagger.yaml .
90+
```
91+
2. Copy OpenAPI generator template
92+
93+
Copy the `templates` folder from {nem2-sdk-typescript-javascript}/infrastructure/ into `sdk` folder
94+
95+
3. Download OpenAPI generator and generate codes
96+
```bash
97+
$ brew install openapi-generator
98+
$ openapi-generator generate -i ./swagger2.yaml -g typescript-node -t templates/ -o ./nem2-ts-sdk/ && rm -R nem2-ts-sdk/test
99+
```
100+
** Note openapi-generator is also available on docker. (`https://hub.docker.com/r/openapitools/openapi-generator`)
101+
4. Fix enum type definitions
102+
103+
As the generator doesn't recognize `enum` type alias, we need to manually move enum classes in to the `enumsMap` list.
104+
- Open generated file `./nem2-ts-sdk/model/models.ts` in editor
105+
- Search for line contains `let enumsMap: {[index: string]: any}`.
106+
- Move all `xxxTypeEnum` entries from below `typeMap` into `enumsMap`.
107+
108+
example below:
109+
```js
110+
let enumsMap: {[index: string]: any} = {
111+
"AccountPropertyTypeEnum": AccountPropertyTypeEnum,
112+
"AliasTypeEnum": AliasTypeEnum,
113+
"ResolutionStatementDTO": ResolutionStatementDTO,
114+
"MosaicPropertyIdEnum": MosaicPropertyIdEnum,
115+
"MultisigModificationTypeEnum": MultisigModificationTypeEnum,
116+
"NamespaceTypeEnum": NamespaceTypeEnum,
117+
"ReceiptTypeEnum": ReceiptTypeEnum,
118+
"RolesTypeEnum": RolesTypeEnum,
119+
}
120+
121+
let typeMap: {[index: string]: any} = {
122+
"AccountDTO": AccountDTO,
123+
"AccountIds": AccountIds,
124+
"AccountInfoDTO": AccountInfoDTO,
125+
"AccountMetaDTO": AccountMetaDTO,
126+
"AccountNamesDTO": AccountNamesDTO,
127+
"AccountPropertiesDTO": AccountPropertiesDTO,
128+
"AccountPropertiesInfoDTO": AccountPropertiesInfoDTO,
129+
"AccountPropertyDTO": AccountPropertyDTO,
130+
"AliasDTO": AliasDTO,
131+
"AnnounceTransactionInfoDTO": AnnounceTransactionInfoDTO,
132+
"BlockDTO": BlockDTO,
133+
"BlockInfoDTO": BlockInfoDTO,
134+
"BlockMetaDTO": BlockMetaDTO,
135+
"BlockchainScoreDTO": BlockchainScoreDTO,
136+
"CommunicationTimestamps": CommunicationTimestamps,
137+
"Cosignature": Cosignature,
138+
"HeightInfoDTO": HeightInfoDTO,
139+
"MerklePathItem": MerklePathItem,
140+
"MerkleProofInfo": MerkleProofInfo,
141+
"MerkleProofInfoDTO": MerkleProofInfoDTO,
142+
"MosaicDTO": MosaicDTO,
143+
"MosaicDefinitionDTO": MosaicDefinitionDTO,
144+
"MosaicIds": MosaicIds,
145+
"MosaicInfoDTO": MosaicInfoDTO,
146+
"MosaicMetaDTO": MosaicMetaDTO,
147+
"MosaicNamesDTO": MosaicNamesDTO,
148+
"MosaicPropertyDTO": MosaicPropertyDTO,
149+
"MultisigAccountGraphInfoDTO": MultisigAccountGraphInfoDTO,
150+
"MultisigAccountInfoDTO": MultisigAccountInfoDTO,
151+
"MultisigDTO": MultisigDTO,
152+
"NamespaceDTO": NamespaceDTO,
153+
"NamespaceIds": NamespaceIds,
154+
"NamespaceInfoDTO": NamespaceInfoDTO,
155+
"NamespaceMetaDTO": NamespaceMetaDTO,
156+
"NamespaceNameDTO": NamespaceNameDTO,
157+
"NetworkTypeDTO": NetworkTypeDTO,
158+
"NodeInfoDTO": NodeInfoDTO,
159+
"NodeTimeDTO": NodeTimeDTO,
160+
"ResolutionEntryDTO": ResolutionEntryDTO,
161+
"ServerDTO": ServerDTO,
162+
"ServerInfoDTO": ServerInfoDTO,
163+
"SourceDTO": SourceDTO,
164+
"StatementsDTO": StatementsDTO,
165+
"StorageInfoDTO": StorageInfoDTO,
166+
"TransactionHashes": TransactionHashes,
167+
"TransactionIds": TransactionIds,
168+
"TransactionInfoDTO": TransactionInfoDTO,
169+
"TransactionMetaDTO": TransactionMetaDTO,
170+
"TransactionPayload": TransactionPayload,
171+
"TransactionStatementDTO": TransactionStatementDTO,
172+
"TransactionStatusDTO": TransactionStatusDTO,
173+
}
174+
```
175+
81176
## License
82177
83178
Copyright (c) 2018-2019 NEM

e2e/infrastructure/AccountHttp.spec.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -444,37 +444,6 @@ describe('AccountHttp', () => {
444444
});
445445
});
446446

447-
describe('Remove test AddressAlias', () => {
448-
let listener: Listener;
449-
before (() => {
450-
listener = new Listener(config.apiUrl);
451-
return listener.open();
452-
});
453-
after(() => {
454-
return listener.close();
455-
});
456-
457-
it('Announce addressAliasTransaction', (done) => {
458-
const addressAliasTransaction = AddressAliasTransaction.create(
459-
Deadline.create(),
460-
AliasActionType.Unlink,
461-
namespaceId,
462-
account.address,
463-
NetworkType.MIJIN_TEST,
464-
);
465-
const signedTransaction = addressAliasTransaction.signWith(account, generationHash);
466-
467-
listener.confirmed(account.address).subscribe(() => {
468-
done();
469-
});
470-
listener.status(account.address).subscribe((error) => {
471-
console.log('Error:', error);
472-
assert(false);
473-
done();
474-
});
475-
transactionHttp.announce(signedTransaction);
476-
});
477-
});
478447
describe('Restore test multisig Accounts', () => {
479448
let listener: Listener;
480449
before (() => {

e2e/infrastructure/MosaicHttp.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ describe('MosaicHttp', () => {
7070
it('Announce MosaicDefinitionTransaction', (done) => {
7171
const nonce = MosaicNonce.createRandom();
7272
mosaicId = MosaicId.createFromNonce(nonce, account.publicAccount);
73-
console.log(mosaicId.toHex());
7473
const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create(
7574
Deadline.create(),
7675
nonce,

e2e/infrastructure/TransactionHttp.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,8 +1704,8 @@ describe('TransactionHttp', () => {
17041704
transactionHttp.getTransactionStatus(transactionHash)
17051705
.subscribe((transactionStatus) => {
17061706
expect(transactionStatus.group).to.be.equal('confirmed');
1707-
expect(transactionStatus.height.lower).to.be.greaterThan(0);
1708-
expect(transactionStatus.height.higher).to.be.equal(0);
1707+
expect(transactionStatus.height!.lower).to.be.greaterThan(0);
1708+
expect(transactionStatus.height!.higher).to.be.equal(0);
17091709
done();
17101710
});
17111711
});
@@ -1716,8 +1716,8 @@ describe('TransactionHttp', () => {
17161716
transactionHttp.getTransactionsStatuses([transactionHash])
17171717
.subscribe((transactionStatuses) => {
17181718
expect(transactionStatuses[0].group).to.be.equal('confirmed');
1719-
expect(transactionStatuses[0].height.lower).to.be.greaterThan(0);
1720-
expect(transactionStatuses[0].height.higher).to.be.equal(0);
1719+
expect(transactionStatuses[0].height!.lower).to.be.greaterThan(0);
1720+
expect(transactionStatuses[0].height!.higher).to.be.equal(0);
17211721
done();
17221722
});
17231723
});

0 commit comments

Comments
 (0)