Skip to content

Commit

Permalink
Merge pull request #1707 from openmeterio/chore/typespec-prettier
Browse files Browse the repository at this point in the history
chore(api): update typespec prettier config
  • Loading branch information
tothandras authored Oct 18, 2024
2 parents 53be8ed + 977f2e1 commit 4c578ce
Show file tree
Hide file tree
Showing 23 changed files with 190 additions and 51 deletions.
2 changes: 1 addition & 1 deletion api/spec/.prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"arrowParens": "always",
"bracketSameLine": false,
"tabWidth": 2,
"printWidth": 120,
"printWidth": 80,
"semi": false,
"singleQuote": true,
"trailingComma": "all",
Expand Down
5 changes: 4 additions & 1 deletion api/spec/lib/rules/casing.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ export const casingRule = createRule({
},
enum: (node) => {
for (const variant of node.members.values()) {
if (typeof variant.name === 'string' && !isSnakeCase(variant.value || variant.name)) {
if (
typeof variant.name === 'string' &&
!isSnakeCase(variant.value || variant.name)
) {
context.reportDiagnostic({
target: variant,
format: {
Expand Down
15 changes: 12 additions & 3 deletions api/spec/lib/rules/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ export const docDecoratorRule = createRule({
},
create: (context) => ({
model: (target) => {
if (target.name && !target.decorators.find((d) => d.decorator?.name === '$docFromComment')) {
if (
target.name &&
!target.decorators.find((d) => d.decorator?.name === '$docFromComment')
) {
context.reportDiagnostic({
target,
format: {
Expand All @@ -19,7 +22,10 @@ export const docDecoratorRule = createRule({
}
},
enum: (target) => {
if (target.name && !target.decorators.find((d) => d.decorator?.name === '$docFromComment')) {
if (
target.name &&
!target.decorators.find((d) => d.decorator?.name === '$docFromComment')
) {
context.reportDiagnostic({
target,
format: {
Expand All @@ -29,7 +35,10 @@ export const docDecoratorRule = createRule({
}
},
union: (target) => {
if (target.name && !target.decorators.find((d) => d.decorator?.name === '$docFromComment')) {
if (
target.name &&
!target.decorators.find((d) => d.decorator?.name === '$docFromComment')
) {
context.reportDiagnostic({
target,
format: {
Expand Down
15 changes: 12 additions & 3 deletions api/spec/lib/rules/friendlyName.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ export const friendlyNameRule = createRule({
},
create: (context) => ({
model: (node) => {
if (node.name && !node.decorators.some((d) => d.decorator.name === '$friendlyName')) {
if (
node.name &&
!node.decorators.some((d) => d.decorator.name === '$friendlyName')
) {
context.reportDiagnostic({
format: {
type: node.kind,
Expand All @@ -21,7 +24,10 @@ export const friendlyNameRule = createRule({
}
},
enum: (node) => {
if (node.name && !node.decorators.some((d) => d.decorator.name === '$friendlyName')) {
if (
node.name &&
!node.decorators.some((d) => d.decorator.name === '$friendlyName')
) {
context.reportDiagnostic({
format: {
type: node.kind,
Expand All @@ -33,7 +39,10 @@ export const friendlyNameRule = createRule({
}
},
union: (node) => {
if (node.name && !node.decorators.some((d) => d.decorator.name === '$friendlyName')) {
if (
node.name &&
!node.decorators.some((d) => d.decorator.name === '$friendlyName')
) {
context.reportDiagnostic({
format: {
type: node.kind,
Expand Down
4 changes: 3 additions & 1 deletion api/spec/src/app/marketplace.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ interface Marketplace {
@get
@route("/listings/{type}/install/oauth2")
@operationId("marketplaceOAuth2InstallGetURL")
getOAuth2InstallURL(@path type: Type): OAuth2.ClientAppStartResponse | CommonErrors;
getOAuth2InstallURL(
@path type: Type,
): OAuth2.ClientAppStartResponse | CommonErrors;

/**
* Authorize OAuth2 code.
Expand Down
5 changes: 4 additions & 1 deletion api/spec/src/app/stripe.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ interface AppStripe {
@post
@route("/api/v1/apps/{id}/stripe/webhook")
@operationId("appStripeWebhook")
webhook(@path id: ULID, @body body: StripeWebhookEvent): StripeWebhookResponse | NotFoundError | CommonErrors;
webhook(
@path id: ULID,
@body body: StripeWebhookEvent,
): StripeWebhookResponse | NotFoundError | CommonErrors;

/**
* Create checkout session.
Expand Down
11 changes: 9 additions & 2 deletions api/spec/src/billing/invoices.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ interface CustomerInvoicesEndpoints {
@route("/items")
@summary("Create a new pending item")
@operationId("billingCreatePendingItemByCustomer")
createPendingItem(@path customerIdOrKey: ULIDOrKey, @body request: Invoices.InvoiceLine): {
createPendingItem(
@path customerIdOrKey: ULIDOrKey,
@body request: Invoices.InvoiceLine,
): {
@statusCode _: 201;
@body body: CreatePendingItemResponse;
} | OpenMeter.CommonErrors;
Expand Down Expand Up @@ -239,7 +242,11 @@ interface CustomerInvoiceEndpoints {
@route("/lines/{lineId}")
@summary("Delete an invoice line")
@operationId("billingDeleteInvoiceLine")
deleteInvoiceLine(@path customerIdOrKey: ULIDOrKey, @path invoiceId: ULID, @path lineId: ULID): {
deleteInvoiceLine(
@path customerIdOrKey: ULIDOrKey,
@path invoiceId: ULID,
@path lineId: ULID,
): {
@statusCode _: 204;
} | OpenMeter.NotFoundError | OpenMeter.CommonErrors;

Expand Down
4 changes: 3 additions & 1 deletion api/spec/src/billing/profile.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ interface Profiles {
@get
@summary("Get a billing profile by ID")
@operationId("billingGetProfile")
get(@path id: string): Profile | OpenMeter.NotFoundError | OpenMeter.CommonErrors;
get(
@path id: string,
): Profile | OpenMeter.NotFoundError | OpenMeter.CommonErrors;

/**
* Update a billing profile
Expand Down
16 changes: 11 additions & 5 deletions api/spec/src/cloud/main.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ interface Meters extends OpenMeter.Meters {
*/
@delete
@operationId("deleteMeter")
delete(@path meterIdOrSlug: OpenMeter.MeterIdentifier): void | OpenMeter.CommonErrors;
delete(
@path meterIdOrSlug: OpenMeter.MeterIdentifier,
): void | OpenMeter.CommonErrors;
}

namespace OpenMeterCloud.Portal {
Expand Down Expand Up @@ -129,7 +131,8 @@ namespace OpenMeterCloud.Notification {

@route("/api/v1/notification/webhook/svix")
@tag("Notification (Experimental)")
interface SvixOperationalWebhooks extends OpenMeter.Notification.SvixOperationalWebhooks {}
interface SvixOperationalWebhooks
extends OpenMeter.Notification.SvixOperationalWebhooks {}
}

namespace OpenMeterCloud.Entitlements {
Expand Down Expand Up @@ -169,11 +172,13 @@ namespace OpenMeterCloud.Billing {

@route("/api/v1/billing/invoices/{customerIdOrKey}")
@tag("Billing (Experimental)")
interface CustomerInvoicesEndpoints extends OpenMeter.Billing.CustomerInvoicesEndpoints {}
interface CustomerInvoicesEndpoints
extends OpenMeter.Billing.CustomerInvoicesEndpoints {}

@route("/api/v1/billing/invoices/{customerIdOrKey}/invoices/{invoiceId}")
@tag("Billing (Experimental)")
interface CustomerInvoiceEndpoints extends OpenMeter.Billing.CustomerInvoiceEndpoints {}
interface CustomerInvoiceEndpoints
extends OpenMeter.Billing.CustomerInvoiceEndpoints {}
}

namespace OpenMeterCloud.ProductCatalog {
Expand All @@ -191,7 +196,8 @@ namespace OpenMeterCloud.ProductCatalog {

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

@route("/api/v1/plans/{planId}/phases")
@tag("Plan (Experimental)")
Expand Down
8 changes: 6 additions & 2 deletions api/spec/src/cloud/subjects.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ interface Subjects {
*/
@get
@operationId("getSubject")
get(@path subjectIdOrKey: string): OpenMeter.Subject | OpenMeter.NotFoundError | OpenMeter.CommonErrors;
get(
@path subjectIdOrKey: string,
): OpenMeter.Subject | OpenMeter.NotFoundError | OpenMeter.CommonErrors;

/**
* Upserts a subject. Creates or updates subject.
Expand All @@ -33,7 +35,9 @@ interface Subjects {
*/
@post
@operationId("upsertSubject")
upsert(@body subject: SubjectUpsert[]): OpenMeter.Subject[] | OpenMeter.CommonErrors;
upsert(
@body subject: SubjectUpsert[],
): OpenMeter.Subject[] | OpenMeter.CommonErrors;

/**
* Delete subject by ID or key.
Expand Down
13 changes: 10 additions & 3 deletions api/spec/src/customer.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,30 @@ interface Customers {
@get
@route("/{customerIdOrKey}")
@operationId("getCustomer")
get(@path customerIdOrKey: CustomerIdentifier): Customer | NotFoundError | CommonErrors;
get(
@path customerIdOrKey: CustomerIdentifier,
): Customer | NotFoundError | CommonErrors;

/**
* Update a customer by ID or key.
*/
@put
@route("/{customerIdOrKey}")
@operationId("updateCustomer")
update(@path customerIdOrKey: CustomerIdentifier, @body customer: Customer): Customer | NotFoundError | CommonErrors;
update(
@path customerIdOrKey: CustomerIdentifier,
@body customer: Customer,
): Customer | NotFoundError | CommonErrors;

/**
* Delete a customer by ID or key.
*/
@delete
@route("/{customerIdOrKey}")
@operationId("deleteCustomer")
delete(@path customerIdOrKey: CustomerIdentifier): Customer | NotFoundError | CommonErrors;
delete(
@path customerIdOrKey: CustomerIdentifier,
): Customer | NotFoundError | CommonErrors;
}

/**
Expand Down
29 changes: 24 additions & 5 deletions api/spec/src/entitlements/entitlements.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,10 @@ union EntitlementCreateInputs {
@friendlyName("EntitlementBaseTemplate")
model EntitlementSharedFields {
...ResourceTimestamps;
...OmitProperties<EntitlementCreateSharedFields, "featureKey" | "featureId" | "usagePeriod">;
...OmitProperties<
EntitlementCreateSharedFields,
"featureKey" | "featureId" | "usagePeriod"
>;

/**
* Readonly unique ULID identifier.
Expand Down Expand Up @@ -308,9 +311,19 @@ model EntitlementMetered {
type: EntitlementType.metered;
...OmitProperties<
EntitlementMeteredCreateInputs,
"type" | "measureUsageFrom" | "metadata" | "usagePeriod" | "featureKey" | "featureId" | "currentUsagePeriod"

| "type"
| "measureUsageFrom"
| "metadata"
| "usagePeriod"
| "featureKey"
| "featureId"
| "currentUsagePeriod"
>;
...OmitProperties<
EntitlementSharedFields,
"type" | "currentUsagePeriod" | "usagePeriod"
>;
...OmitProperties<EntitlementSharedFields, "type" | "currentUsagePeriod" | "usagePeriod">;
...EntitlementMeteredCalculatedFields;
}

Expand All @@ -320,7 +333,10 @@ model EntitlementMetered {
@friendlyName("EntitlementBoolean")
model EntitlementBoolean extends EntitlementSharedFields {
type: EntitlementType.boolean;
...OmitProperties<EntitlementBooleanCreateInputs, "type" | "metadata" | "usagePeriod" | "featureKey" | "featureId">;
...OmitProperties<
EntitlementBooleanCreateInputs,
"type" | "metadata" | "usagePeriod" | "featureKey" | "featureId"
>;
...OmitProperties<EntitlementSharedFields, "type">;
}

Expand All @@ -330,7 +346,10 @@ model EntitlementBoolean extends EntitlementSharedFields {
@friendlyName("EntitlementStatic")
model EntitlementStatic {
type: EntitlementType.static;
...OmitProperties<EntitlementStaticCreateInputs, "type" | "metadata" | "usagePeriod" | "featureKey" | "featureId">;
...OmitProperties<
EntitlementStaticCreateInputs,
"type" | "metadata" | "usagePeriod" | "featureKey" | "featureId"
>;
...OmitProperties<EntitlementSharedFields, "type">;
}

Expand Down
4 changes: 3 additions & 1 deletion api/spec/src/entitlements/feature.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ interface Features {
*/
@get
@operationId("getFeature")
get(@path featureId: string): Feature | OpenMeter.NotFoundError | OpenMeter.CommonErrors;
get(
@path featureId: string,
): Feature | OpenMeter.NotFoundError | OpenMeter.CommonErrors;

/**
* Archive a feature by ID.
Expand Down
22 changes: 18 additions & 4 deletions api/spec/src/entitlements/subjects.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ interface Subjects {
@post
@summary("Create an entitlement")
@operationId("createEntitlement")
post(@path subjectIdOrKey: string, @body entitlement: EntitlementCreateInputs): {
post(
@path subjectIdOrKey: string,
@body entitlement: EntitlementCreateInputs,
): {
@statusCode _: 201;
@body body: EntitlementCreateInputs;
} | OpenMeter.CommonErrors | OpenMeter.ConflictError;
Expand All @@ -36,7 +39,10 @@ interface Subjects {
*/
@get
@operationId("listSubjectEntitlements")
list(@path subjectIdOrKey: string, @query includeDeleted?: boolean = false): Entitlement[] | OpenMeter.CommonErrors;
list(
@path subjectIdOrKey: string,
@query includeDeleted?: boolean = false,
): Entitlement[] | OpenMeter.CommonErrors;

/**
* Get entitlement by id. For checking entitlement access, use the /value endpoint instead.
Expand Down Expand Up @@ -108,7 +114,11 @@ interface Subjects {
@post
@operationId("createGrant")
@route("/{entitlementIdOrFeatureKey}/grants")
createGrant(@path subjectIdOrKey: string, @path entitlementIdOrFeatureKey: string, @body grant: GrantCreateInput): {
createGrant(
@path subjectIdOrKey: string,
@path entitlementIdOrFeatureKey: string,
@body grant: GrantCreateInput,
): {
@statusCode _: 201;
@body body: Grant;
} | OpenMeter.CommonErrors | OpenMeter.ConflictError;
Expand Down Expand Up @@ -171,7 +181,11 @@ interface Subjects {
@post
@operationId("resetEntitlementUsage")
@route("/{entitlementId}/reset")
reset(@path subjectIdOrKey: string, @path entitlementId: string, @body reset: ResetEntitlementUsageInput): {
reset(
@path subjectIdOrKey: string,
@path entitlementId: string,
@body reset: ResetEntitlementUsageInput,
): {
@statusCode _: 204;
} | OpenMeter.CommonErrors | OpenMeter.NotFoundError;
}
Expand Down
10 changes: 8 additions & 2 deletions api/spec/src/events.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,21 @@ interface Events {
@post
@operationId("ingestEvents")
@sharedRoute
ingestEvent(@header contentType: "application/cloudevents+json", @body body: Event): {
ingestEvent(
@header contentType: "application/cloudevents+json",
@body body: Event,
): {
@header contentType: "application/cloudevents+json";
@body _: Event;
} | CommonErrors;

@post
@operationId("ingestEvents")
@sharedRoute
ingestEvents(@header contentType: "application/cloudevents-batch+json", @body body: Event[]): {
ingestEvents(
@header contentType: "application/cloudevents-batch+json",
@body body: Event[],
): {
@header contentType: "application/cloudevents-batch+json";
@body _: Event[];
} | CommonErrors;
Expand Down
Loading

0 comments on commit 4c578ce

Please sign in to comment.