Skip to content

Commit

Permalink
fix: mandate enum prefixes for generated APIs (#1688)
Browse files Browse the repository at this point in the history
This disables the heuristics of oapi codegen thus we get stable names.
  • Loading branch information
turip authored Oct 16, 2024
1 parent d0b8827 commit 1903540
Show file tree
Hide file tree
Showing 20 changed files with 613 additions and 568 deletions.
971 changes: 486 additions & 485 deletions api/api.gen.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions api/codegen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ compatibility:
apply-chi-middleware-first-to-last: true
# See: https://github.com/oapi-codegen/oapi-codegen/issues/778
disable-required-readonly-as-pointer: true
always-prefix-enum-values: true
output: ./api.gen.go
114 changes: 66 additions & 48 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4325,7 +4325,7 @@ components:
required: false
description: The order direction.
schema:
$ref: '#/components/schemas/Order'
$ref: '#/components/schemas/SortOrder'
explode: false
EntitlementOrderByOrdering.orderBy:
name: orderBy
Expand All @@ -4341,7 +4341,7 @@ components:
required: false
description: The order direction.
schema:
$ref: '#/components/schemas/Order'
$ref: '#/components/schemas/SortOrder'
explode: false
FeatureOrderByOrdering.orderBy:
name: orderBy
Expand All @@ -4357,7 +4357,7 @@ components:
required: false
description: The order direction.
schema:
$ref: '#/components/schemas/Order'
$ref: '#/components/schemas/SortOrder'
explode: false
GrantOrderByOrdering.orderBy:
name: orderBy
Expand Down Expand Up @@ -4485,7 +4485,7 @@ components:
required: false
description: The order direction.
schema:
$ref: '#/components/schemas/Order'
$ref: '#/components/schemas/SortOrder'
explode: false
NotificationChannelOrderByOrdering.orderBy:
name: orderBy
Expand All @@ -4501,7 +4501,7 @@ components:
required: false
description: The order direction.
schema:
$ref: '#/components/schemas/Order'
$ref: '#/components/schemas/SortOrder'
explode: false
NotificationEventOrderByOrdering.orderBy:
name: orderBy
Expand All @@ -4517,7 +4517,7 @@ components:
required: false
description: The order direction.
schema:
$ref: '#/components/schemas/Order'
$ref: '#/components/schemas/SortOrder'
explode: false
NotificationRuleOrderByOrdering.orderBy:
name: orderBy
Expand Down Expand Up @@ -4728,7 +4728,7 @@ components:
readOnly: true
status:
allOf:
- $ref: '#/components/schemas/OpenMeter.App.AppStatus'
- $ref: '#/components/schemas/AppStatus'
description: Status of the app connection.
readOnly: true
description: |-
Expand Down Expand Up @@ -4804,6 +4804,12 @@ components:
maxItems: 1000
description: The items in the page.
description: A page of results.
AppStatus:
type: string
enum:
- ready
- unauthorized
description: App installed status.
BadRequestProblemResponse:
type: object
allOf:
Expand Down Expand Up @@ -6465,15 +6471,18 @@ components:
description: A page of results.
MeasureUsageFrom:
oneOf:
- $ref: '#/components/schemas/MeasureUsageFromEnum'
- $ref: '#/components/schemas/MeasureUsageFromPreset'
- $ref: '#/components/schemas/MeasureUsageFromTime'
description: Measure usage from
MeasureUsageFromEnum:
MeasureUsageFromPreset:
type: string
enum:
- CURRENT_PERIOD_START
- NOW
description: Start of measurement options
x-enum-varnames:
- CurrentPeriodStart
- Now
MeasureUsageFromTime:
type: string
format: date-time
Expand Down Expand Up @@ -6731,6 +6740,8 @@ components:
enum:
- WEBHOOK
description: Type of the notification channel.
x-enum-varnames:
- Webhook
NotificationChannelWebhook:
type: object
required:
Expand Down Expand Up @@ -6988,15 +6999,10 @@ components:
- channel
properties:
state:
type: string
enum:
- SUCCESS
- FAILED
- SENDING
- PENDING
allOf:
- $ref: '#/components/schemas/NotificationEventDeliveryStatusState'
example: SUCCESS
description: Delivery state of the notification event to the channel.
title: Delivery State
readOnly: true
reason:
type: string
Expand All @@ -7018,6 +7024,20 @@ components:
title: Notification Channel
readOnly: true
description: The delivery status of the notification event.
NotificationEventDeliveryStatusState:
type: string
enum:
- SUCCESS
- FAILED
- SENDING
- PENDING
description: The delivery state of the notification event to the channel.
title: Delivery State
x-enum-varnames:
- Success
- Failed
- Sending
- Pending
NotificationEventOrderBy:
type: string
enum:
Expand Down Expand Up @@ -7215,14 +7235,21 @@ components:
description: Value of the threshold.
title: Threshold Value
type:
type: string
enum:
- PERCENT
- NUMBER
allOf:
- $ref: '#/components/schemas/NotificationRuleBalanceThresholdValueType'
example: NUMBER
description: Type of the threshold.
title: Threshold Type
description: Threshold value with multiple supported types.
NotificationRuleBalanceThresholdValueType:
type: string
enum:
- PERCENT
- NUMBER
description: Type of the rule in the balance threshold specification.
title: Notification balance threshold type
x-enum-varnames:
- Percent
- Number
NotificationRuleCreateRequest:
type: object
allOf:
Expand Down Expand Up @@ -7273,36 +7300,11 @@ components:
- server_error
- temporarily_unavailable
description: OAuth2 authorization code grant error types.
OpenMeter.App.AppStatus:
type: string
enum:
- ready
- unauthorized
description: App installed status.
OpenMeter.App.StripePaymentIntentStatus:
type: string
enum:
- canceled
- processing
- requires_action
- requires_confirmation
- requires_payment_method
- succeeded
description: Stripe payment intent status.
OpenMeter.App.Type:
type: string
enum:
- stripe
description: Type of the app.
Order:
type: string
enum:
- ASC
- DESC
description: The order direction.
x-enum-varnames:
- SortOrderASC
- SortOrderDESC
Period:
type: object
required:
Expand Down Expand Up @@ -7448,6 +7450,12 @@ components:
allOf:
- $ref: '#/components/schemas/UnexpectedProblemResponse'
description: The server is currently unable to handle the request due to a temporary overload or scheduled maintenance, which will likely be alleviated after some delay.
SortOrder:
type: string
enum:
- ASC
- DESC
description: The order direction.
StripeApp:
type: object
required:
Expand Down Expand Up @@ -7512,7 +7520,7 @@ components:
readOnly: true
status:
allOf:
- $ref: '#/components/schemas/OpenMeter.App.AppStatus'
- $ref: '#/components/schemas/AppStatus'
description: Status of the app connection.
readOnly: true
type:
Expand Down Expand Up @@ -7559,6 +7567,16 @@ components:
enum:
- setup
description: Stripe CheckoutSession.mode
StripePaymentIntentStatus:
type: string
enum:
- canceled
- processing
- requires_action
- requires_confirmation
- requires_payment_method
- succeeded
description: Stripe payment intent status.
StripeSetupIntent:
type: object
required:
Expand All @@ -7572,7 +7590,7 @@ components:
description: The setup intent id.
status:
allOf:
- $ref: '#/components/schemas/OpenMeter.App.StripePaymentIntentStatus'
- $ref: '#/components/schemas/StripePaymentIntentStatus'
description: The setup intent status.
payment_method:
type: string
Expand Down
1 change: 1 addition & 0 deletions api/spec/src/app/app.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ model AppBase {
/**
* App installed status.
*/
@friendlyName("AppStatus")
enum AppStatus {
/**
* The app is ready to be used.
Expand Down
1 change: 1 addition & 0 deletions api/spec/src/app/stripe.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ model StripeSetupIntent {
/**
* Stripe payment intent status.
*/
@friendlyName("StripePaymentIntentStatus")
enum StripePaymentIntentStatus {
Canceled: "canceled",
Processing: "processing",
Expand Down
7 changes: 4 additions & 3 deletions api/spec/src/entitlements/entitlements.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,9 @@ model EntitlementStatic {
/**
* Start of measurement options
*/
@friendlyName("MeasureUsageFromEnum")
enum MeasureUsageFromEnum {
@friendlyName("MeasureUsageFromPreset")
@extension("x-enum-varnames", ["CurrentPeriodStart", "Now"])
enum MeasureUsageFromPreset {
#suppress "@openmeter/api-spec/casing" "Use existing values"
CURRENT_PERIOD_START: "CURRENT_PERIOD_START",
#suppress "@openmeter/api-spec/casing" "Use existing values"
Expand All @@ -354,6 +355,6 @@ scalar MeasureUsageFromTime extends DateTime;
@friendlyName("MeasureUsageFrom")
@oneOf
union MeasureUsageFrom {
`enum`: MeasureUsageFromEnum,
preset: MeasureUsageFromPreset,
time: MeasureUsageFromTime,
}
1 change: 1 addition & 0 deletions api/spec/src/notification/channel.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace OpenMeter.Notification;
* Type of the notification channel.
*/
@friendlyName("NotificationChannelType")
@extension("x-enum-varnames", ["Webhook"])
enum NotificationChannelType {
#suppress "@openmeter/api-spec/casing" "Ignore due to backward compatibility"
webhook: "WEBHOOK",
Expand Down
18 changes: 15 additions & 3 deletions api/spec/src/notification/event.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ model NotificationEventDeliveryStatus {
* Delivery state of the notification event to the channel.
*/
@visibility("read")
@summary("Delivery State")
@example("SUCCESS")
state: "SUCCESS" | "FAILED" | "SENDING" | "PENDING";
@example(NotificationEventDeliveryStatusState.Success)
state: NotificationEventDeliveryStatusState;

/**
* The reason of the last deliverry state update.
Expand All @@ -54,6 +53,19 @@ model NotificationEventDeliveryStatus {
channel: NotificationChannelMeta;
}

/**
* The delivery state of the notification event to the channel.
*/
@friendlyName("NotificationEventDeliveryStatusState")
@summary("Delivery State")
@extension("x-enum-varnames", ["Success", "Failed", "Sending", "Pending"])
enum NotificationEventDeliveryStatusState {
Success: "SUCCESS",
Failed: "FAILED",
Sending: "SENDING",
Pending: "PENDING",
}

/**
* The delivery status of the notification event.
*/
Expand Down
16 changes: 13 additions & 3 deletions api/spec/src/notification/rule.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,19 @@ model NotificationRuleBalanceThresholdValue {
* Type of the threshold.
*/
@visibility("read", "create", "update")
@summary("Threshold Type")
@example("NUMBER")
type: "PERCENT" | "NUMBER";
@example(NotificationRuleBalanceThresholdValueType.NUMBER)
type: NotificationRuleBalanceThresholdValueType;
}

/**
* Type of the rule in the balance threshold specification.
*/
@summary("Notification balance threshold type")
@friendlyName("NotificationRuleBalanceThresholdValueType")
@extension("x-enum-varnames", ["Percent", "Number"])
enum NotificationRuleBalanceThresholdValueType {
PERCENT,
NUMBER,
}

/**
Expand Down
9 changes: 4 additions & 5 deletions api/spec/src/query.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ model QueryOrdering<T> {
* The order direction.
*/
@query
@example(Order.ASC)
order?: Order;
@example(SortOrder.ASC)
order?: SortOrder;

/**
* The order by field.
Expand All @@ -88,9 +88,8 @@ model QueryOrdering<T> {
/**
* The order direction.
*/
@friendlyName("Order")
@extension("x-enum-varnames", ["SortOrderASC", "SortOrderDESC"])
enum Order {
@friendlyName("SortOrder")
enum SortOrder {
#suppress "@openmeter/api-spec/casing" "Use existing values"
ASC: "ASC",
#suppress "@openmeter/api-spec/casing" "Use existing values"
Expand Down
Loading

0 comments on commit 1903540

Please sign in to comment.