Skip to content

Commit

Permalink
feat: add Plan API to TypeSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgacsal committed Oct 18, 2024
1 parent eb2d1cf commit 9893e38
Show file tree
Hide file tree
Showing 15 changed files with 5,191 additions and 2,268 deletions.
2,722 changes: 1,919 additions & 803 deletions api/api.gen.go

Large diffs are not rendered by default.

4,076 changes: 2,765 additions & 1,311 deletions api/openapi.yaml

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions api/spec/src/billing/invoices/invoice.tsp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import "@typespec/http";
import "@typespec/rest";
import "@typespec/openapi3";
import "../../ratecards.tsp";

using TypeSpec.Http;
using TypeSpec.Rest;
using TypeSpec.OpenAPI;

using OpenMeter.ProductCatalog;

namespace Invoices;

/**
Expand Down Expand Up @@ -282,7 +283,7 @@ model UnitPriceLine extends Line {
type: LineTypes.unitPrice;

@summary("Details about what is being sold.")
item: OpenMeter.RateCard;
item: RateCard;

@summary("Quantity of the item being sold.")
quantity: Numeric;
Expand Down
1 change: 1 addition & 0 deletions api/spec/src/billing/invoices/main.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "@typespec/openapi3";
import "@typespec/versioning";

import "../..";
import "../../productcatalog";

// Package Contents
import "./invoice.tsp";
Expand Down
22 changes: 22 additions & 0 deletions api/spec/src/cloud/main.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,25 @@ namespace OpenMeterCloud.Billing {
@tag("Billing (Experimental)")
interface CustomerInvoiceEndpoints extends OpenMeter.Billing.CustomerInvoiceEndpoints {}
}

namespace OpenMeterCloud.ProductCatalog {
@route("/api/v1/plans")
@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 {}
}
86 changes: 0 additions & 86 deletions api/spec/src/discounts.tsp

This file was deleted.

1 change: 1 addition & 0 deletions api/spec/src/main.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import "./debug.tsp";
import "./notification";
import "./entitlements";
import "./billing";
import "./productcatalog";

using TypeSpec.Http;
using TypeSpec.Rest;
Expand Down
86 changes: 86 additions & 0 deletions api/spec/src/productcatalog/discounts.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
namespace OpenMeter.ProductCatalog;

/**
* The type of the discount.
*/
@friendlyName("DiscountType")
enum DiscountType {
percentage: "percentage",
amount: "amount",
usage: "usage",
}

/**
* A discount on a price.
* One of: percentage, amount, or usage.
*/
@discriminator("type")
@friendlyName("Discount")
union Discount {
@summary("Percentage discount")
percentage: DiscountPercentage,

// @summary("Amount discount")
// amount: DiscountAmount,

// @summary("Usage discount")
// usage: DiscountUsage,
}

/**
* Percentage discount.
*/
@friendlyName("DiscountPercentage")
model DiscountPercentage {
/**
* The type of the discount.
*/
@summary("Type")
type: DiscountType.percentage;

/**
* The percentage of the discount.
*/
@summary("Percentage")
@minValue(0)
@maxValue(100)
percentage: float;
}

// NOTE(chrisgacsal): amount discount is going to be implemented in future releases
// /**
// * Amount discount.
// */
// @friendlyName("DiscountAmount")
// model DiscountAmount {
// /**
// * The type of the discount.
// */
// @summary("Type")
// type: DiscountType.amount;

// /**
// * The amount of the discount.
// */
// @summary("Amount")
// amount: Money;
// }

// NOTE(chrisgacsal): usage discount is going to be implemented in future releases
// /**
// * Usage discount.
// */
// @friendlyName("UsageDiscount")
// model DiscountUsage {
// /**
// * The type of the discount.
// */
// @summary("Type")
// type: DiscountType.usage;

// /**
// * The usage discount.
// */
// @summary("Usage")
// usage: float64;
// }
14 changes: 14 additions & 0 deletions api/spec/src/productcatalog/main.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import "@typespec/http";
import "@typespec/openapi";
import "@typespec/openapi3";

import "..";

// Package Contents
import "./discounts.tsp";
import "./plan.tsp";
import "./prices.tsp";
import "./ratecards.tsp";
import "./routes.tsp";

namespace OpenMeter.ProductCatalog;
Loading

0 comments on commit 9893e38

Please sign in to comment.