Skip to content

[OpenAPI Codegen] Update scaffolding models from rippled-api-spec v0.1.0-b1 #832

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ docstring-convention=google
# E203 and W503 don't interact well with black
ignore = D205,D212,D415,E203,W503

exclude =
xrpl/openapi-codegen/*
Comment on lines +10 to +11
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't exclude the folder, if there's something wrong with the typing then the codegen probably needs to be fixed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, will fix the pipeline


# This is the line length that black uses
# https://black.readthedocs.io/en/stable/the_black_code_style.html#line-length
max-line-length = 88
Expand Down
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[mypy]
exclude = dist
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't exclude the folder, if there's something wrong with the typing then the codegen probably needs to be fixed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I will fix the CI/CD pipeline on the codegen end to fix linting issues before publishing the code

exclude = ^(dist|xrpl/openapi-codegen)
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ build-backend = "poetry.core.masonry.api"
[tool.coverage.run]
branch = true
source = ["xrpl"]
omit = ["xrpl/openapi-codegen/*"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't be needed if the openapi-codegen folder is at the top level


[tool.coverage.report]
show_missing = true
Expand Down
19 changes: 19 additions & 0 deletions xrpl/openapi-codegen/models/auth_account.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Model for AuthAccount."""

from dataclasses import dataclass
from xrpl.models.base_model import BaseModel
from xrpl.models.utils import REQUIRED
from xrpl.models.utils import require_kwargs_on_init


@require_kwargs_on_init
@dataclass(frozen=True)
class AuthAccount(BaseModel):
Copy link
Collaborator

@mvadari mvadari Apr 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to use NestedModel - all inner object types will need it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. Will fix in the next version

account: str = REQUIRED
"""
(Required) The address of the account to authorize.
"""

def _get_errors(self: AuthAccount) -> Dict[str, str]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_get_errors shouldn't be included if there's nothing to include

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch, I think this is a spec error specific to this object (probably we added a validation rule with incorrect name for this object

errors = super._get_errors()
return errors
24 changes: 24 additions & 0 deletions xrpl/openapi-codegen/models/authorize_credentials.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""Model for AuthorizeCredentials."""

from dataclasses import dataclass
from xrpl.models.base_model import BaseModel
from xrpl.models.utils import REQUIRED
from xrpl.models.utils import require_kwargs_on_init


@require_kwargs_on_init
@dataclass(frozen=True)
class AuthorizeCredentials(BaseModel):
"""
Represents a credential used for preauthorization.
"""

issuer: str = REQUIRED
"""
(Required) The issuer of the credential.
"""

credential_type: str = REQUIRED
"""
(Required) The credential type of the credential.
"""
10 changes: 10 additions & 0 deletions xrpl/openapi-codegen/models/currency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""
The XRP Ledger has two kinds of money: XRP, and issued currencies. Both types have high
precision, although their formats are different.
"""

from typing import Union
from xrpl.models.issued_currency import IssuedCurrency
from xrpl.models.xrp import XRP

Currency = Union[IssuedCurrency, XRP]
25 changes: 25 additions & 0 deletions xrpl/openapi-codegen/models/issued_currency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""Model for IssuedCurrency."""

from dataclasses import dataclass
from typing import Optional
from xrpl.models.base_model import BaseModel
from xrpl.models.utils import require_kwargs_on_init


@require_kwargs_on_init
@dataclass(frozen=True)
class IssuedCurrency(BaseModel):
currency: Optional[str] = None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't all types have a description?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we will fix after revising the spec

"""
Arbitrary currency code for the token.
"""

issuer: Optional[str] = None
"""
Generally, the account that issues this token. In special cases, this can refer to the
account that holds the token instead (for example, in a Clawback transaction).
"""

def _get_errors(self: IssuedCurrency) -> Dict[str, str]:
errors = super._get_errors()
return errors
29 changes: 29 additions & 0 deletions xrpl/openapi-codegen/models/memo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""Model for Memo."""

from dataclasses import dataclass
from typing import Optional
from xrpl.models.base_model import BaseModel
from xrpl.models.utils import require_kwargs_on_init


@require_kwargs_on_init
@dataclass(frozen=True)
class Memo(BaseModel):
memo_data: Optional[str] = None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if a type doesn't have a description, can there be a newline between the class line and the first param? Easier to read that way

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. But all of them should have a description imo so probably will need to add to the spec

"""
Arbitrary hex value, conventionally containing the content of the memo.
"""

memo_format: Optional[str] = None
"""
Hex value representing characters allowed in URLs. Conventionally containing information
on how the memo is encoded, for example as a [MIME
type](https://www.iana.org/assignments/media-types/media-types.xhtml).
"""

memo_type: Optional[str] = None
"""
Hex value representing characters allowed in URLs. Conventionally, a unique relation
(according to [RFC 5988](https://datatracker.ietf.org/doc/html/rfc5988#section-4)) that
defines the format of this memo.
"""
47 changes: 47 additions & 0 deletions xrpl/openapi-codegen/models/path_step.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""Model for PathStep."""

from dataclasses import dataclass
from typing import Optional
from xrpl.models.base_model import BaseModel
from xrpl.models.utils import require_kwargs_on_init


@require_kwargs_on_init
@dataclass(frozen=True)
class PathStep(BaseModel):
"""
A PathStep represents an individual step along a Path.
"""

account: Optional[str] = None
"""
(Optional) If present, this path step represents rippling through the specified address.
MUST NOT be provided if this step specifies the currency or issuer fields.
"""

currency: Optional[str] = None
"""
(Optional) If present, this path step represents changing currencies through an order
book. The currency specified indicates the new currency. MUST NOT be provided if this
step specifies the account field.
"""

issuer: Optional[str] = None
"""
(Optional) If present, this path step represents changing currencies and this address
defines the issuer of the new currency. If omitted in a step with a non-XRP currency, a
previous step of the path defines the issuer. If present when currency is omitted,
indicates a path step that uses an order book between same-named currencies with
different issuers. MUST be omitted if the currency is XRP. MUST NOT be provided if this
step specifies the account field.
"""

type: Optional[int] = None
"""
DEPRECATED (Optional) An indicator of which other fields are present.
"""

type_hex: Optional[str] = None
"""
DEPRECATED: (Optional) A hexadecimal representation of the type field.
"""
59 changes: 59 additions & 0 deletions xrpl/openapi-codegen/models/price_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""Model for PriceData."""

from dataclasses import dataclass
from typing import Optional
from xrpl.models.base_model import BaseModel
from xrpl.models.utils import REQUIRED
from xrpl.models.utils import require_kwargs_on_init


@require_kwargs_on_init
@dataclass(frozen=True)
class PriceData(BaseModel):
base_asset: str = REQUIRED
"""
The primary asset in a trading pair (e.g., BTC in BTC/USD). Any valid identifier, such
as a stock symbol, bond CUSIP, or currency code, is allowed.
"""

quote_asset: str = REQUIRED
"""
The quote asset in a trading pair, denoting the price of one unit of the base asset
(e.g., USD in BTC/USD).
"""

asset_price: Optional[str] = None
"""
The asset price after applying the Scale precision level. Recommended to be provided as
a hexadecimal, but decimal numbers are accepted. Not included if the last update
transaction didn't include the BaseAsset/QuoteAsset pair.
"""

scale: Optional[int] = None
"""
The scaling factor to apply to an asset price. If Scale is 6 and the original price is
0.155, then the scaled price is 155000. Valid scale ranges are 0-10. Not included if
the last update transaction didn't include the BaseAsset/QuoteAsset pair.
"""

def _get_errors(self: PriceData) -> Dict[str, str]:
errors = super._get_errors()
if (self.asset_price is not None) != (self.scale is not None):
errors["PriceData"] = (
"Both `asset_price` and `scale` are required if any is presented."
)
if (
self.asset_price is not None
and self.asset_price != REQUIRED
and not self.asset_price.isnumeric()
):
errors["PriceData"] = "`asset_price` must be numeric."
if self.scale is not None and self.scale < 0:
errors["PriceData"] = (
"Field `scale` must have a value greater than or equal to 0"
)
if self.scale is not None and self.scale > 10:
errors["PriceData"] = (
"Field `scale` must have a value less than or equal to 10"
)
return errors
21 changes: 21 additions & 0 deletions xrpl/openapi-codegen/models/requests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""Request models."""

from xrpl.models.requests.account_channels import AccountChannels
from xrpl.models.requests.account_info import AccountInfo
from xrpl.models.requests.account_lines import AccountLines
from xrpl.models.requests.lookup_by_ledger_request import LookupByLedgerRequest
from xrpl.models.requests.lookup_by_ledger_request import (
LookupByLedgerRequestLedgerIndex,
)
from xrpl.models.requests.request import Request
from xrpl.models.requests.server_info import ServerInfo

__all__ = [
AccountChannels,
AccountInfo,
AccountLines,
LookupByLedgerRequest,
LookupByLedgerRequestLedgerIndex,
Request,
ServerInfo,
]
57 changes: 57 additions & 0 deletions xrpl/openapi-codegen/models/requests/account_channels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""Model for AccountChannels request type."""

from dataclasses import dataclass, field
from typing import Any, Optional, Union
from xrpl.models.requests.request import RequestMethod
from xrpl.models.utils import REQUIRED
from xrpl.models.requests.base_request import BaseRequest
from xrpl.models.requests.lookup_by_ledger import LookupByLedgerRequest
from xrpl.models.utils import require_kwargs_on_init


@require_kwargs_on_init
@dataclass(frozen=True)
class AccountChannels(BaseRequest, LookupByLedgerRequest):
"""
The account_channels method returns information about an account's Payment Channels.
This includes only channels where the specified account is the channel's source, not the
destination. (A channel's source and owner are the same.) All information retrieved is
relative to a particular version of the ledger. Returns an AccountChannelsResponse.
"""

method: RequestMethod = field(default=RequestMethod.ACCOUNT_CHANNELS, init=False)

account: str = REQUIRED
"""
The unique identifier of an account, typically the account's address.
"""

destination_account: Optional[str] = None
"""
The unique identifier of an account, typically the account's address. If provided,
filter results to payment channels whose destination is this account.
"""

limit: Optional[Union[float, int]] = None
"""
Limit the number of transactions to retrieve. Cannot be less than 10 or more than 400.
The default is 200.
"""

marker: Optional[Any] = None
"""
Value from a previous paginated response. Resume retrieving data where that response
left off.
"""

def _get_errors(self: AccountChannels) -> Dict[str, str]:
errors = super._get_errors()
if self.limit is not None and self.limit < 10:
errors["AccountChannels"] = (
"Field `limit` must have a value greater than or equal to 10"
)
if self.limit is not None and self.limit > 400:
errors["AccountChannels"] = (
"Field `limit` must have a value less than or equal to 400"
)
return errors
40 changes: 40 additions & 0 deletions xrpl/openapi-codegen/models/requests/account_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""Model for AccountInfo request type."""

from dataclasses import dataclass, field
from typing import Optional
from xrpl.models.requests.request import RequestMethod
from xrpl.models.utils import REQUIRED
from xrpl.models.requests.base_request import BaseRequest
from xrpl.models.requests.lookup_by_ledger import LookupByLedgerRequest
from xrpl.models.utils import require_kwargs_on_init


@require_kwargs_on_init
@dataclass(frozen=True)
class AccountInfo(BaseRequest, LookupByLedgerRequest):
"""
The account_info command retrieves information about an account, its activity, and its
XRP balance. All information retrieved is relative to a particular version of the
ledger. Returns an AccountInfoResponse
"""

method: RequestMethod = field(default=RequestMethod.ACCOUNT_INFO, init=False)

account: str = REQUIRED
"""
The account to look up.
"""

queue: Optional[bool] = None
"""
If true, return stats about queued transactions sent by this account. Can only be used
when querying for the data from the current open ledger. Not available from servers in
Reporting Mode.
"""

signer_lists: Optional[bool] = None
"""
API v1: If true, return any SignerList objects associated with this account. API v2:
Identical to v1, but also returns an invalidParams error if you provide a non-boolean
value.
"""
Loading