getlago / lago-api

Open Source Metering and Usage Based Billing
https://www.getlago.com/
GNU Affero General Public License v3.0
314 stars 92 forks source link

[BUG]: OpenAPI definition of CustomerUsageObject misalignment with lago-api #1585

Closed grafjo closed 6 months ago

grafjo commented 6 months ago

Describe the bug

Calling the current usage of a given customer via the http api contains undocumented attributes like from_date / to_date. Even https://swagger.getlago.com/#/customers/findCustomerCurrentUsage dosn't mention them nor https://docs.getlago.com/api-reference/customer-usage/get-current

This leads to invalid generated clients based on openapi definition like java client (https://github.com/getlago/lago-java-client/pull/7).

To Reproduce Steps to reproduce the behavior:

LAGO_URL="http://localhost:3000"
API_KEY="xxxxxx"
EXTERNAL_CUSTOMER_ID="db2ab212"
EXTERNAL_SUBSCRIPTION_ID="2615873e-6ef2-4ad7-b172-946e9941fef8"

# Retrieve current usage for a customer
curl --location --request GET "$LAGO_URL/api/v1/customers/$EXTERNAL_CUSTOMER_ID/current_usage?external_subscription_id=$EXTERNAL_SUBSCRIPTION_ID" \
--header "Authorization: Bearer $API_KEY" \
--header 'Content-Type: application/json' | jq .
{
  "customer_usage": {
    "from_datetime": "2024-01-03T00:00:00Z",
    "to_datetime": "2024-02-02T23:59:59Z",
    "issuing_date": "2024-02-02",
    "currency": "EUR",
    "amount_cents": 900,
    "total_amount_cents": 1071,
    "taxes_amount_cents": 171,
    "lago_invoice_id": null,
    "from_date": "2024-01-03",
    "to_date": "2024-02-02",
    "amount_currency": "EUR",
    "total_amount_currency": "EUR",
    "vat_amount_currency": "EUR",
    "vat_amount_cents": 171,
    "charges_usage": [
      {
        "units": "5.0",
        "events_count": 5,
        "amount_cents": 900,
        "amount_currency": "EUR",
        "charge": {
          "lago_id": "c857ed3a-1732-41d2-8b41-f356cfd6c8bd",
          "charge_model": "standard",
          "invoice_display_name": null
        },
        "billable_metric": {
          "lago_id": "2d610d56-8348-4482-a587-72cee518c0cf",
          "name": "Users",
          "code": "users",
          "aggregation_type": "unique_count_agg"
        },
        "groups": []
      }
    ]
  }
}

Expected behavior I expect that the openapi-definiton contains only attributes that are returned by the api or that clients are generated in a way that they will ignore unknown attributes.

Version

vincent-pochet commented 6 months ago

Hello @grafjo, thank you for pointing this issue.

from_date and to_date are legacy fields that should not be used anymore, they have been replaced by from_datetime and to_datetime respectively. They are still exposed in the API for compatibility reason, to prevent breaking existing implementation, but are undocumented to discourage usage in new implementation.

That said, it's indeed an issue if these fields cause errors in the Java SDK. It seems related to a configuration issue of the openapi java sdk generator we are using. We will update the configuration to make sure the client does not fail when an unknown attribute is received in an API response.

grafjo commented 6 months ago

Hi @vincent-pochet,

thanks for your answer. I opened a new bug in the lago-java-client https://github.com/getlago/lago-java-client/issues/8

I'm not sure if this issue here has to be open or closed.

vincent-pochet commented 6 months ago

Thank you @grafjo.

Since you open the issue on the java SDK side, I'm closing this one.