Skip to content

Commit

Permalink
fix: invoice updates should allow adding new lines without IDs
Browse files Browse the repository at this point in the history
This patch makes sure that it's not mandatory to specify a fake ULID to create
new invoice lines.
  • Loading branch information
turip committed Jan 27, 2025
1 parent df4767c commit 522d75c
Show file tree
Hide file tree
Showing 7 changed files with 1,133 additions and 1,074 deletions.
1,023 changes: 514 additions & 509 deletions api/api.gen.go

Large diffs are not rendered by default.

1,046 changes: 525 additions & 521 deletions api/client/go/client.gen.go

Large diffs are not rendered by default.

28 changes: 16 additions & 12 deletions api/client/javascript/src/client/schemas.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4070,7 +4070,9 @@ export interface components {
*/
category?: components['schemas']['InvoiceFlatFeeCategory']
}
/** @description Resource update operation model. */
/** @description InvoiceFlatFeeLineReplaceUpdate represents the update model for a flat fee invoice line.
*
* This type makes ID optional to allow for creating new lines as part of the update. */
InvoiceFlatFeeLineReplaceUpdate: {
/**
* Display name
Expand All @@ -4087,11 +4089,6 @@ export interface components {
* @description Additional metadata for the resource.
*/
metadata?: components['schemas']['Metadata'] | null
/**
* @description ULID (Universally Unique Lexicographically Sortable Identifier).
* @example 01G65Z755AFWAKHE12NY0CQ9FH
*/
id: string
/** @description Tax config specify the tax configuration for this line. */
taxConfig?: components['schemas']['TaxConfig']
/** @description Period of the line item applies to for revenue recognition pruposes.
Expand Down Expand Up @@ -4120,6 +4117,11 @@ export interface components {
* @default regular
*/
category?: components['schemas']['InvoiceFlatFeeCategory']
/**
* @description The ID of the line.
* @example 01G65Z755AFWAKHE12NY0CQ9FH
*/
id?: string
}
/** @description InvoiceFlatFeePendingLineCreate represents the create model for an invoice line that is sold to the customer as a manually added fee. */
InvoiceFlatFeePendingLineCreate: {
Expand Down Expand Up @@ -4648,7 +4650,9 @@ export interface components {
* It is non-zero in case of progressive billing, when this shows how much of the usage was already billed. */
readonly preLinePeriodQuantity?: components['schemas']['Numeric']
}
/** @description Resource update operation model. */
/** @description InvoiceUpdateUsageBasedLineReplaceUpdate represents the update model for an UBP invoice line.
*
* This type makes ID optional to allow for creating new lines as part of the update. */
InvoiceUsageBasedLineReplaceUpdate: {
/**
* Display name
Expand All @@ -4665,11 +4669,6 @@ export interface components {
* @description Additional metadata for the resource.
*/
metadata?: components['schemas']['Metadata'] | null
/**
* @description ULID (Universally Unique Lexicographically Sortable Identifier).
* @example 01G65Z755AFWAKHE12NY0CQ9FH
*/
id: string
/** @description Tax config specify the tax configuration for this line. */
taxConfig?: components['schemas']['TaxConfig']
/** @description Period of the line item applies to for revenue recognition pruposes.
Expand All @@ -4687,6 +4686,11 @@ export interface components {
price: components['schemas']['RateCardUsageBasedPrice']
/** @description The feature that the usage is based on. */
featureKey: string
/**
* @description The ID of the line.
* @example 01G65Z755AFWAKHE12NY0CQ9FH
*/
id?: string
}
/** @description InvoiceUsageBasedLineCreateWithCustomer represents the create model for an invoice line that is sold to the customer based on usage. */
InvoiceUsageBasedPendingLineCreate: {
Expand Down
32 changes: 18 additions & 14 deletions api/openapi.cloud.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11245,7 +11245,6 @@ components:
type: object
required:
- name
- id
- period
- invoiceAt
- type
Expand All @@ -11270,11 +11269,6 @@ components:
nullable: true
description: Additional metadata for the resource.
title: Metadata
id:
type: string
pattern: ^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$
description: ULID (Universally Unique Lexicographically Sortable Identifier).
example: 01G65Z755AFWAKHE12NY0CQ9FH
taxConfig:
allOf:
- $ref: '#/components/schemas/TaxConfig'
Expand Down Expand Up @@ -11313,7 +11307,15 @@ components:
- $ref: '#/components/schemas/InvoiceFlatFeeCategory'
description: Category of the flat fee.
default: regular
description: Resource update operation model.
id:
type: string
pattern: ^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$
description: The ID of the line.
example: 01G65Z755AFWAKHE12NY0CQ9FH
description: |-
InvoiceFlatFeeLineReplaceUpdate represents the update model for a flat fee invoice line.

This type makes ID optional to allow for creating new lines as part of the update.
InvoiceFlatFeePendingLineCreate:
type: object
required:
Expand Down Expand Up @@ -12186,7 +12188,6 @@ components:
type: object
required:
- name
- id
- period
- invoiceAt
- type
Expand All @@ -12211,11 +12212,6 @@ components:
nullable: true
description: Additional metadata for the resource.
title: Metadata
id:
type: string
pattern: ^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$
description: ULID (Universally Unique Lexicographically Sortable Identifier).
example: 01G65Z755AFWAKHE12NY0CQ9FH
taxConfig:
allOf:
- $ref: '#/components/schemas/TaxConfig'
Expand Down Expand Up @@ -12244,7 +12240,15 @@ components:
maxLength: 64
pattern: ^[a-z0-9]+(?:_[a-z0-9]+)*$
description: The feature that the usage is based on.
description: Resource update operation model.
id:
type: string
pattern: ^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$
description: The ID of the line.
example: 01G65Z755AFWAKHE12NY0CQ9FH
description: |-
InvoiceUpdateUsageBasedLineReplaceUpdate represents the update model for an UBP invoice line.

This type makes ID optional to allow for creating new lines as part of the update.
InvoiceUsageBasedPendingLineCreate:
type: object
required:
Expand Down
32 changes: 18 additions & 14 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11011,7 +11011,6 @@ components:
type: object
required:
- name
- id
- period
- invoiceAt
- type
Expand All @@ -11036,11 +11035,6 @@ components:
nullable: true
description: Additional metadata for the resource.
title: Metadata
id:
type: string
pattern: ^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$
description: ULID (Universally Unique Lexicographically Sortable Identifier).
example: 01G65Z755AFWAKHE12NY0CQ9FH
taxConfig:
allOf:
- $ref: '#/components/schemas/TaxConfig'
Expand Down Expand Up @@ -11079,7 +11073,15 @@ components:
- $ref: '#/components/schemas/InvoiceFlatFeeCategory'
description: Category of the flat fee.
default: regular
description: Resource update operation model.
id:
type: string
pattern: ^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$
description: The ID of the line.
example: 01G65Z755AFWAKHE12NY0CQ9FH
description: |-
InvoiceFlatFeeLineReplaceUpdate represents the update model for a flat fee invoice line.

This type makes ID optional to allow for creating new lines as part of the update.
InvoiceFlatFeePendingLineCreate:
type: object
required:
Expand Down Expand Up @@ -11952,7 +11954,6 @@ components:
type: object
required:
- name
- id
- period
- invoiceAt
- type
Expand All @@ -11977,11 +11978,6 @@ components:
nullable: true
description: Additional metadata for the resource.
title: Metadata
id:
type: string
pattern: ^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$
description: ULID (Universally Unique Lexicographically Sortable Identifier).
example: 01G65Z755AFWAKHE12NY0CQ9FH
taxConfig:
allOf:
- $ref: '#/components/schemas/TaxConfig'
Expand Down Expand Up @@ -12010,7 +12006,15 @@ components:
maxLength: 64
pattern: ^[a-z0-9]+(?:_[a-z0-9]+)*$
description: The feature that the usage is based on.
description: Resource update operation model.
id:
type: string
pattern: ^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$
description: The ID of the line.
example: 01G65Z755AFWAKHE12NY0CQ9FH
description: |-
InvoiceUpdateUsageBasedLineReplaceUpdate represents the update model for an UBP invoice line.

This type makes ID optional to allow for creating new lines as part of the update.
InvoiceUsageBasedPendingLineCreate:
type: object
required:
Expand Down
42 changes: 40 additions & 2 deletions api/spec/src/billing/invoices/invoice.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,46 @@ union InvoiceLine {
@friendlyName("InvoiceLineReplaceUpdate")
@discriminator("type")
union InvoiceLineReplaceUpdate {
usageBased: Rest.Resource.ResourceReplaceModel<InvoiceUsageBasedLine>,
flatFee: Rest.Resource.ResourceReplaceModel<InvoiceFlatFeeLine>,
usageBased: InvoiceUsageBasedLineReplaceUpdate,
flatFee: InvoiceFlatFeeLineReplaceUpdate,
}

/**
* InvoiceUpdateUsageBasedLineReplaceUpdate represents the update model for an UBP invoice line.
*
* This type makes ID optional to allow for creating new lines as part of the update.
*/
@friendlyName("InvoiceUsageBasedLineReplaceUpdate")
model InvoiceUsageBasedLineReplaceUpdate {
...Rest.Resource.ResourceReplaceModel<OmitProperties<
InvoiceUsageBasedLine,
"id"
>>;

/**
* The ID of the line.
*/
@visibility(Lifecycle.Update)
id?: ULID;
}

/**
* InvoiceFlatFeeLineReplaceUpdate represents the update model for a flat fee invoice line.
*
* This type makes ID optional to allow for creating new lines as part of the update.
*/
@friendlyName("InvoiceFlatFeeLineReplaceUpdate")
model InvoiceFlatFeeLineReplaceUpdate {
...Rest.Resource.ResourceReplaceModel<OmitProperties<
InvoiceFlatFeeLine,
"id"
>>;

/**
* The ID of the line.
*/
@visibility(Lifecycle.Update)
id?: ULID;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions openmeter/billing/httpdriver/invoiceline.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,9 +637,9 @@ func getIDFromLineReplace(line api.InvoiceLineReplaceUpdate) (string, error) {

switch v := value.(type) {
case api.InvoiceFlatFeeLineReplaceUpdate:
return v.Id, nil
return lo.FromPtrOr(v.Id, ""), nil
case api.InvoiceUsageBasedLineReplaceUpdate:
return v.Id, nil
return lo.FromPtrOr(v.Id, ""), nil
default:
return "", fmt.Errorf("unknown line type: %T", value)
}
Expand Down

0 comments on commit 522d75c

Please sign in to comment.