Skip to content

Commit

Permalink
fix(api): fix plan update & rate card mapping
Browse files Browse the repository at this point in the history
* feat(api): fix PUT plan body type & remove timestamps from nested models

* fix(api): fix plan update & rate card mapping
  • Loading branch information
tothandras authored Nov 18, 2024
1 parent 18f7a67 commit 62c1165
Show file tree
Hide file tree
Showing 16 changed files with 2,143 additions and 2,145 deletions.
1,496 changes: 734 additions & 762 deletions api/api.gen.go

Large diffs are not rendered by default.

1,514 changes: 743 additions & 771 deletions api/client/go/client.gen.go

Large diffs are not rendered by default.

221 changes: 82 additions & 139 deletions api/client/node/schemas/openapi.ts

Large diffs are not rendered by default.

213 changes: 78 additions & 135 deletions api/client/web/src/client/openapi.ts

Large diffs are not rendered by default.

268 changes: 130 additions & 138 deletions api/openapi.cloud.yaml

Large diffs are not rendered by default.

270 changes: 132 additions & 138 deletions api/openapi.yaml

Large diffs are not rendered by default.

26 changes: 23 additions & 3 deletions api/spec/src/productcatalog/plan.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,34 @@ model Plan {
*/
@friendlyName("PlanPhase")
model PlanPhase {
...OmitProperties<Resource, "id">;

/**
* Unique key among the plan phases. Used to reference the phase in the subscription & plan.
* A semi-unique identifier for the resource.
*/
@visibility("read", "create")
@summary("Key")
key: Key;

/**
* Human-readable name for the resource. Between 1 and 256 characters.
*/
@summary("Display name")
@minLength(1)
@maxLength(256)
name: string;

/**
* Optional description of the resource. Maximum 1024 characters.
*/
@maxLength(1024)
@summary("Description")
description?: string;

/**
* Additional metadata for the resource.
*/
@summary("Metadata")
metadata?: Metadata | null;

/**
* The rate cards of the plan.
*/
Expand Down
30 changes: 28 additions & 2 deletions api/spec/src/productcatalog/ratecards.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,41 @@ enum RateCardType {
*/
@friendlyName("RateCardBase")
model RateCardBase<T extends RateCardType> {
...OmitProperties<UniqueResource, "id">;

/**
* The type of the RateCard.
*/
@visibility("read", "create", "update")
@summary("RateCard type")
type: T;

/**
* A semi-unique identifier for the resource.
*/
@visibility("read", "create")
@summary("Key")
key: Key;

/**
* Human-readable name for the resource. Between 1 and 256 characters.
*/
@summary("Display name")
@minLength(1)
@maxLength(256)
name: string;

/**
* Optional description of the resource. Maximum 1024 characters.
*/
@maxLength(1024)
@summary("Description")
description?: string;

/**
* Additional metadata for the resource.
*/
@summary("Metadata")
metadata?: Metadata | null;

/**
* The feature the customer is entitled to use.
*/
Expand Down
13 changes: 6 additions & 7 deletions api/spec/src/productcatalog/routes.tsp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import "../rest.tsp";

namespace OpenMeter.ProductCatalog;

using TypeSpec.Http;
Expand All @@ -11,7 +13,7 @@ interface Plans {
/**
* List all plans.
*/
@get
@list
@operationId("listPlans")
@summary("List plans")
@extension("x-internal", true)
Expand Down Expand Up @@ -56,7 +58,7 @@ interface Plans {
@extension("x-internal", true)
create(@body request: TypeSpec.Rest.Resource.ResourceCreateModel<Plan>): {
@statusCode _: 201;
@bodyRoot body: Plan;
@body body: Plan;
} | OpenMeter.CommonErrors;

/**
Expand All @@ -68,7 +70,7 @@ interface Plans {
@extension("x-internal", true)
update(
@path planId: ULID,
@body request: TypeSpec.Rest.Resource.ResourceCreateOrUpdateModel<Plan>,
@body request: TypeSpec.Rest.Resource.ResourceReplaceModel<Plan>,
): Plan | OpenMeter.NotFoundError | OpenMeter.CommonErrors;

/**
Expand Down Expand Up @@ -111,7 +113,6 @@ interface Plans {
*/
@post
@route("/{planId}/publish")
@sharedRoute
@operationId("publishPlan")
@summary("Publish plan")
@extension("x-internal", true)
Expand All @@ -124,7 +125,6 @@ interface Plans {
*/
@post
@route("/{planId}/archive")
@sharedRoute
@operationId("archivePlan")
@summary("Archive plan version")
@extension("x-internal", true)
Expand All @@ -138,7 +138,6 @@ interface Plans {
*/
@post
@route("/{planIdOrKey}/next")
@sharedRoute
@operationId("nextPlan")
@summary("New draft plan")
@extension("x-internal", true)
Expand All @@ -148,7 +147,7 @@ interface Plans {
planIdOrKey: PlanIdOrKey,
): {
@statusCode _: 201;
@bodyRoot body: Plan;
@body body: Plan;
} | OpenMeter.NotFoundError | OpenMeter.CommonErrors;
}

Expand Down
3 changes: 3 additions & 0 deletions api/spec/src/query.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ model QueryPagination {
@query
@minValue(1)
@example(1)
@pageIndex
page?: integer = 1;

/**
Expand All @@ -32,6 +33,7 @@ model QueryPagination {
@minValue(1)
@maxValue(1000)
@example(100)
@pageSize
pageSize?: integer = 100;
}

Expand Down Expand Up @@ -122,5 +124,6 @@ model PaginatedResponse<T> {
/**
* The items in the current page.
*/
@pageItems
items: T[];
}
11 changes: 11 additions & 0 deletions api/spec/src/rest.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import "@typespec/rest";

namespace TypeSpec.Rest.Resource {
/**
* Resource update operation model.
* @template Resource The resource model to update with replace.
*/
@friendlyName("{name}ReplaceUpdate", Resource)
model ResourceReplaceModel<Resource extends {}>
is UpdateableProperties<DefaultKeyVisibility<Resource, "read">>;
}
2 changes: 1 addition & 1 deletion api/spec/src/types.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ model Resource {
* Additional metadata for the resource.
*/
@summary("Metadata")
metadata?: Metadata; // FIXME: linter error for: = #{};
metadata?: Metadata | null;

...ResourceTimestamps;
}
Expand Down
1 change: 1 addition & 0 deletions openmeter/productcatalog/plan/adapter/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ func (a *adapter) UpdatePlan(ctx context.Context, params plan.UpdatePlanInput) (
if len(diffResult.Update) > 0 {
for _, updateInput := range diffResult.Update {
updateInput.Namespace = params.Namespace
updateInput.PlanID = p.ID

phase, err := a.UpdatePhase(ctx, updateInput)
if err != nil {
Expand Down
Loading

0 comments on commit 62c1165

Please sign in to comment.