Skip to content

Conversation

@anstylian
Copy link
Member

@anstylian anstylian commented Sep 17, 2025

refactor(amplifier-api): migrate to codegen OpenAPI client, remove hand-written types/client

  • Replace hand-written API client, types, and BigInt logic with code generated from OpenAPI schema (schema.yaml) using progenitor.
  • Add build.rs to generate Rust client code at build time, including custom Borsh serialization and QueueMsgId trait implementations.
  • Update dependencies in Cargo.toml for codegen and tracing/opentelemetry support.
  • Remove src/big_int.rs, src/client.rs, src/client/requests.rs, and src/types.rs.
  • All API types and client logic now come from generated code in amplifier_open_api module.

The schema is coming from here:
schema/schema.yaml

Comment on lines +513 to +517
# properties:
# type:
# $ref: '#/components/schemas/EventType'
# required:
# - type
Copy link
Member Author

@anstylian anstylian Sep 17, 2025

Choose a reason for hiding this comment

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

This is commented out to get the generated code like this:

    pub enum Event {
        GasCreditEvent(GasCreditEvent),
        GasRefundedEvent(GasRefundedEvent),
        CallEvent(CallEvent),
        MessageApprovedEvent(MessageApprovedEvent),
        MessageExecutedEvent(MessageExecutedEvent),
        MessageExecutedEventV2(MessageExecutedEventV2),
        CannotExecuteMessageEvent(CannotExecuteMessageEvent),
        CannotExecuteMessageEventV2(CannotExecuteMessageEventV2),
        CannotRouteMessageEvent(CannotRouteMessageEvent),
        CannotExecuteTaskEvent(CannotExecuteTaskEvent),
        SignersRotatedEvent(SignersRotatedEvent),
        ItsLinkTokenStartedEvent(ItsLinkTokenStartedEvent),
        ItsTokenMetadataRegisteredEvent(ItsTokenMetadataRegisteredEvent),
        ItsInterchainTokenDeploymentStartedEvent(
            ItsInterchainTokenDeploymentStartedEvent,
        ),
        ItsInterchainTransferEvent(ItsInterchainTransferEvent),
        AppInterchainTransferSentEvent(AppInterchainTransferSentEvent),
        AppInterchainTransferReceivedEvent(AppInterchainTransferReceivedEvent),
    }

If have those lines enabled the generated code looks like this:

    pub enum Event {
        Variant0 {
            #[serde(rename = "eventID")]
            event_id: EventVariant0EventId,
            #[serde(rename = "messageID")]
            message_id: EventVariant0MessageId,
            #[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
            meta: ::std::option::Option<EventMetadata>,
            payment: UnsignedToken,
            #[serde(rename = "refundAddress")]
            refund_address: Address,
            #[serde(rename = "type")]
            type_: EventType,
        },
        Variant1 {
            cost: Cost,
            #[serde(rename = "eventID")]
            event_id: EventVariant1EventId,
            #[serde(rename = "messageID")]
            message_id: EventVariant1MessageId,
            #[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
            meta: ::std::option::Option<EventMetadata>,
            #[serde(rename = "recipientAddress")]
            recipient_address: Address,
            #[serde(rename = "refundedAmount")]
            refunded_amount: UnsignedToken,
            #[serde(rename = "type")]
            type_: EventType,
        },

@anstylian anstylian changed the title Introduce codegen for open-api refactor(amplifier-api): Introduce codegen for open-api Sep 17, 2025
@anstylian anstylian changed the title refactor(amplifier-api): Introduce codegen for open-api refactor(amplifier-api): introduce codegen for open-api Sep 17, 2025
@@ -0,0 +1,138 @@
//! Helpers for creating an authenticated `reqwest::Client` for amplifier-api.
Copy link
Member Author

Choose a reason for hiding this comment

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

This code is moved from the previous implementation. It was at crates/amplifier-api/src/client.rs.

// while returning the result of `internal`.
cx.waker().wake_by_ref();
return Poll::Ready(Some(Ok(res)));
return Poll::Ready(Some(Ok(Ok(()))));
Copy link
Member Author

Choose a reason for hiding this comment

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

I’d prefer not to edit this file much, so I added Ok(Ok(())) here. Later, in the JoinSet, a future returning eyre::Result<()> will be added.


cx.waker().wake_by_ref();
return Poll::Ready(Some(Ok(res)));
return Poll::Ready(Some(Ok(Ok(()))));
Copy link
Member Author

Choose a reason for hiding this comment

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

I’d prefer not to edit this file much, so I added Ok(Ok(())) here. Later, in the JoinSet, a future returning eyre::Result<()> will be added.

@anstylian anstylian marked this pull request as ready for review September 19, 2025 08:19
@anstylian
Copy link
Member Author

If you have any good suggestion, I prefer to drop the changes of crate relayer-amplifier-api-integration

@anstylian anstylian marked this pull request as draft September 19, 2025 11:04
@anstylian
Copy link
Member Author

I have convert it back to Draft because the QueueMsgId needs to be implemented for Events as well.

@anstylian anstylian marked this pull request as ready for review September 19, 2025 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants