Skip to content

Commit

Permalink
Merge pull request #1584 from openmeterio/typespec-fixes
Browse files Browse the repository at this point in the history
TypeSpec fixes
  • Loading branch information
sagikazarmark authored Sep 28, 2024
2 parents d64ea4e + 4aa21aa commit b2b088a
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 14 deletions.
4 changes: 4 additions & 0 deletions api/spec/src/cloud/main.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,7 @@ namespace OpenMeterCloud.Entitlements {
@tag("Entitlements (Experimental)")
interface Subjects extends OpenMeter.Entitlements.Subjects {}
}

@route("/api/v1/customers")
@tag("Customers")
interface Customers extends OpenMeter.Customers {}
9 changes: 8 additions & 1 deletion api/spec/src/cloud/subjects.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,15 @@ interface Subjects {
* If the subject exists, it will be partially updated with the provided fields.
*/
@post
@operationId("listSubjects")
@operationId("upsertSubject")
upsert(@body subject: Subject[]): Subject[] | OpenMeter.CommonErrors;

/**
* Delete subject by ID or key.
*/
@delete
@operationId("deleteSubject")
delete(@path subjectIdOrKey: string): void | OpenMeter.CommonErrors;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion api/spec/src/entitlements/subjects.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ interface Subjects {
/**
* Windowsize
*/
@query windowSize?: OpenMeter.WindowSize,
@query windowSize: OpenMeter.WindowSize,

/**
* The timezone used when calculating the windows.
Expand Down
16 changes: 8 additions & 8 deletions api/spec/src/events.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface Events {
*/
@query
@example(utcDateTime.fromISO("2023-01-01T00:00:00Z"))
ingestedAtFrom: utcDateTime,
ingestedAtFrom?: utcDateTime,

/**
* End date-time in RFC 3339 format.
Expand All @@ -36,7 +36,7 @@ interface Events {
*/
@query
@example(utcDateTime.fromISO("2023-01-01T00:00:00Z"))
ingestedAtTo: utcDateTime,
ingestedAtTo?: utcDateTime,

/**
* If not provided lists all events.
Expand All @@ -47,7 +47,7 @@ interface Events {
*/
@query
@example(false)
hasError: boolean,
hasError?: boolean,

/**
* The event ID.
Expand All @@ -56,7 +56,7 @@ interface Events {
*/
@query
@example("my-event-id")
id: string,
id?: string,

/**
* The event subject.
Expand All @@ -65,7 +65,7 @@ interface Events {
*/
@query
@example("customer-1")
subject: string,
subject?: string,

/**
* Start date-time in RFC 3339 format.
Expand All @@ -74,7 +74,7 @@ interface Events {
*/
@query
@example(utcDateTime.fromISO("2023-01-01T00:00:00Z"))
from: utcDateTime,
from?: utcDateTime,

/**
* End date-time in RFC 3339 format.
Expand All @@ -83,7 +83,7 @@ interface Events {
*/
@query
@example(utcDateTime.fromISO("2023-01-01T00:00:00Z"))
to: utcDateTime,
to?: utcDateTime,

/**
* Number of events to return.
Expand All @@ -92,7 +92,7 @@ interface Events {
@minValue(1)
@maxValue(100)
@example(100)
limit: integer = 100,
limit?: integer = 100,
): IngestedEvent[] | CommonErrors;

@post
Expand Down
4 changes: 2 additions & 2 deletions api/spec/src/notification/rule.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ interface Rules {
*/
@query
@example(true)
includeDeleted?: boolean,
includeDeleted?: boolean = false,

/**
* Include disabled notification rules in response.
Expand All @@ -232,7 +232,7 @@ interface Rules {
*/
@query
@example(false)
includeDisabled?: boolean,
includeDisabled?: boolean = false,

// TODO(chrisgacsal): figure out if there is a way to use union type for attribute like this
// where the code generation results a less complicated/more idiomatic code.
Expand Down
8 changes: 6 additions & 2 deletions api/spec/src/portal.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ interface Meters {
@route("/{meterSlug}/query")
@operationId("queryPortalMeter")
@sharedRoute
queryJson(@path meterSlug: Key, ...OpenMeter.MeterQuery, @header accept?: "application/json" = "application/json"): {
queryJson(
@path meterSlug: Key,
...OmitProperties<OpenMeter.MeterQuery, "subject">,
@header accept?: "application/json" = "application/json",
): {
@header contentType: "application/json";
@body _: MeterQueryResult;
} | NotFoundError | CommonErrors;
Expand All @@ -89,7 +93,7 @@ interface Meters {
@route("/{meterSlug}/query")
@operationId("queryPortalMeter")
@sharedRoute
queryCsv(@path meterSlug: Key, ...OpenMeter.MeterQuery, @header accept?: "text/csv"): {
queryCsv(@path meterSlug: Key, ...OmitProperties<OpenMeter.MeterQuery, "subject">, @header accept?: "text/csv"): {
@header contentType: "text/csv";

@body
Expand Down

0 comments on commit b2b088a

Please sign in to comment.