Merge pull request #1612 from Kukks/api/swaggerln

Api/swaggerln
This commit is contained in:
Nicolas Dorier 2020-05-29 18:47:25 +09:00 committed by GitHub
commit 3456d87bb5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 1089 additions and 44 deletions

View file

@ -0,0 +1,15 @@
using System.Globalization;
using BTCPayServer.Lightning;
using Newtonsoft.Json;
namespace BTCPayServer.Client.JsonConverters
{
public class LightMoneyJsonConverter : BTCPayServer.Lightning.JsonConverters.LightMoneyJsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
if (value != null)
writer.WriteValue(((LightMoney)value).MilliSatoshi.ToString(CultureInfo.InvariantCulture));
}
}
}

View file

@ -0,0 +1,25 @@
using System;
using System.Globalization;
using NBitcoin;
using Newtonsoft.Json;
namespace BTCPayServer.Client.JsonConverters
{
public class MoneyJsonConverter : NBitcoin.JsonConverters.MoneyJsonConverter
{
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.String)
{
return new Money( long.Parse((string) reader.Value));
}
return base.ReadJson(reader, objectType, existingValue, serializer);
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
if (value != null)
writer.WriteValue(((Money)value).Satoshi.ToString(CultureInfo.InvariantCulture));
}
}
}

View file

@ -1,6 +1,6 @@
using System;
using BTCPayServer.Client.JsonConverters;
using BTCPayServer.Lightning;
using BTCPayServer.Lightning.JsonConverters;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

View file

@ -1,4 +1,5 @@
using System.Collections.Generic;
using BTCPayServer.Client.JsonConverters;
using BTCPayServer.Lightning;
using NBitcoin;
using NBitcoin.JsonConverters;
@ -20,10 +21,10 @@ namespace BTCPayServer.Client.Models
public bool IsActive { get; set; }
[JsonProperty(ItemConverterType = typeof(MoneyJsonConverter))]
[JsonProperty(ItemConverterType = typeof(LightMoneyJsonConverter))]
public LightMoney Capacity { get; set; }
[JsonProperty(ItemConverterType = typeof(MoneyJsonConverter))]
[JsonProperty(ItemConverterType = typeof(LightMoneyJsonConverter))]
public LightMoney LocalBalance { get; set; }
public string ChannelPoint { get; set; }

View file

@ -1,6 +1,7 @@
using NBitcoin;
using NBitcoin.JsonConverters;
using Newtonsoft.Json;
using MoneyJsonConverter = BTCPayServer.Client.JsonConverters.MoneyJsonConverter;
namespace BTCPayServer.Client.Models
{

View file

@ -13,14 +13,14 @@ namespace BTCPayServer.Controllers.GreenField
{
[ApiController]
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
public class InternalLightningNodeApiInternalController : LightningNodeApiController
public class InternalLightningNodeApiController : LightningNodeApiController
{
private readonly BTCPayServerOptions _btcPayServerOptions;
private readonly BTCPayNetworkProvider _btcPayNetworkProvider;
private readonly LightningClientFactoryService _lightningClientFactory;
public InternalLightningNodeApiInternalController(BTCPayServerOptions btcPayServerOptions,
public InternalLightningNodeApiController(BTCPayServerOptions btcPayServerOptions,
BTCPayNetworkProvider btcPayNetworkProvider, BTCPayServerEnvironment btcPayServerEnvironment,
CssThemeManager cssThemeManager, LightningClientFactoryService lightningClientFactory) : base(
btcPayNetworkProvider, btcPayServerEnvironment, cssThemeManager)

View file

@ -4,14 +4,6 @@
"ConnectToNodeRequest": {
"oneOf": [
{
"$ref": "#/components/schemas/ConnectToNodeRequest1"
},
{
"$ref": "#/components/schemas/ConnectToNodeRequest2"
}
]
},
"ConnectToNodeRequest1": {
"type": "object",
"additionalProperties": false,
"properties": {
@ -21,7 +13,7 @@
}
}
},
"ConnectToNodeRequest2": {
{
"type": "object",
"additionalProperties": false,
"properties": {
@ -38,6 +30,8 @@
"format": "int32"
}
}
}
]
},
"CreateLightningInvoiceRequest": {
"type": "object",
@ -65,8 +59,9 @@
}
},
"LightMoney": {
"type": "integer",
"type": "string",
"format": "int64",
"description": "a number amount wrapped in a string, represented in millistatoshi (00000000001BTC = 1 mSAT)",
"additionalProperties": false
},
"LightningChannelData": {
@ -219,8 +214,9 @@
}
},
"Money": {
"type": "integer",
"format": "int64"
"type": "string",
"format": "int64",
"description": "a number amount wrapped in a string, represented in satoshi (00000001BTC = 1 sat)"
},
"FeeRate": {
"oneOf": [
@ -235,10 +231,5 @@
]
}
}
},
"tags": [
{
"name": "Lightning"
}
]
}

View file

@ -0,0 +1,470 @@
{
"paths": {
"/api/v1/server/lightning/{cryptoCode}/info": {
"get": {
"tags": [
"Lightning (Internal Node)"
],
"summary": "Get node information",
"parameters": [
{
"name": "cryptoCode",
"in": "path",
"required": true,
"description": "The cryptoCode of the lightning-node to query",
"schema": {
"type": "string"
}
}
],
"description": "View information about the lightning node",
"operationId": "InternalLightningNodeApi_GetInfo",
"responses": {
"200": {
"description": "Lightning node information such as reachable nodeinfos",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LightningNodeInformationData"
}
}
}
},
"400": {
"description": "A list of errors that occurred",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ValidationProblemDetails"
}
}
}
},
"403": {
"description": "If you are authenticated but forbidden"
}
},
"security": [
{
"API Key": [
"btcpay.server.canuseinternallightningnode"
],
"Basic": []
}
]
}
},
"/api/v1/server/lightning/{cryptoCode}/connect": {
"post": {
"tags": [
"Lightning (Internal Node)"
],
"summary": "Connect to lightning node",
"parameters": [
{
"name": "cryptoCode",
"in": "path",
"required": true,
"description": "The cryptoCode of the lightning-node to query",
"schema": {
"type": "string"
}
}
],
"description": "Connect to another lightning node.",
"operationId": "InternalLightningNodeApi_ConnectToNode",
"responses": {
"200": {
"description": "Successfully connected"
},
"400": {
"description": "A list of errors that occurred when attempting to connect to the lightning node",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ValidationProblemDetails"
}
}
}
},
"403": {
"description": "If you are authenticated but forbidden"
}
},
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ConnectToNodeRequest"
}
}
}
},
"security": [
{
"API Key": [
"btcpay.server.canuseinternallightningnode"
],
"Basic": []
}
]
}
},
"/api/v1/server/lightning/{cryptoCode}/channels": {
"get": {
"tags": [
"Lightning (Internal Node)"
],
"summary": "Get channels",
"parameters": [
{
"name": "cryptoCode",
"in": "path",
"required": true,
"description": "The cryptoCode of the lightning-node to query",
"schema": {
"type": "string"
}
}
],
"description": "View information about the current channels of the lightning node",
"operationId": "InternalLightningNodeApi_GetChannels",
"responses": {
"200": {
"description": "list of channels",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/LightningChannelData"
}
}
}
}
},
"400": {
"description": "A list of errors that occurred",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ValidationProblemDetails"
}
}
}
},
"403": {
"description": "If you are authenticated but forbidden"
}
},
"security": [
{
"API Key": [
"btcpay.server.canuseinternallightningnode"
],
"Basic": []
}
]
},
"post": {
"tags": [
"Lightning (Internal Node)"
],
"summary": "Open channel",
"parameters": [
{
"name": "cryptoCode",
"in": "path",
"required": true,
"description": "The cryptoCode of the lightning-node to query",
"schema": {
"type": "string"
}
}
],
"description": "Open a channel with another lightning node. You should connect to that node first.",
"operationId": "InternalLightningNodeApi_OpenChannel",
"responses": {
"200": {
"description": "Successfully opened"
},
"400": {
"description": "A list of errors that occurred when attempting to connect to the lightning node",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ValidationProblemDetails"
}
}
}
},
"403": {
"description": "If you are authenticated but forbidden"
}
},
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/OpenLightningChannelRequest"
}
}
}
},
"security": [
{
"API Key": [
"btcpay.server.canuseinternallightningnode"
],
"Basic": []
}
]
}
},
"/api/v1/server/lightning/{cryptoCode}/address": {
"get": {
"tags": [
"Lightning (Internal Node)"
],
"summary": "Get deposit address",
"parameters": [
{
"name": "cryptoCode",
"in": "path",
"required": true,
"description": "The cryptoCode of the lightning-node to query",
"schema": {
"type": "string"
}
}
],
"description": "Get an on-chain deposit address for the lightning node ",
"operationId": "InternalLightningNodeApi_GetDepositAddress",
"responses": {
"200": {
"description": "deposit address",
"content": {
"application/json": {
"schema": {
"type": "string"
}
}
}
},
"400": {
"description": "A list of errors that occurred",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ValidationProblemDetails"
}
}
}
},
"403": {
"description": "If you are authenticated but forbidden"
}
},
"security": [
{
"API Key": [
"btcpay.server.canuseinternallightningnode"
],
"Basic": []
}
]
}
},
"/api/v1/server/lightning/{cryptoCode}/invoices/{id}": {
"get": {
"tags": [
"Lightning (Internal Node)"
],
"summary": "Get invoice",
"parameters": [
{
"name": "cryptoCode",
"in": "path",
"required": true,
"description": "The cryptoCode of the lightning-node to query",
"schema": {
"type": "string"
}
} , {
"name": "id",
"in": "path",
"required": true,
"description": "The id of the lightning invoice.",
"schema": {
"type": "string"
}
}
],
"description": "View information about the requested lightning invoice",
"operationId": "InternalLightningNodeApi_GetInvoice",
"responses": {
"200": {
"description": "Lightning invoice data",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LightningInvoiceData"
}
}
}
},
"400": {
"description": "A list of errors that occurred",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ValidationProblemDetails"
}
}
}
},
"403": {
"description": "If you are authenticated but forbidden"
}
},
"security": [
{
"API Key": [
"btcpay.server.canuseinternallightningnode"
],
"Basic": []
}
]
}
},
"/api/v1/server/lightning/{cryptoCode}/invoices/pay": {
"post": {
"tags": [
"Lightning (Internal Node)"
],
"summary": "Pay Lightning Invoice",
"parameters": [
{
"name": "cryptoCode",
"in": "path",
"required": true,
"description": "The cryptoCode of the lightning-node to query",
"schema": {
"type": "string"
}
}
],
"description": "Pay a lightning invoice.",
"operationId": "InternalLightningNodeApi_PayInvoice",
"responses": {
"200": {
"description": "Successfully paid"
},
"400": {
"description": "A list of errors that occurred when attempting to pay the lightning invoice",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ValidationProblemDetails"
}
}
}
},
"403": {
"description": "If you are authenticated but forbidden"
}
},
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/PayLightningInvoiceRequest"
}
}
}
},
"security": [
{
"API Key": [
"btcpay.server.canuseinternallightningnode"
],
"Basic": []
}
]
}
},
"/api/v1/server/lightning/{cryptoCode}/invoices": {
"post": {
"tags": [
"Lightning (Internal Node)"
],
"summary": "Create lightning invoice",
"parameters": [
{
"name": "cryptoCode",
"in": "path",
"required": true,
"description": "The cryptoCode of the lightning-node to query",
"schema": {
"type": "string"
}
}
],
"description": "Create a lightning invoice.",
"operationId": "InternalLightningNodeApi_CreateInvoice",
"responses": {
"200": {
"description": "Successfully created",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LightningInvoiceData"
}
}
}
},
"400": {
"description": "A list of errors that occurred when attempting to create the lightning invoice",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ValidationProblemDetails"
}
}
}
},
"403": {
"description": "If you are authenticated but forbidden"
}
},
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/PayLightningInvoiceRequest"
}
}
}
},
"security": [
{
"API Key": [
"btcpay.server.cancreatelightninginvoiceinternalnode"
],
"Basic": []
}
]
}
}
},
"tags": [
{
"name": "Lightning (Internal Node)"
}
]
}

View file

@ -0,0 +1,542 @@
{
"paths": {
"/api/v1/stores/{storeId}/lightning/{cryptoCode}/info": {
"get": {
"tags": [
"Lightning (Store)"
],
"summary": "Get node information",
"parameters": [
{
"name": "storeId",
"in": "path",
"required": true,
"description": "The store id with the lightning node configuration you wish to use",
"schema": {
"type": "string"
}
},
{
"name": "cryptoCode",
"in": "path",
"required": true,
"description": "The cryptoCode of the lightning-node to query",
"schema": {
"type": "string"
}
}
],
"description": "View information about the lightning node",
"operationId": "StoreLightningNodeApi_GetInfo",
"responses": {
"200": {
"description": "Lightning node information such as reachable nodeinfos",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LightningNodeInformationData"
}
}
}
},
"400": {
"description": "A list of errors that occurred",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ValidationProblemDetails"
}
}
}
},
"403": {
"description": "If you are authenticated but forbidden"
}
},
"security": [
{
"API Key": [
"btcpay.store.canuselightningnode"
],
"Basic": []
}
]
}
},
"/api/v1/stores/{storeId}/lightning/{cryptoCode}/connect": {
"post": {
"tags": [
"Lightning (Store)"
],
"summary": "Connect to lightning node",
"parameters": [
{
"name": "storeId",
"in": "path",
"required": true,
"description": "The store id with the lightning node configuration you wish to use",
"schema": {
"type": "string"
}
},
{
"name": "cryptoCode",
"in": "path",
"required": true,
"description": "The cryptoCode of the lightning-node to query",
"schema": {
"type": "string"
}
}
],
"description": "Connect to another lightning node.",
"operationId": "StoreLightningNodeApi_ConnectToNode",
"responses": {
"200": {
"description": "Successfully connected"
},
"400": {
"description": "A list of errors that occurred when attempting to connect to the lightning node",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ValidationProblemDetails"
}
}
}
},
"403": {
"description": "If you are authenticated but forbidden"
}
},
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ConnectToNodeRequest"
}
}
}
},
"security": [
{
"API Key": [
"btcpay.store.canuselightningnode"
],
"Basic": []
}
]
}
},
"/api/v1/stores/{storeId}/lightning/{cryptoCode}/channels": {
"get": {
"tags": [
"Lightning (Store)"
],
"summary": "Get channels",
"parameters": [
{
"name": "storeId",
"in": "path",
"required": true,
"description": "The store id with the lightning node configuration you wish to use",
"schema": {
"type": "string"
}
},
{
"name": "cryptoCode",
"in": "path",
"required": true,
"description": "The cryptoCode of the lightning-node to query",
"schema": {
"type": "string"
}
}
],
"description": "View information about the current channels of the lightning node",
"operationId": "StoreLightningNodeApi_GetChannels",
"responses": {
"200": {
"description": "list of channels",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/LightningChannelData"
}
}
}
}
},
"400": {
"description": "A list of errors that occurred",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ValidationProblemDetails"
}
}
}
},
"403": {
"description": "If you are authenticated but forbidden"
}
},
"security": [
{
"API Key": [
"btcpay.store.canuselightningnode"
],
"Basic": []
}
]
},
"post": {
"tags": [
"Lightning (Store)"
],
"summary": "Open channel",
"parameters": [
{
"name": "storeId",
"in": "path",
"required": true,
"description": "The store id with the lightning node configuration you wish to use",
"schema": {
"type": "string"
}
},
{
"name": "cryptoCode",
"in": "path",
"required": true,
"description": "The cryptoCode of the lightning-node to query",
"schema": {
"type": "string"
}
}
],
"description": "Open a channel with another lightning node. You should connect to that node first.",
"operationId": "StoreLightningNodeApi_OpenChannel",
"responses": {
"200": {
"description": "Successfully opened"
},
"400": {
"description": "A list of errors that occurred when attempting to connect to the lightning node",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ValidationProblemDetails"
}
}
}
},
"403": {
"description": "If you are authenticated but forbidden"
}
},
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/OpenLightningChannelRequest"
}
}
}
},
"security": [
{
"API Key": [
"btcpay.store.canuselightningnode"
],
"Basic": []
}
]
}
},
"/api/v1/stores/{storeId}/lightning/{cryptoCode}/address": {
"get": {
"tags": [
"Lightning (Store)"
],
"summary": "Get deposit address",
"parameters": [
{
"name": "storeId",
"in": "path",
"required": true,
"description": "The store id with the lightning node configuration you wish to use",
"schema": {
"type": "string"
}
},
{
"name": "cryptoCode",
"in": "path",
"required": true,
"description": "The cryptoCode of the lightning-node to query",
"schema": {
"type": "string"
}
}
],
"description": "Get an on-chain deposit address for the lightning node ",
"operationId": "StoreLightningNodeApi_GetDepositAddress",
"responses": {
"200": {
"description": "deposit address",
"content": {
"application/json": {
"schema": {
"type": "string"
}
}
}
},
"400": {
"description": "A list of errors that occurred",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ValidationProblemDetails"
}
}
}
},
"403": {
"description": "If you are authenticated but forbidden"
}
},
"security": [
{
"API Key": [
"btcpay.store.canuselightningnode"
],
"Basic": []
}
]
}
},
"/api/v1/stores/{storeId}/lightning/{cryptoCode}/invoices/{id}": {
"get": {
"tags": [
"Lightning (Store)"
],
"summary": "Get invoice",
"parameters": [
{
"name": "storeId",
"in": "path",
"required": true,
"description": "The store id with the lightning node configuration you wish to use",
"schema": {
"type": "string"
}
},
{
"name": "cryptoCode",
"in": "path",
"required": true,
"description": "The cryptoCode of the lightning-node to query",
"schema": {
"type": "string"
}
},
{
"name": "id",
"in": "path",
"required": true,
"description": "The id of the lightning invoice.",
"schema": {
"type": "string"
}
}
],
"description": "View information about the requested lightning invoice",
"operationId": "StoreLightningNodeApi_GetInvoice",
"responses": {
"200": {
"description": "Lightning invoice data",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LightningInvoiceData"
}
}
}
},
"400": {
"description": "A list of errors that occurred",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ValidationProblemDetails"
}
}
}
},
"403": {
"description": "If you are authenticated but forbidden"
}
},
"security": [
{
"API Key": [
"btcpay.store.canuselightningnode"
],
"Basic": []
}
]
}
},
"/api/v1/stores/{storeId}/lightning/{cryptoCode}/invoices/pay": {
"post": {
"tags": [
"Lightning (Store)"
],
"summary": "Pay Lightning Invoice",
"parameters": [
{
"name": "storeId",
"in": "path",
"required": true,
"description": "The store id with the lightning node configuration you wish to use",
"schema": {
"type": "string"
}
},
{
"name": "cryptoCode",
"in": "path",
"required": true,
"description": "The cryptoCode of the lightning-node to query",
"schema": {
"type": "string"
}
}
],
"description": "Pay a lightning invoice.",
"operationId": "StoreLightningNodeApi_PayInvoice",
"responses": {
"200": {
"description": "Successfully paid"
},
"400": {
"description": "A list of errors that occurred when attempting to pay the lightning invoice",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ValidationProblemDetails"
}
}
}
},
"403": {
"description": "If you are authenticated but forbidden"
}
},
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/PayLightningInvoiceRequest"
}
}
}
},
"security": [
{
"API Key": [
"btcpay.store.canuselightningnode"
],
"Basic": []
}
]
}
},
"/api/v1/stores/{storeId}/lightning/{cryptoCode}/invoices": {
"post": {
"tags": [
"Lightning (Store)"
],
"summary": "Create lightning invoice",
"parameters": [
{
"name": "storeId",
"in": "path",
"required": true,
"description": "The store id with the lightning node configuration you wish to use",
"schema": {
"type": "string"
}
},
{
"name": "cryptoCode",
"in": "path",
"required": true,
"description": "The cryptoCode of the lightning-node to query",
"schema": {
"type": "string"
}
}
],
"description": "Create a lightning invoice.",
"operationId": "StoreLightningNodeApi_CreateInvoice",
"responses": {
"200": {
"description": "Successfully created",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LightningInvoiceData"
}
}
}
},
"400": {
"description": "A list of errors that occurred when attempting to create the lightning invoice",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ValidationProblemDetails"
}
}
}
},
"403": {
"description": "If you are authenticated but forbidden"
}
},
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/PayLightningInvoiceRequest"
}
}
}
},
"security": [
{
"API Key": [
"btcpay.store.cancreatelightninginvoice"
],
"Basic": []
}
]
}
}
},
"tags": [
{
"name": "Lightning (Store)"
}
]
}