Skip to content

Commit 51d616a

Browse files
authored
chore(api): refactor names and patch typespec (#4411)
1 parent d0836b2 commit 51d616a

14 files changed

Lines changed: 2206 additions & 1121 deletions

File tree

api/spec/packages/aip/lib/rules/friendly-name.js

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createRule, paramMessage } from '@typespec/compiler'
1+
import { createRule, getFriendlyName, paramMessage } from '@typespec/compiler'
22

33
export const friendlyNameRule = createRule({
44
name: 'friendly-name',
@@ -10,9 +10,7 @@ export const friendlyNameRule = createRule({
1010
},
1111
create: (context) => ({
1212
interface: (node) => {
13-
const hasFriendlyName = node.decorators.some(
14-
(d) => d.decorator.name === '$friendlyName',
15-
)
13+
const hasFriendlyName = !!getFriendlyName(context.program, node)
1614
const isEndpointsOrOperations =
1715
node.name.endsWith('Endpoints') || node.name.endsWith('Operations')
1816

@@ -40,10 +38,7 @@ export const friendlyNameRule = createRule({
4038
}
4139
},
4240
model: (node) => {
43-
if (
44-
node.name &&
45-
!node.decorators.some((d) => d.decorator.name === '$friendlyName')
46-
) {
41+
if (node.name && !getFriendlyName(context.program, node)) {
4742
context.reportDiagnostic({
4843
format: {
4944
type: node.kind,
@@ -55,10 +50,7 @@ export const friendlyNameRule = createRule({
5550
}
5651
},
5752
enum: (node) => {
58-
if (
59-
node.name &&
60-
!node.decorators.some((d) => d.decorator.name === '$friendlyName')
61-
) {
53+
if (node.name && !getFriendlyName(context.program, node)) {
6254
context.reportDiagnostic({
6355
format: {
6456
type: node.kind,
@@ -70,10 +62,7 @@ export const friendlyNameRule = createRule({
7062
}
7163
},
7264
union: (node) => {
73-
if (
74-
node.name &&
75-
!node.decorators.some((d) => d.decorator.name === '$friendlyName')
76-
) {
65+
if (node.name && !getFriendlyName(context.program, node)) {
7766
context.reportDiagnostic({
7867
format: {
7968
type: node.kind,

api/spec/packages/aip/src/billing/tax.tsp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ model TaxConfig {
5151
* `stripe.code` is ignored.
5252
*/
5353
@summary("Tax code")
54-
tax_code?: Tax.TaxCodeReference;
54+
tax_code?: Shared.ResourceReference<Tax.TaxCode>;
5555
}
5656

5757
/**

api/spec/packages/aip/src/customers/credits/grant.tsp

Lines changed: 98 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ model CreditGrantTaxConfig {
109109
/**
110110
* Tax code applied to the invoice line item.
111111
*/
112-
tax_code?: Tax.TaxCodeReference;
112+
tax_code?: Shared.ResourceReference<Tax.TaxCode>;
113113
}
114114

115115
/**
@@ -143,63 +143,10 @@ model CreditGrant {
143143
amount: Shared.Numeric;
144144

145145
/**
146-
* Purchase and payment terms of the grant. Present when a funding workflow applies
147-
* (funding_method is not `none`).
146+
* Present when a funding workflow applies (funding_method is not `none`).
148147
*/
149148
@visibility(Lifecycle.Read, Lifecycle.Create)
150-
purchase?: {
151-
/**
152-
* Currency of the purchase amount.
153-
*/
154-
@visibility(Lifecycle.Read, Lifecycle.Create)
155-
currency: Shared.CurrencyCode;
156-
157-
/**
158-
* Cost basis per credit unit used to calculate the purchase amount.
159-
*
160-
* If `per_unit_cost_basis` is 0.50 and credit amount is $100.00, the total charge
161-
* is $50.00. The value must be greater than 0. If the cost basis is 0, use
162-
* `funding_method=none` instead.
163-
*
164-
* Defaults to 1.0.
165-
*/
166-
@visibility(Lifecycle.Read, Lifecycle.Create)
167-
per_unit_cost_basis?: Shared.Numeric = "1.0";
168-
169-
/**
170-
* The purchase amount. Calculated from `per_unit_cost_basis` and credit `amount`.
171-
*/
172-
@visibility(Lifecycle.Read)
173-
amount: Shared.Numeric;
174-
175-
/**
176-
* Controls when credits become available for consumption.
177-
*
178-
* Defaults to `on_creation`.
179-
*/
180-
@visibility(Lifecycle.Read, Lifecycle.Create)
181-
availability_policy?: CreditAvailabilityPolicy = CreditAvailabilityPolicy.OnCreation;
182-
183-
// TODO: add this option later
184-
// /**
185-
// * The initial payment settlement status when creating a grant with
186-
// * `external` funding method.
187-
// *
188-
// * Governs the payment state of the grant on creation. If the external
189-
// * system tracks payment status, synchronize their state with this system
190-
// * so that revenue recognition works as expected.
191-
// *
192-
// * Defaults to `settled` (the external payment is assumed to be already settled on creation).
193-
// */
194-
// @visibility(Lifecycle.Create)
195-
// external_payment_initial_settlement_status?: CreditPurchasePaymentSettlementStatus = CreditPurchasePaymentSettlementStatus.Settled;
196-
197-
/**
198-
* Current payment settlement status.
199-
*/
200-
@visibility(Lifecycle.Read)
201-
settlement_status?: CreditPurchasePaymentSettlementStatus;
202-
};
149+
purchase?: CreditGrantPurchase;
203150

204151
/**
205152
* Tax configuration for the grant.
@@ -213,37 +160,14 @@ model CreditGrant {
213160
tax_config?: CreditGrantTaxConfig;
214161

215162
/**
216-
* Invoice references for the grant. Available when `funding_method` is `invoice`.
163+
* Available when `funding_method` is `invoice`.
217164
*/
218165
@visibility(Lifecycle.Read)
219-
invoice?: {
220-
/**
221-
* Identifier of the invoice associated with the grant.
222-
*/
223-
@visibility(Lifecycle.Read)
224-
id?: Shared.ULID;
225-
226-
/**
227-
* Identifier of the invoice line associated with the grant.
228-
*/
229-
@visibility(Lifecycle.Read)
230-
line?: {
231-
id: Shared.ULID;
232-
};
233-
};
166+
invoice?: CreditGrantInvoiceReference;
234167

235-
/**
236-
* Filters for the credit grant.
237-
*/
168+
#suppress "@openmeter/api-spec-aip/doc-decorator" "nested model"
238169
@visibility(Lifecycle.Read, Lifecycle.Create)
239-
filters?: {
240-
/**
241-
* Limit the credit grant to specific features. If no features are specified, the
242-
* credit grant can be used for any feature.
243-
*/
244-
@example(#["input_tokens", "output_tokens"])
245-
features?: Shared.ResourceKey[];
246-
};
170+
filters?: CreditGrantFilters;
247171

248172
/**
249173
* Draw-down priority of the grant. Lower values have higher priority.
@@ -289,3 +213,94 @@ model CreditGrant {
289213
@visibility(Lifecycle.Read)
290214
status: CreditGrantStatus;
291215
}
216+
217+
/**
218+
* Purchase and payment terms of the grant.
219+
*/
220+
@friendlyName("BillingCreditGrantPurchase")
221+
model CreditGrantPurchase {
222+
/**
223+
* Currency of the purchase amount.
224+
*/
225+
@visibility(Lifecycle.Read, Lifecycle.Create)
226+
currency: Shared.CurrencyCode;
227+
228+
/**
229+
* Cost basis per credit unit used to calculate the purchase amount.
230+
*
231+
* If `per_unit_cost_basis` is 0.50 and credit amount is $100.00, the total charge
232+
* is $50.00. The value must be greater than 0. If the cost basis is 0, use
233+
* `funding_method=none` instead.
234+
*
235+
* Defaults to 1.0.
236+
*/
237+
@visibility(Lifecycle.Read, Lifecycle.Create)
238+
per_unit_cost_basis?: Shared.Numeric = "1.0";
239+
240+
/**
241+
* The purchase amount. Calculated from `per_unit_cost_basis` and credit `amount`.
242+
*/
243+
@visibility(Lifecycle.Read)
244+
amount: Shared.Numeric;
245+
246+
/**
247+
* Controls when credits become available for consumption.
248+
*
249+
* Defaults to `on_creation`.
250+
*/
251+
@visibility(Lifecycle.Read, Lifecycle.Create)
252+
availability_policy?: CreditAvailabilityPolicy = CreditAvailabilityPolicy.OnCreation;
253+
254+
// TODO: add this option later
255+
// /**
256+
// * The initial payment settlement status when creating a grant with
257+
// * `external` funding method.
258+
// *
259+
// * Governs the payment state of the grant on creation. If the external
260+
// * system tracks payment status, synchronize their state with this system
261+
// * so that revenue recognition works as expected.
262+
// *
263+
// * Defaults to `settled` (the external payment is assumed to be already settled on creation).
264+
// */
265+
// @visibility(Lifecycle.Create)
266+
// external_payment_initial_settlement_status?: CreditPurchasePaymentSettlementStatus = CreditPurchasePaymentSettlementStatus.Settled;
267+
268+
/**
269+
* Current payment settlement status.
270+
*/
271+
@visibility(Lifecycle.Read)
272+
settlement_status?: CreditPurchasePaymentSettlementStatus;
273+
}
274+
275+
/**
276+
* Filters for the credit grant.
277+
*/
278+
@friendlyName("BillingCreditGrantFilters")
279+
model CreditGrantFilters {
280+
/**
281+
* Limit the credit grant to specific features. If no features are specified, the
282+
* credit grant can be used for any feature.
283+
*/
284+
@example(#["input_tokens", "output_tokens"])
285+
features?: Shared.ResourceKey[];
286+
}
287+
288+
/**
289+
* Invoice references for the grant.
290+
*/
291+
@friendlyName("BillingCreditGrantInvoiceReference")
292+
model CreditGrantInvoiceReference {
293+
/**
294+
* Identifier of the invoice associated with the grant.
295+
*/
296+
@visibility(Lifecycle.Read)
297+
id?: Shared.ULID;
298+
299+
/**
300+
* Identifier of the invoice line associated with the grant.
301+
*/
302+
@visibility(Lifecycle.Read)
303+
line?: {
304+
id: Shared.ULID;
305+
};
306+
}

api/spec/packages/aip/src/subscriptions/operations.tsp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ interface SubscriptionsOperations {
9595
* - `id`
9696
* - `active_from` (default)
9797
* - `active_to`
98+
*
99+
* The `asc` suffix is optional as the default sort order is ascending. The `desc`
100+
* suffix is used to specify a descending order.
98101
*/
99102
@query(#{ name: "sort" })
100103
sort?: Common.SortQuery,

api/spec/packages/aip/src/tax/codes.tsp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,3 @@ model TaxCode {
3636
@summary("App type to tax code mappings")
3737
app_mappings: TaxCodeAppMapping[];
3838
}
39-
40-
/**
41-
* Reference to a tax code.
42-
*/
43-
#suppress "@openmeter/api-spec-aip/composition-over-inheritance" "spead doesn't work here"
44-
@friendlyName("BillingTaxCodeReference")
45-
model TaxCodeReference extends Shared.ResourceReference<Tax.TaxCode> {}

0 commit comments

Comments
 (0)