Skip to content

Commit

Permalink
Merge pull request #1743 from openmeterio/refactor/plan-api
Browse files Browse the repository at this point in the history
refactor: Plan API typespec
  • Loading branch information
chrisgacsal authored Oct 23, 2024
2 parents 5cef1dc + 2138c6e commit feb07ed
Show file tree
Hide file tree
Showing 8 changed files with 1,662 additions and 1,605 deletions.
1,287 changes: 631 additions & 656 deletions api/api.gen.go

Large diffs are not rendered by default.

1,717 changes: 911 additions & 806 deletions api/client/go/client.gen.go

Large diffs are not rendered by default.

185 changes: 78 additions & 107 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4725,22 +4725,33 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/PlanCreate'
/api/v1/plans/{planId}:
put:
operationId: updatePlan
summary: Update a plan
description: Update plan by id.
/api/v1/plans/{planIdOrKey}/next:
post:
operationId: newDraftPlan
summary: New draft plan
description: |-
Create a new draft version from plan.
It returns error if there is already a plan in draft or planId does not reference the latest published version.
parameters:
- name: planId
- name: planIdOrKey
in: path
required: true
schema:
type: string
example: 01G65Z755AFWAKHE12NY0CQ9FH
pattern: ^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$
anyOf:
- type: string
example: 01G65Z755AFWAKHE12NY0CQ9FH
pattern: ^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$
description: ULID (Universally Unique Lexicographically Sortable Identifier).
- type: string
minLength: 1
maxLength: 64
pattern: ^[a-z0-9]+(?:_[a-z0-9]+)*$
description: A key is a unique string that is used to identify a resource.
x-go-type: string
x-go-type: string
responses:
'200':
description: The request has succeeded.
'201':
description: The request has succeeded and a new resource has been created as a result.
content:
application/json:
schema:
Expand Down Expand Up @@ -4789,33 +4800,19 @@ paths:
$ref: '#/components/schemas/UnexpectedProblemResponse'
tags:
- Plan (Experimental)
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/PlanUpdate'
get:
operationId: getPlan
summary: Get plan
description: Get a plan by id or key. The latest published version is returned if latter is used.
/api/v1/plans/{planId}:
put:
operationId: updatePlan
summary: Update a plan
description: Update plan by id.
parameters:
- name: planId
in: path
required: true
schema:
anyOf:
- type: string
example: 01G65Z755AFWAKHE12NY0CQ9FH
pattern: ^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$
description: ULID (Universally Unique Lexicographically Sortable Identifier).
- type: string
minLength: 1
maxLength: 64
pattern: ^[a-z0-9]+(?:_[a-z0-9]+)*$
description: A key is a unique string that is used to identify a resource.
x-go-type: string
x-go-type: string
type: string
example: 01G65Z755AFWAKHE12NY0CQ9FH
pattern: ^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$
responses:
'200':
description: The request has succeeded.
Expand Down Expand Up @@ -4867,24 +4864,40 @@ paths:
$ref: '#/components/schemas/UnexpectedProblemResponse'
tags:
- Plan (Experimental)
delete:
operationId: deletePlan
summary: Delete plan
description: |-
Soft delete plan by plan.id.
Once a plan is deleted it cannot be undeleted.
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/PlanUpdate'
get:
operationId: getPlan
summary: Get plan
description: Get a plan by id or key. The latest published version is returned if latter is used.
parameters:
- name: planId
in: path
required: true
schema:
type: string
example: 01G65Z755AFWAKHE12NY0CQ9FH
pattern: ^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$
anyOf:
- type: string
example: 01G65Z755AFWAKHE12NY0CQ9FH
pattern: ^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$
description: ULID (Universally Unique Lexicographically Sortable Identifier).
- type: string
minLength: 1
maxLength: 64
pattern: ^[a-z0-9]+(?:_[a-z0-9]+)*$
description: A key is a unique string that is used to identify a resource.
x-go-type: string
x-go-type: string
responses:
'204':
description: 'There is no content to send for this request, but the headers may be useful. '
'200':
description: The request has succeeded.
content:
application/json:
schema:
$ref: '#/components/schemas/Plan'
'400':
description: The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
content:
Expand Down Expand Up @@ -4929,37 +4942,24 @@ paths:
$ref: '#/components/schemas/UnexpectedProblemResponse'
tags:
- Plan (Experimental)
/api/v1/plans/{planId}/next:
post:
operationId: newDraftPlan
summary: New draft plan
delete:
operationId: deletePlan
summary: Delete plan
description: |-
Create a new draft version from plan.
It returns error if there is already a plan in draft or planId does not reference the latest published version.
Soft delete plan by plan.id.
Once a plan is deleted it cannot be undeleted.
parameters:
- name: planId
in: path
required: true
schema:
anyOf:
- type: string
example: 01G65Z755AFWAKHE12NY0CQ9FH
pattern: ^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$
description: ULID (Universally Unique Lexicographically Sortable Identifier).
- type: string
minLength: 1
maxLength: 64
pattern: ^[a-z0-9]+(?:_[a-z0-9]+)*$
description: A key is a unique string that is used to identify a resource.
x-go-type: string
x-go-type: string
type: string
example: 01G65Z755AFWAKHE12NY0CQ9FH
pattern: ^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$
responses:
'201':
description: The request has succeeded and a new resource has been created as a result.
content:
application/json:
schema:
$ref: '#/components/schemas/Plan'
'204':
description: 'There is no content to send for this request, but the headers may be useful. '
'400':
description: The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
content:
Expand Down Expand Up @@ -9040,32 +9040,6 @@ components:
Mapping to attribute metered usage to the customer.
One customer can have multiple subjects,
but one subject can only belong to one customer.
Discount:
type: object
allOf:
- $ref: '#/components/schemas/DiscountPercentage'
description: |-
A discount on a price.
One of: percentage, amount, or usage.
DiscountPercentage:
type: object
required:
- type
- percentage
properties:
type:
type: string
enum:
- percentage
description: The type of the discount.
title: Type
percentage:
type: number
minimum: 0
maximum: 100
description: The percentage of the discount.
title: Percentage
description: Percentage discount.
Entitlement:
anyOf:
- $ref: '#/components/schemas/EntitlementMetered'
Expand Down Expand Up @@ -12071,7 +12045,7 @@ components:
enum:
- flat_fee
description: The type of the RateCard.
title: Channel Type
title: RateCard type
featureKey:
type: string
minLength: 1
Expand All @@ -12097,9 +12071,7 @@ components:
type: string
format: duration
nullable: true
description: |-
The billing cadence of the rate card.
When null, the rate card is a one-time purchase.
description: The billing cadence of the rate card.
title: Billing cadence
price:
type: object
Expand Down Expand Up @@ -12159,7 +12131,7 @@ components:
description: |-
The interval of the metered entitlement.
Defaults to the billing cadence of the rate card.
title: Interval
title: Usage Period
description: The entitlement template with a metered entitlement.
RateCardStaticEntitlement:
type: object
Expand Down Expand Up @@ -12241,7 +12213,7 @@ components:
enum:
- usage_based
description: The type of the RateCard.
title: Channel Type
title: RateCard type
featureKey:
type: string
minLength: 1
Expand All @@ -12266,7 +12238,9 @@ components:
billingCadence:
type: string
format: duration
description: The billing cadence of the rate card.
description: |-
The billing cadence of the rate card.
When null, the rate card is a one-time purchase.
title: Billing cadence
price:
anyOf:
Expand All @@ -12287,11 +12261,6 @@ components:
The price of the rate card.
When null, the feature or service is free.
title: Price
discount:
allOf:
- $ref: '#/components/schemas/Discount'
description: The discount of the rate card.
title: Discount
description: A usage-based rate card defines a price based on usage.
RecurringPeriod:
type: object
Expand Down Expand Up @@ -12809,6 +12778,7 @@ components:
Defines if the tiering mode is volume-based or graduated:
- In `volume`-based tiering, the maximum quantity within a period determines the per unit price.
- In `graduated` tiering, pricing can change as the quantity grows.
title: Mode
tiers:
type: array
items:
Expand All @@ -12817,6 +12787,7 @@ components:
description: |-
The tiers of the tiered price.
At least one price component is required in each tier.
title: Tiers
minimumAmount:
allOf:
- $ref: '#/components/schemas/Numeric'
Expand Down
13 changes: 0 additions & 13 deletions api/spec/src/cloud/main.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,6 @@ namespace OpenMeterCloud.ProductCatalog {
@tag("Plan (Experimental)")
interface PlansById extends OpenMeter.ProductCatalog.Plans {}

@route("/api/v1/plans/{planId}/publish")
@tag("Plan (Experimental)")
interface PlanPublishById extends OpenMeter.ProductCatalog.PlanPublish {}

@route("/api/v1/plans/{planId}/unpublish")
@tag("Plan (Experimental)")
interface PlanUnpublishById extends OpenMeter.ProductCatalog.PlanUnpublish {}

@route("/api/v1/plans/{planId}/next")
@tag("Plan (Experimental)")
interface PlanNewDraftVersion
extends OpenMeter.ProductCatalog.PlanNewDraftVersion {}

@route("/api/v1/plans/{planId}/phases")
@tag("Plan (Experimental)")
interface PlanByIdPhases extends OpenMeter.ProductCatalog.PlanPhases {}
Expand Down
6 changes: 4 additions & 2 deletions api/spec/src/productcatalog/discounts.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace OpenMeter.ProductCatalog;
@friendlyName("DiscountType")
enum DiscountType {
percentage: "percentage",
amount: "amount",
usage: "usage",
// amount: "amount",
// usage: "usage",
}

/**
Expand Down Expand Up @@ -35,12 +35,14 @@ model DiscountPercentage {
/**
* The type of the discount.
*/
@visibility("read", "create")
@summary("Type")
type: DiscountType.percentage;

/**
* The percentage of the discount.
*/
@visibility("read", "create", "update")
@summary("Percentage")
@minValue(0)
@maxValue(100)
Expand Down
Loading

0 comments on commit feb07ed

Please sign in to comment.