Skip to content

Conversation

@pengying
Copy link
Contributor

@pengying pengying commented Jan 24, 2026

TL;DR

Refactored OpenAPI schema to use proper discriminators for polymorphic types in transaction and quote models.

What changed?

  • Added proper discriminator fields (sourceType and destinationType) to polymorphic types in the API schema
  • Extracted reusable schema components into separate files for better organization:
    • Created dedicated schema files for source and destination types (Account, UMA Address)
    • Added proper type discriminators to enable client code generation tools to handle polymorphism correctly
  • Removed inline examples from the /quotes endpoint request body
  • Removed redundant examples from schema definitions that were duplicated across multiple components

@greptile-apps
Copy link

greptile-apps bot commented Jan 24, 2026

Greptile Overview

Greptile Summary

This PR refactors the OpenAPI schema to implement proper discriminator patterns for polymorphic types across quotes and transactions.

Key Changes:

  • Extracted inline schemas into reusable components (AccountSource, AccountDestination, UmaAddressDestination, UmaAddressSource, QuoteRealtimeFundingSource)
  • Added discriminator fields (sourceType, destinationType, type) with proper mappings to enable code generators to handle polymorphism
  • Removed inline examples from /quotes endpoint request body
  • Added lint ignores for required at oneOf level per OpenAPI spec patterns

Impact:

  • Improves code generation for client SDKs by providing explicit type discriminators
  • Reduces duplication through schema extraction and reuse
  • All discriminator mappings are consistent with their corresponding const values
  • No breaking API changes - purely structural improvements to the schema definition

Note on Lint Ignores:
The required keyword at the oneOf level follows the OpenAPI spec example for discriminated polymorphism. While some linters flag this, it's a valid pattern for ensuring discriminator fields are present.

Confidence Score: 5/5

  • This PR is safe to merge - it's a well-executed schema refactoring with no runtime impact
  • All discriminator mappings are verified consistent with const values, schema extractions are clean and reusable, and the changes are purely structural improvements to OpenAPI definitions without affecting API behavior
  • No files require special attention

Important Files Changed

Filename Overview
openapi/components/schemas/common/AccountSource.yaml New reusable schema for account funding source with ACCOUNT discriminator - clean extraction
openapi/components/schemas/common/AccountDestination.yaml New reusable schema for account destination with ACCOUNT discriminator - clean extraction
openapi/components/schemas/quotes/QuoteSource.yaml Refactored to use discriminator pattern with proper $refs instead of inline schemas
openapi/components/schemas/quotes/Quote.yaml Added discriminator for destination oneOf - references extracted schemas
openapi/components/schemas/transactions/Transaction.yaml Added discriminator for destination oneOf - references extracted schemas
.redocly.lint-ignore.yaml Added lint ignores for required at oneOf level per OpenAPI spec recommendation

Sequence Diagram

sequenceDiagram
    participant Client
    participant API as Grid API
    participant Validator as Schema Validator
    participant CodeGen as Code Generator

    Note over Client,CodeGen: Quote Creation with Discriminated Source Types

    Client->>API: POST /quotes<br/>{source: {sourceType: "ACCOUNT", accountId: "..."},<br/>destination: {...}}
    API->>Validator: Validate request against QuoteRequest schema
    Validator->>Validator: Check source.sourceType discriminator
    alt sourceType == "ACCOUNT"
        Validator->>Validator: Validate against AccountSource.yaml
    else sourceType == "REALTIME_FUNDING"
        Validator->>Validator: Validate against QuoteRealtimeFundingSource.yaml
    end
    Validator->>API: Valid ✓
    API->>Client: 201 Quote Created

    Note over Client,CodeGen: Transaction Response with Discriminated Types

    Client->>API: GET /transactions/{id}
    API->>Client: 200 Transaction Response<br/>{type: "OUTGOING",<br/>source: {sourceType: "ACCOUNT", ...},<br/>destination: {destinationType: "UMA_ADDRESS", ...}}
    
    Client->>CodeGen: Deserialize response
    CodeGen->>CodeGen: Read type discriminator = "OUTGOING"
    CodeGen->>CodeGen: Map to OutgoingTransaction class
    CodeGen->>CodeGen: Read source.sourceType = "ACCOUNT"
    CodeGen->>CodeGen: Map to AccountSource class
    CodeGen->>CodeGen: Read destination.destinationType = "UMA_ADDRESS"
    CodeGen->>CodeGen: Map to UmaAddressDestination class
    CodeGen->>Client: Strongly-typed Transaction object
Loading

@pengying pengying force-pushed the 01-24-feat_flatten_lightningexternalaccountinfo_schema_split branch from a26b5f1 to 8e458b0 Compare January 27, 2026 01:29
@pengying pengying force-pushed the 01-24-feat_flatten_lightningexternalaccountinfo_schema_split_split branch from e7d2ae0 to 2793eb3 Compare January 27, 2026 01:29
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@pengying pengying force-pushed the 01-24-feat_flatten_lightningexternalaccountinfo_schema_split branch from 8e458b0 to 8f5820a Compare January 27, 2026 05:17
@pengying pengying force-pushed the 01-24-feat_flatten_lightningexternalaccountinfo_schema_split_split branch from 2793eb3 to a6d5ea6 Compare January 27, 2026 05:18
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@pengying pengying force-pushed the 01-24-feat_flatten_lightningexternalaccountinfo_schema_split branch 2 times, most recently from 941bc27 to b9e7d56 Compare January 27, 2026 05:23
@pengying pengying force-pushed the 01-24-feat_flatten_lightningexternalaccountinfo_schema_split_split branch from a6d5ea6 to ba5b137 Compare January 27, 2026 05:23
@pengying pengying force-pushed the 01-24-feat_flatten_lightningexternalaccountinfo_schema_split branch from b9e7d56 to 13de662 Compare January 27, 2026 20:38
@pengying pengying force-pushed the 01-24-feat_flatten_lightningexternalaccountinfo_schema_split_split branch from ba5b137 to 8e152e4 Compare January 27, 2026 20:38
@pengying pengying force-pushed the 01-24-feat_flatten_lightningexternalaccountinfo_schema_split branch from 13de662 to 98da0bf Compare January 27, 2026 21:19
@pengying pengying force-pushed the 01-24-feat_flatten_lightningexternalaccountinfo_schema_split_split branch from 8e152e4 to 4db1ea5 Compare January 27, 2026 21:19
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@pengying pengying changed the base branch from 01-24-feat_flatten_lightningexternalaccountinfo_schema_split to graphite-base/129 January 27, 2026 22:31
@pengying pengying force-pushed the 01-24-feat_flatten_lightningexternalaccountinfo_schema_split_split branch from 4db1ea5 to 152d09c Compare January 27, 2026 23:55
@pengying pengying changed the base branch from graphite-base/129 to main January 27, 2026 23:55
@pengying pengying force-pushed the 01-24-feat_flatten_lightningexternalaccountinfo_schema_split_split branch from 152d09c to 5adb57b Compare January 27, 2026 23:57
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@pengying pengying force-pushed the 01-24-feat_flatten_lightningexternalaccountinfo_schema_split_split branch 2 times, most recently from c88c884 to 7fc9ade Compare January 28, 2026 00:15
@pengying pengying force-pushed the 01-24-feat_flatten_lightningexternalaccountinfo_schema_split_split branch from 7fc9ade to 36f295c Compare January 28, 2026 00:27
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