Coder Social home page Coder Social logo

symbol / symbol-openapi Goto Github PK

View Code? Open in Web Editor NEW
12.0 21.0 6.0 3.78 MB

OpenAPI specification for catapult-rest

Home Page: https://nemtech.github.io/api.html

License: Apache License 2.0

HTML 39.28% Shell 60.72%
nem symbol api open-api open-api-specification specification swagger rest docs documentation

symbol-openapi's Introduction

symbol-openapi

Build Status

OpenAPI specification for catapult-rest.

Requirements

  • Node.js 12 LTS

Installation

  1. Clone the symbol-openapi repository.
git clone https://github.com/nemtech/symbol-openapi.git
  1. Install swagger-cli globally.
npm install -g @apidevtools/swagger-cli

Commands

Build

Compile the specification. The generated output is saved under _build directory.

npm run build

Test

Check if the specification is valid.

npm run test

Contributing

Before contributing please read this.

License

Copyright (c) 2018-present NEM Licensed under the Apache License 2.0

symbol-openapi's People

Contributors

anthonylaw avatar dgarcia360 avatar fboucquez avatar martinayora avatar rg911 avatar segfaultxavi avatar vektrat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

symbol-openapi's Issues

Document node peers endpoint

Implemented in: symbol/catapult-rest@68b26e6

/node/peers

Example output:

[
    {
        "version": 0,
        "publicKey": "6767654342D851850ADD01F2A739F8D0798976543216A9D704A189AA4565EE3F",
        "networkGenerationHash": "292A26631A2F5D988D726594AD018B2ECCD69F61C8F0060A3284255392169259",
        "roles": 1,
        "port": 7900,
        "networkIdentifier": 152,
        "host": "peer-node-0",
        "friendlyName": "peer-node-0"
    },
    {
        "version": 0,
        "publicKey": "189AA4565EE3F6767654342D851850ADD01F2A739F8D0798976543216A9D704A",
        "networkGenerationHash": "AA45467892F5D988D726594AD018B2ECCD69F61C8F0060A32842555654B45C4A",
        "roles": 1,
        "port": 7900,
        "networkIdentifier": 152,
        "host": "peer-node-1",
        "friendlyName": "peer-node-1"
    }
]

Notice that the output is just an array of nodeInfo items, you may be able to reuse an existing openApi DTO

Error types are missing from the transaction status type enum for 0.9.5.1

New errors were added for the new transaction added in 0.9.5.1. the transaction status type enum needs to be updated. Below is one example.

https://github.com/nemtech/symbol-openapi/blob/2bb345f25def64585050b2209d4f80fa3c7bd267/spec/core/transaction/schemas/TransactionStatusTypeEnum.yml#L1

catapult_server0001.log:2020-05-19 23:38:59.580589 0x00007fc445ffb700: (chain::UtUpdater.cpp@160) dropping transaction 61D3415802FEE63086E95D0260A9B000CB6DA594A15FA65BB535DFD36847649F: Failure_Core_Link_Already_Exists
catapult_server0001.log:2020-05-19 23:38:59.586438 0x00007fc445ffb700: (subscribers::SubscriptionManager.cpp@101) rejected tx 61D3415802FEE63086E95D0260A9B000CB6DA594A15FA65BB535DFD36847649F due to result Failure_Core_Link_Already_Exists (deadline 16508338905)

3 numbers versions

The project https://github.com/NEMStudios/nem2-open-api-generator generates maven and npm packages for the Java and TS SDKs.

The version of the generated artifacts must match the version of the Open API spec. You can tell exactly what version of the open API of the clients are generated from, and by extension, the Open API version the SDKs support.

Maven supports multiple number versions but NPM complains if there are more than 2 dots in a version (if there are just numbers).

The current version of the spec is 0.7.20.6. https://github.com/nemtech/nem2-openapi/blob/master/spec/info.yml#L1

We need to touch the generated NPM package version calling it something different like 0.7.20-beta.6

https://www.npmjs.com/package/nem2-sdk-openapi-typescript-node-client

Could it be possible to use a simple 3 numbers version in the spec like 0.7.21 and update the minor version with every merged change?

CC: @dgarcia360 @rg911

Add "status" to transaction payload

ATM is not trivial to check the status of a transaction by just looking at the payload. The client and SDKs need to assume the value by checking at the metadata to see if there is a height or not (for example) or by knowing if the transaction was loading using a rest endpoint or another (like group: partial)

https://github.com/nemtech/symbol-sdk-typescript-javascript/blob/master/src/model/transaction/Transaction.ts#L300

https://github.com/nemtech/symbol-sdk-typescript-javascript/blob/master/src/model/transaction/Transaction.ts#L314

https://github.com/nemfoundation/symbol-desktop-wallet/blob/master/src/core/transactions/TransactionView.ts#L74

I would like to add a status to the transaction, probably inside the meta payloads like:

meta: {status: partial | confirmed | unconfirmed | error?}

Unsure if it makes sense to add it to embedded transactions too. I guess it does if embedded transactions are loaded as top-level search results.

TransactionState missing 'partial' value

For an aggregate bonded transaction when it first gets submitted, it goes to the pt cache(partial transaction queue) and wait for cosigners to sign the tx. When the transaction is in this queue the state should be partial.e.g. Below is the status of a transaction from rest gateway when in that queue.

{"group":"partial","code":"Success","hash":"F7A99B130CFD5641B71CCABC538CE893164AF84229076541A9C8A47F1BF90677","deadline":"5520432181","height":"0"}

Originally posted by @Wayonb in https://github.com/nemtech/nem2-sdk-java/pull/195

https://github.com/nemtech/nem2-openapi/blob/master/spec/core/transaction/schemas/TransactionStateTypeEnum.yml

Once we have a new version I can add that value to the java enum value.

https://github.com/nemtech/nem2-sdk-java/issues/197

Add metadata endpoints to the schema

WIP in #5

Initial endpoints proposal targeting accounts, should be duplicated per mosaic and namespaces.

  1. GET /account/{accountId}/metadata/
    Returns the complete accountId current state metadata. Ideally with pagination + order.

  2. GET /account/{accountId}/metadata/{key}
    Returns all the account current state metadata for that key. The response should be an array, as multiple signers can add metadata with the same key.

  3. POST /account/{accountId}/metadata
    Returns metadadata for an array of accountIds.

Let's use this issue to discuss changes in those endpoints and discuss if we need more of them.

Metadata valueSize not provided/not needed

Hi @dgarcia360

Open API specifies that the valueSize should be present in Account/Mosaic/Namespace metadata transactions, for example:

https://github.com/nemtech/nem2-openapi/blob/master/spec/openapi3.yaml#L2649

It seems like Rest is not providing the valueSize anymore (@Vektrat ):

image

valueSize is not required by catbuffer but it used to be provided in the rest transaction payloads. Is this valueSize required? Do we need it to calculate the new delta when updating metadata or can we just remove it from the open API spec? @rg911?

[TypeScript generator] undefined accountIds

Originally reported by @rg911

The rest sever only takes one public key or address after calling POST /account/. In our current DTO definition, we have both keys set as optional.

The problem comes after generating the typescript client with openapi-generator. Although we provide only one of the ids, the other key is still in the model showing as undefined which causes the error.

Let's use the issue to discuss possible solutions.

MosaicDefinitionTransaction's nonce is overflowing

Hi guys, the nonce value in the MosaicDefinitinoTransaction is overflowing in Java and it will overflow in other languages

com.fasterxml.jackson.databind.JsonMappingException: Numeric value (3143697214) out of range of int (-2147483648 - 2147483647)
 at [Source: (String)"{"deadline":"16039398229","divisibility":4,"duration":"100","entityBody_Reserved1":0,"flags":7,"id":"13C22C203106ED04","maxFee":"1000000","network":152,"nonce":3143697214,"signature":"ADFAABBEB2C29B0A6665CCE3BB1E575387F43A0D010372415360AAB29C25C91ADCFC93B3C5542BE55630941FDD0D540E5A4B1495F2AA8885A49A8C3C35D68D0B","signerPublicKey":"085ADC6A515307DA80727293C081550FD138B8B97D16CA338F43F2A821555E2A","type":16717,"verifiableEntityHeader_Reserved1":0,"version":1}"; line: 1, column: 161] (through reference chain: io.nem.symbol.sdk.openapi.vertx.model.MosaicDefinitionTransactionDTO["nonce"])

2 possible solutions

  1. Nonce to be changed to numeric string like any other uint64 number
    https://github.com/nemtech/symbol-openapi/blob/master/spec/plugins/mosaic/schemas/MosaicDefinitionTransactionBodyDTO.yml#L14
  2. Rest to return the overflowed negative number as we are really interested in the bytes of the nonce, not in the number itself. I gues this is a secondary effect of bigint in rest not overflowing numbers like it used to?

@Vektrat @dgarcia360 @rg911

Harvest Info

I would like to propose add new endpoint to get harvester infomation.

Reason

  • As supernode owner I believe harvest infomation is important to them.
  • Implement Harvester information on Symbol explorer.

Route
/harvesters
/harvesters/{accountId}

Example HarvesterDTO

address : '9081FCCB41F8C8409A9B99E485E0E28D23BD6304EF7215E01A'
totalHarvestedBlocks :  100
totalHarvestedFees:  2300.000000
lastHarvestedBlock : '23410'

Remark

  • Aggregating data for /harvesters queries may cost inefficient performance for rest endpoint, not sure using pagination will resolved the issue.

feedback are welcome.

Account key link transaction the remotePublicKey property was rename to linkedPublicKey

For account key link transaction, the remotePublicKey property need to get rename to linkedPublicKey. This is causing failures in the SDK.

https://github.com/nemtech/symbol-openapi/blob/51bd06363a972489f3df34ea168fd4df4c54c4c7/spec/plugins/account_link/schemas/AccountKeyLinkTransactionBodyDTO.yml#L6

{"meta":{"height":"333","hash":"86D317C374E4552A27850A3CC5776446903835CFCD75740FBBDBB483AA5EE05C","merkleComponentHash":"86D317C374E4552A27850A3CC5776446903835CFCD75740FBBDBB483AA5EE05C","index":0,"id":"5EC4505DB8551373BD6D227B"},"transaction":{"signature":"837A63D8869F7D3C28983B273A580BC46CD1B4A395954A9DC96FE2F99527CEF756DF463CF695D7B3C1426834F11C69FF8180D8FEF37211577EB8AC124A229004","signerPublicKey":"89589C81C500A65F4019DAD36198230373EBC2C646D3FDD0DDD3D966404559D4","version":1,"network":152,"type":16716,"maxFee":"16100","deadline":"16500718888","linkedPublicKey":"cbJOSD9mbSB8tSpqbYyAw/60wWIFVGji0vtY1LDuzWc=","linkAction":1}}

Caused by: java.lang.IllegalArgumentException: Public key is not valid
at io.nem.symbol.core.crypto.RawAddress.generateAddress(RawAddress.java:56) ~[symbol-sdk-core-0.17.2-20200516.002415-7.jar:?]
at io.nem.symbol.sdk.model.account.Address.createFromPublicKey(Address.java:144) ~[symbol-sdk-core-0.17.2-20200516.002415-7.jar:?]
at io.nem.symbol.sdk.model.account.PublicAccount.(PublicAccount.java:34) ~[symbol-sdk-core-0.17.2-20200516.002415-7.jar:?]
at io.nem.symbol.sdk.model.account.PublicAccount.createFromPublicKey(PublicAccount.java:46) ~[symbol-sdk-core-0.17.2-20200516.002415-7.jar:?]
at io.nem.symbol.sdk.infrastructure.vertx.mappers.AccountKeyLinkTransactionMapper.createFactory(AccountLinkTransactionMapper.java:43) ~[symbol-sdk-vertx-client-0.17.2-20200516.002415-7.jar:?]
at io.nem.symbol.sdk.infrastructure.vertx.mappers.AccountKeyLinkTransactionMapper.createFactory(AccountLinkTransactionMapper.java:32) ~[symbol-sdk-vertx-client-0.17.2-20200516.002415-7.jar:?]
at io.nem.symbol.sdk.infrastructure.vertx.mappers.AbstractTransactionMapper.createModel(AbstractTransactionMapper.java:75) ~[symbol-sdk-vertx-client-0.17.2-20200516.002415-7.jar:?]
at io.nem.symbol.sdk.infrastructure.vertx.mappers.AbstractTransactionMapper.map(AbstractTransactionMapper.java:67) ~[symbol-sdk-vertx-client-0.17.2-20200516.002415-7.jar:?]
at io.nem.symbol.sdk.infrastructure.vertx.mappers.GeneralTransactionMapper.map(GeneralTransactionMapper.java:89) ~[symbol-sdk-vertx-client-0.17.2-20200516.002415-7.jar:?]
at io.nem.symbol.sdk.infrastructure.vertx.TransactionRepositoryVertxImpl.toTransaction(TransactionRepositoryVertxImpl.java:76) ~[symbol-sdk-vertx-client-0.17.2-20200516.002415-7.jar:?]
at io.reactivex.internal.operators.observable.ObservableMap$MapObserver.onNext(ObservableMap.java:59) ~[rxjava-2.1.7.jar:?]
at io.reactivex.internal.operators.observable.ObservableOnErrorNext$OnErrorNextObserver.onNext(ObservableOnErrorNext.java:68) ~[rxjava-2.1.7.jar:?]
at io.reactivex.internal.operators.single.SingleToObservable$SingleToObservableObserver.onSuccess(SingleToObservable.java:59) ~[rxjava-2.1.7.jar:?]
at io.vertx.reactivex.core.impl.AsyncResultSingle.lambda$subscribeActual$0(AsyncResultSingle.java:41) ~[vertx-rx-java2-3.5.0.jar:?]
at io.nem.symbol.sdk.openapi.vertx.invoker.ApiClient.lambda$buildResponseHandler$7(ApiClient.java:599) ~[symbol-openapi-vertx-client-0.8.10.jar:?]
at io.vertx.ext.web.client.impl.HttpContext.lambda$null$0(HttpContext.java:125) ~[vertx-web-client-3.5.0.jar:?]

anyOf keyword should be replaced with oneOf

Several DTO uses the anyOf keyword when they should be using the oneOf keyword. The reason behind this intentional change allows us to generate code that compiles. At the current moment, most openapi-generators do not support code generation with oneOf keyword.

Rules of usage, according to the docs:

  • anyOf: Validates the value against any (one or more) of the subschemas.
  • oneOf: Validates the value against exactly one of the subschemas.

If you want to contribute to this issue, you can coordinate with the openapi-generator community to apply the necessary changes for better support of the OAS3 specific keywords.

NetworkTypeDTO's name attribute should be a Enum.

Hi @dgarcia360

I've revisited one of the endpoints. I want to map the possible string values of http://localhost:3000/network to the NetworkType enums we use.

At the moment, open API doesn't specify those values, just the mijinTest example. Would it possible to add all the examples or even better change the name type to enum? It's hard to tell which are the expected values from other networks.

The workaround is using /node/info endpoint to know easily know the network type.

Rebranding

  • Rebranding branch created
  • New design applied (font, logos, colors)
  • Codename references renamed
  • Ticker references renamed
  • Links reviewed
  • README reviewed
  • Dependencies reviewed
  • PR created
  • Package renamed
  • Package tagged

HaskLockTranscation mosaic object vs mosaicId/Value

Hi @dgarcia360 ,

I'm doing some integration tests and I noticed that the HaskLockTranscation returned by rest doesn't have the format defined in the open API spec. The rest payload doesn't have the nested mosaic object, it just has the mosaicId and the amount. Is this an open API issue or a rest issue? @Vektrat?

I think at this stage is easier to fix the open API than rest and TS SDK (@rg911). Please notice that Java SDK uses the object generated from the open API spec. I would need to patch the open API spec in order to fix the Java SDK.

https://github.com/nemtech/nem2-openapi/blob/master/spec/openapi3.yaml#L2287

image

image

image

Reorganize Metadata Endpoints

One of the reasons for not having separated metadata was due to previous account restrictions endpoint structure.

Taking into consideration similar features that depend on others (restrictions, multisig), we are creating endpoints under each main independent concept (e.g. /account/<:accountId>/restrictons).

#28 changes the /restrictions endpoints and opens the door to reorganize metadata endpoints.

Proposal

The does not change the number of endpoints or responses, but how they are called. Repeat changing /account/{accountId} for mosaic and namespaces endpoints.

Previous Endpoint New endpoint
/account/{accountId}/metadata/ /metadata/account/{accountId}
/account/{accountId}/metadata/{key} /metadata/account/{accountId}/key/{key}
/account/{accountId}/metadata/{key}/sender/{publicKey} /metadata/account/{accountId}/key/{key}/sender/{publicKey}

@Vektrat @rg911 @fboucquez Let me know if do you have any objection/improvements.

Single quotes in example values breaks auto-generated test cases

OpenAPI Generator for Python auto-generates fully formed test cases in Travis-CI. These tests revealed possible issues and/or room for improvements in the OpenAPI spec.

The first type of issue that broke several tests with invalid syntax error are the single quotes in example values. Screenshot of the errors (sample) in travis job log below or view the raw log.

image

Examples of the OpenAPI spec that caused the error:

Example 1:
maxTransactionsPerAggregate:
type: string
description: Maximum number of transactions per aggregate.
example: 1'000

Example 2:
currencyMosaicId:
type: string
description: Mosaic id used as primary chain currency.
example: 0x621E'C5B4'0385'6FC2

The fix is to remove the single quotes in the example values.
1.) 1'000 is replaced with 1000
2.) 0x621E'C5B4'0385'6FC2 is replaced with 0x621EC5B403856FC2

Altogether, the invalid syntax errors were found in 12 test cases and the corresponding values (with some repeats) are as follows:

  1. test_aggregate_network_properties_dto.py
    • max_transactions_per_aggregate = '1'000'
  2. test_chain_properties_dto.py
    • currency_mosaic_id = '0x621E'C5B4'0385'6FC2'
  3. test_hash_lock_network_properties_dto.py
    • locked_funds_per_aggregate = '10'000'000'
  4. test_mosaic_network_properties_dto.py
    • max_mosaics_per_account = '10'000'
  5. test_network_configuration_dto.py
    • currency_mosaic_id = '0x621E'C5B4'0385'6FC2'
  6. test_plugins_properties_dto.py
    • max_transactions_per_aggregate = '1'000'
  7. test_chain_properties_dto.py
    • harvesting_mosaic_id = '0x4291'ED23'000A'037A'
  8. test_mosaic_network_properties_dto.py
    • max_mosaics_per_account = '10'000'
  9. test_network_configuration_dto.py
    • harvesting_mosaic_id = '0x4291'ED23'000A'037A'
  10. test_plugins_properties_dto.py
    • max_mosaics_per_account = '10'000'
  11. test_chain_properties_dto.py
    • initial_currency_atomic_units = '8'998'999'998'000'000'
  12. test_network_configuration_dto.py
    • initial_currency_atomic_units = '8'998'999'998'000'000'

As a workaround, I've added a script in existing download-and-patch.sh to fix the above values. I've also attached the openapi yml with and without the single quote fix patch for comparison:
openapi3-any-of-patch.yml.txt
openapi3-any-of-patch-single-quote-patch.yml.txt

@dgarcia360 I can also fix the above values in the spec files in this repo and remove the workaround patch. Please let me know.

I'm also looking into the other failed test cases.

Database id inconsistency in Transaction payloads

Depending on the location of the transaction returned by rest, the database id can be at top level or inside the meta object. I would like to improve this by making all the objects (top-level or embedded) to have the id in the same place, ideally at top level (outside meta) like other similar stored entities.

This change will simplify the open api specification and the mappers in the clients/SDKs

Search page has ids at top level,

image

By id/s has ids at meta-level:

image

image

@Vektrat, is it possible to implement the improvement in rest?

/transaction specification only allows top level transactions to be returned

Transaction endpoints may return single, list or pages of embedded transactions but the spec only states top-level transactions

https://github.com/nemtech/symbol-openapi/blob/master/spec/core/transaction/routes/getTransaction.yml#L14

https://github.com/nemtech/symbol-openapi/blob/master/spec/core/transaction/schemas/TransactionInfoDTO.yml#L11

https://github.com/nemtech/symbol-openapi/blob/master/spec/core/transaction/schemas/TransactionMetaDTO.yml#L2

https://github.com/nemtech/symbol-openapi/blob/master/spec/core/transaction/schemas/TransactionPage.yml

https://github.com/nemtech/symbol-openapi/blob/master/spec/core/transaction/schemas/TransactionPage.yml#L10

For example:

image

Something similar to pages of transactions when embedded=true

image

It is rather aggregateHash instead of just hash

When generating the objects, aggregateHash and aggregateId are ignored from top level transactions and clients cannot create the standalone embedded transactions

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.