Skip to content

Conversation

@pengying
Copy link
Contributor

@pengying pengying commented Jan 28, 2026

TL;DR

Replace const with enum arrays in OpenAPI schema definitions for better compatibility with OpenAPI tooling.

What changed?

This PR replaces all instances of the const keyword with enum arrays containing a single value throughout the OpenAPI schema definitions. For example:

- const: 401
+ type: integer
+ enum:
+   - 401

The change affects various schema components including:

  • HTTP status codes in error responses
  • Account type identifiers
  • Customer types
  • Asset types
  • Webhook event types

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@pengying pengying marked this pull request as ready for review January 28, 2026 19:25
@greptile-apps
Copy link

greptile-apps bot commented Jan 28, 2026

Greptile Overview

Greptile Summary

This PR reverts the changes from PR #126 by converting all const keywords back to single-value enum arrays throughout the OpenAPI schema. The change improves compatibility with OpenAPI code generators and tooling that may not fully support the const keyword.

Key changes

  • Error schemas (9 files): HTTP status codes changed from const: 401 to type: integer with enum: [401]
  • Discriminator properties: Added explicit discriminator fields with single-value enums:
    • customerType in BusinessCustomer and IndividualCustomer
    • beneficiaryType in BusinessBeneficiary and IndividualBeneficiary
    • accountType in various account info schemas
  • New base schemas: Created base schemas with proper discriminator mappings:
    • BasePaymentAccountInfo for payment instructions
    • BaseExternalAccountInfo for external accounts
    • BaseBeneficiary for beneficiary types
    • BaseDestination and BaseQuoteSource for quotes
    • BaseTransactionSource and BaseTransactionDestination for transactions
  • Schema restructuring: Multiple schemas refactored to use allOf pattern with base schemas for better inheritance and discriminator support
  • Webhook events: Event type discriminators changed from const to single-value enum

All changes are consistent and follow the same pattern. The bundled outputs (openapi.yaml and mintlify/openapi.yaml) have been regenerated to reflect these changes.

Confidence Score: 5/5

  • This PR is safe to merge with no risk - it's a systematic revert to improve tooling compatibility
  • The changes are mechanical, consistent, and well-justified. All 100 files follow the same pattern of replacing const with single-value enum arrays. The PR addresses a real compatibility issue with OpenAPI generators. No logic changes, no new features - just schema format adjustments. The bundled outputs were properly regenerated.
  • No files require special attention

Important Files Changed

Filename Overview
openapi/components/schemas/errors/Error401.yaml Replaced const: 401 with type: integer and enum: [401] for HTTP status code
openapi/components/schemas/customers/BusinessCustomer.yaml Added explicit customerType discriminator with enum: [BUSINESS] for polymorphism
openapi/components/schemas/common/BasePaymentAccountInfo.yaml New base schema with discriminator for payment account types
openapi/components/schemas/webhooks/InvitationClaimedWebhook.yaml Replaced const: INVITATION_CLAIMED with enum: [INVITATION_CLAIMED] for event type
openapi/components/schemas/external_accounts/BaseExternalAccountInfo.yaml New base schema with discriminator mapping for all external account types
openapi/components/schemas/quotes/BaseDestination.yaml New base schema with discriminator for quote destination types

Sequence Diagram

sequenceDiagram
    participant Dev as Developer
    participant Schema as OpenAPI Schema Files
    participant Bundle as Build Process
    participant Tools as OpenAPI Tools/Generators
    
    Note over Dev,Tools: PR #126: Convert enum to const
    Dev->>Schema: Replace single-value enums with const
    Schema->>Bundle: npm run build:openapi
    Bundle->>Tools: Generate client SDKs
    Tools-->>Dev: ❌ Compatibility issues with const
    
    Note over Dev,Tools: PR #140: Revert to enum (this PR)
    Dev->>Schema: Replace const with single-value enum
    Note over Schema: 1. Error schemas: const: 401 → enum: [401]
    Note over Schema: 2. Discriminators: Add explicit enums
    Note over Schema: 3. Base schemas: Add discriminator mappings
    Schema->>Bundle: npm run build:openapi
    Bundle->>Tools: Generate client SDKs
    Tools-->>Dev: ✅ Better compatibility
Loading

@pengying pengying force-pushed the 01-28-fix_reverting_back_to_using_enums_instead_of_const_for_openapi_generator branch 6 times, most recently from d1f51d7 to 3a34b56 Compare January 30, 2026 00:01
@pengying pengying force-pushed the 01-28-fix_reverting_back_to_using_enums_instead_of_const_for_openapi_generator branch from 3a34b56 to f173a87 Compare January 30, 2026 17:58
Comment on lines +6 to +11
assetType:
type: string
description: Type of asset
enum:
- USDC
- USDT
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be a ref?

Copy link
Contributor Author

@pengying pengying Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could make it a ref if you want to create an enum for openapi-generator for webdev.

    @field_validator('asset_type')

    def asset_type_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value
        if value not in set(['USDC', 'USDT']):
            raise ValueError("must be one of enum values ('USDC', 'USDT')")
        return value
    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )

For external generation via stainless, this results in a distinct type:
https://github.com/stainless-sdks/grid-kotlin/blob/main/grid-kotlin-core/src/main/kotlin/com/grid/api/models/quotes/PaymentInstructions.kt#L4432

class AssetType @JsonCreator private constructor(private val value: JsonField<String>) :
                Enum {

                /**
                 * Returns this class instance's raw value.
                 *
                 * This is usually only useful if this instance was deserialized from data that
                 * doesn't match any known member, and you want to know that value. For example, if
                 * the SDK is on an older version than the API, then the API may respond with new
                 * members that the SDK is unaware of.
                 */
                @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField<String> = value

                companion object {

                    val USDC = of("USDC")

                    val USDT = of("USDT")

                    fun of(value: String) = AssetType(JsonField.of(value))
                }

                /** An enum containing [AssetType]'s known values. */
                enum class Known {
                    USDC,
                    USDT,
                }

@pengying pengying merged commit 1df8211 into main Jan 30, 2026
7 checks passed
@pengying pengying deleted the 01-28-fix_reverting_back_to_using_enums_instead_of_const_for_openapi_generator branch January 30, 2026 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants