-
Notifications
You must be signed in to change notification settings - Fork 3
fix: reverting back to using enums instead of const for openapi generator #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: reverting back to using enums instead of const for openapi generator #140
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
Greptile OverviewGreptile SummaryThis PR reverts the changes from PR #126 by converting all Key changes
All changes are consistent and follow the same pattern. The bundled outputs ( Confidence Score: 5/5
|
| 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
d1f51d7 to
3a34b56
Compare
3a34b56 to
f173a87
Compare
| assetType: | ||
| type: string | ||
| description: Type of asset | ||
| enum: | ||
| - USDC | ||
| - USDT |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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,
}

TL;DR
Replace
constwithenumarrays in OpenAPI schema definitions for better compatibility with OpenAPI tooling.What changed?
This PR replaces all instances of the
constkeyword withenumarrays containing a single value throughout the OpenAPI schema definitions. For example:The change affects various schema components including: