Skip to content
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

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

Closed
grafjo opened this issue Jan 4, 2024 · 3 comments
Closed

Comments

@grafjo
Copy link

grafjo commented Jan 4, 2024

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 (getlago/lago-java-client#7).

To Reproduce
Steps to reproduce the behavior:

  • have a customer including a subscription and some billable events
  • call current-usage endpoint of this customer and subscription
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
Copy link
Collaborator

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
Copy link
Author

grafjo commented Jan 7, 2024

Hi @vincent-pochet,

thanks for your answer. I opened a new bug in the lago-java-client getlago/lago-java-client#8

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

@vincent-pochet
Copy link
Collaborator

Thank you @grafjo.

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

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

No branches or pull requests

2 participants