Skip to content

Commit 7c38846

Browse files
committed
Add OpenAPI spec generation via utoipa
Derive ToSchema on all request/response and domain types in ldk-server-json-models, with #[schema(value_type = String)] overrides for hex-serialized fields. Define all 36 API path operations in a new openapi module using utoipa's path macro on stub functions, grouped by tags (Node, Onchain, Bolt11, Bolt12, Channels, Payments, Peers, Send, Graph, Crypto, Events). The spec is served at /openapi.json without authentication, cached via LazyLock. AI tools were used in preparing this commit.
1 parent dd3065a commit 7c38846

10 files changed

Lines changed: 834 additions & 120 deletions

File tree

Cargo.lock

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ldk-server-json-models/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ edition = "2021"
55

66
[dependencies]
77
serde = { version = "1.0", features = ["derive"] }
8+
utoipa = { version = "5", features = ["preserve_order"] }

ldk-server-json-models/src/api.rs

Lines changed: 100 additions & 71 deletions
Large diffs are not rendered by default.

ldk-server-json-models/src/error.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
// licenses.
99

1010
use serde::{Deserialize, Serialize};
11+
use utoipa::ToSchema;
1112

1213
/// When HttpStatusCode is not ok (200), the response `content` contains a serialized `ErrorResponse`
1314
/// with the relevant ErrorCode and `message`
14-
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
15+
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, ToSchema)]
1516
pub struct ErrorResponse {
1617
/// The error message containing a generic description of the error condition in English.
1718
/// It is intended for a human audience only and should not be parsed to extract any information
@@ -23,7 +24,9 @@ pub struct ErrorResponse {
2324
pub error_code: ErrorCode,
2425
}
2526

26-
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
27+
#[derive(
28+
Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize, ToSchema,
29+
)]
2730
pub enum ErrorCode {
2831
/// Will never be used as `error_code` by server.
2932
UnknownError,

ldk-server-json-models/src/events.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
// licenses.
99

1010
use serde::{Deserialize, Serialize};
11+
use utoipa::ToSchema;
1112

1213
/// An event emitted by the LDK Server to notify consumers of payment lifecycle changes.
1314
///
1415
/// Events are published to the configured messaging system (e.g., RabbitMQ) as JSON.
15-
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
16+
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, ToSchema)]
1617
#[serde(rename_all = "snake_case")]
1718
pub enum Event {
1819
PaymentReceived(PaymentReceived),
@@ -23,36 +24,36 @@ pub enum Event {
2324
}
2425

2526
/// PaymentReceived indicates a payment has been received.
26-
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
27+
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, ToSchema)]
2728
pub struct PaymentReceived {
2829
/// The payment details for the received payment.
2930
pub payment: super::types::Payment,
3031
}
3132

3233
/// PaymentSuccessful indicates a sent payment was successful.
33-
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
34+
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, ToSchema)]
3435
pub struct PaymentSuccessful {
3536
/// The payment details for the successful payment.
3637
pub payment: super::types::Payment,
3738
}
3839

3940
/// PaymentFailed indicates a sent payment has failed.
40-
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
41+
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, ToSchema)]
4142
pub struct PaymentFailed {
4243
/// The payment details for the failed payment.
4344
pub payment: super::types::Payment,
4445
}
4546

4647
/// PaymentClaimable indicates a payment has arrived and is waiting to be manually claimed or failed.
4748
/// This event is only emitted for payments created via `Bolt11ReceiveForHash`.
48-
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
49+
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, ToSchema)]
4950
pub struct PaymentClaimable {
5051
/// The payment details for the claimable payment.
5152
pub payment: super::types::Payment,
5253
}
5354

5455
/// PaymentForwarded indicates a payment was forwarded through the node.
55-
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
56+
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, ToSchema)]
5657
pub struct PaymentForwarded {
5758
/// The forwarded payment details.
5859
pub forwarded_payment: super::types::ForwardedPayment,

0 commit comments

Comments
 (0)