Skip to content

fix: separating create customer from customer response schemas#142

Merged
pengying merged 3 commits intomainfrom
01-30-fix_separating_create_customer_from_customer_response_schemas
Feb 2, 2026
Merged

fix: separating create customer from customer response schemas#142
pengying merged 3 commits intomainfrom
01-30-fix_separating_create_customer_from_customer_response_schemas

Conversation

@pengying
Copy link
Contributor

@pengying pengying commented Jan 31, 2026

TL;DR

Refactored customer schema definitions to use a consistent approach for both creation and update operations.

What changed?

  • Created new schema definitions for customer creation requests:
    • CustomerCreateRequest as a base schema
    • IndividualCustomerCreateRequest and BusinessCustomerCreateRequest extending the base schema
    • CustomerCreateRequestOneOf to handle the oneOf relationship between customer types
  • Replaced the separate update schemas (IndividualCustomerUpdate and BusinessCustomerUpdate) with the same creation request schemas
  • Updated API endpoints to reference the new schema definitions:
    • Changed POST /customers to use CustomerCreateRequestOneOf
    • Changed PATCH /customers/{customerId} to use CustomerCreateRequestOneOf

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 31, 2026 00:29
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 31, 2026

Greptile Overview

Greptile Summary

Refactored customer schema architecture to separate create and update request schemas with consistent structure.

  • Created new CustomerCreateRequest base schema with required platformCustomerId field
  • Created IndividualCustomerCreateRequest and BusinessCustomerCreateRequest extending the base
  • Created CustomerUpdateRequest base schema without required platformCustomerId for partial updates
  • Introduced shared field schemas (BusinessCustomerFields, IndividualCustomerFields) for code reuse
  • Split BusinessInfo (requires legalName) and BusinessInfoUpdate (no required fields) to enforce validation rules appropriately
  • Updated POST /customers to use CustomerCreateRequestOneOf and PATCH /customers/{customerId} to use CustomerUpdateRequestOneOf
  • Removed deprecated schemas (BusinessCustomerUpdate, IndividualCustomerUpdate)

The refactoring maintains backward compatibility for the PATCH endpoint by keeping fields optional for partial updates, while enforcing stricter validation for POST requests.

Confidence Score: 4/5

  • Safe to merge after fixing syntax issues in CustomerCreateRequest.yaml
  • The refactoring is well-structured and maintains API compatibility by keeping separate schemas for create vs update operations. The only issues are minor syntax problems (missing type declaration and duplicate text) that need to be fixed before merging.
  • openapi/components/schemas/customers/CustomerCreateRequest.yaml requires fixes for missing type declaration and duplicate text

Important Files Changed

Filename Overview
openapi/components/schemas/customers/CustomerCreateRequest.yaml new base schema for customer creation with missing type declaration and duplicate text
openapi/components/schemas/customers/CustomerCreateRequestOneOf.yaml simple oneOf wrapper for create requests, properly configured
openapi/components/schemas/customers/BusinessCustomerCreateRequest.yaml correctly extends base create request with business fields requiring legalName
openapi/components/schemas/customers/CustomerUpdateRequest.yaml base schema for updates without platformCustomerId requirement
openapi/components/schemas/customers/BusinessInfo.yaml business info schema requiring legalName for creation
openapi/components/schemas/customers/BusinessInfoUpdate.yaml business info schema without required fields for partial updates

Sequence Diagram

sequenceDiagram
    participant Client
    participant API as Grid API
    participant ValidationLayer as Schema Validation
    participant Database

    Note over Client,Database: Customer Creation Flow

    Client->>API: POST /customers
    Note right of Client: CustomerCreateRequestOneOf<br/>(requires platformCustomerId)
    API->>ValidationLayer: Validate request schema
    ValidationLayer->>ValidationLayer: Check customerType (INDIVIDUAL/BUSINESS)
    ValidationLayer->>ValidationLayer: Validate required fields<br/>(platformCustomerId, customerType)
    alt Business Customer
        ValidationLayer->>ValidationLayer: Validate BusinessInfo<br/>(legalName required)
    else Individual Customer
        ValidationLayer->>ValidationLayer: Validate IndividualCustomerFields
    end
    ValidationLayer->>API: Schema valid
    API->>Database: Create customer record
    Database->>API: Customer created
    API->>Client: 201 Created (Customer object)

    Note over Client,Database: Customer Update Flow

    Client->>API: PATCH /customers/{customerId}
    Note right of Client: CustomerUpdateRequestOneOf<br/>(platformCustomerId optional)
    API->>ValidationLayer: Validate request schema
    ValidationLayer->>ValidationLayer: Check customerType (INDIVIDUAL/BUSINESS)
    ValidationLayer->>ValidationLayer: Validate optional fields<br/>(partial update allowed)
    alt Business Customer Update
        ValidationLayer->>ValidationLayer: Validate BusinessInfoUpdate<br/>(no required fields)
    else Individual Customer Update
        ValidationLayer->>ValidationLayer: Validate IndividualCustomerFields
    end
    ValidationLayer->>API: Schema valid
    API->>Database: Update customer record
    Database->>API: Customer updated
    API->>Client: 200 OK (Updated Customer object)
Loading

Copy link
Contributor

@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.

4 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@pengying pengying force-pushed the 01-30-fix_separating_create_customer_from_customer_response_schemas branch from 00a920e to 4970949 Compare January 31, 2026 01:05
Copy link
Contributor

@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.

3 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@pengying pengying force-pushed the 01-30-fix_separating_create_customer_from_customer_response_schemas branch from e93abea to f8c05b0 Compare January 31, 2026 04:11
Copy link
Contributor

@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.

7 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@pengying pengying force-pushed the 01-30-fix_separating_create_customer_from_customer_response_schemas branch from f8c05b0 to 51732f6 Compare January 31, 2026 04:18
Copy link

Choose a reason for hiding this comment

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

should we just have the one BusinessInfo.yaml (with legalName required)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was originally structured that way. The issue is that if you're patching a business, it's annoying to always include business legalName in every request.

I restructured it so legalName is required on create and in the response.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but optional in patch

@pengying pengying force-pushed the 01-30-fix_separating_create_customer_from_customer_response_schemas branch from 51732f6 to 96dadbd Compare February 2, 2026 18:55
Copy link
Contributor

@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.

7 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +12 to +16
umaAddress:
description: >-
Optional UMA address identifier. If not provided during customer creation, one will be generated by the system.
If provided during customer update, the UMA address will be updated to the provided value. This is an optional identifier to route payments to the customer.
This is an optional identifier to route payments to the customer.
Copy link
Contributor

Choose a reason for hiding this comment

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

duplicated sentence - "This is an optional identifier to route payments to the customer." appears twice

Suggested change
umaAddress:
description: >-
Optional UMA address identifier. If not provided during customer creation, one will be generated by the system.
If provided during customer update, the UMA address will be updated to the provided value. This is an optional identifier to route payments to the customer.
This is an optional identifier to route payments to the customer.
umaAddress:
type: string
description: >-
Optional UMA address identifier. If not provided during customer creation, one will be generated by the system.
If provided during customer update, the UMA address will be updated to the provided value. This is an optional identifier to route payments to the customer.
example: $john.doe@uma.domain.com
Prompt To Fix With AI
This is a comment left during a code review.
Path: openapi/components/schemas/customers/CustomerCreateRequest.yaml
Line: 12:16

Comment:
duplicated sentence - "This is an optional identifier to route payments to the customer." appears twice

```suggestion
  umaAddress:
    type: string
    description: >-
      Optional UMA address identifier. If not provided during customer creation, one will be generated by the system.
      If provided during customer update, the UMA address will be updated to the provided value. This is an optional identifier to route payments to the customer.
    example: $john.doe@uma.domain.com
```

How can I resolve this? If you propose a fix, please make it concise.

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Copy link
Contributor

@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.

5 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@pengying pengying enabled auto-merge (squash) February 2, 2026 21:19
Copy link
Contributor

@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.

6 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +12 to +16
umaAddress:
description: >-
Optional UMA address identifier. If not provided during customer creation, one will be generated by the system.
If provided during customer update, the UMA address will be updated to the provided value. This is an optional identifier to route payments to the customer.
This is an optional identifier to route payments to the customer.
Copy link
Contributor

Choose a reason for hiding this comment

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

missing type: string for umaAddress field

Suggested change
umaAddress:
description: >-
Optional UMA address identifier. If not provided during customer creation, one will be generated by the system.
If provided during customer update, the UMA address will be updated to the provided value. This is an optional identifier to route payments to the customer.
This is an optional identifier to route payments to the customer.
umaAddress:
type: string
description: >-
Optional UMA address identifier. If not provided during customer creation, one will be generated by the system.
If provided during customer update, the UMA address will be updated to the provided value. This is an optional identifier to route payments to the customer.
example: $john.doe@uma.domain.com
Prompt To Fix With AI
This is a comment left during a code review.
Path: openapi/components/schemas/customers/CustomerCreateRequest.yaml
Line: 12:16

Comment:
missing `type: string` for `umaAddress` field

```suggestion
  umaAddress:
    type: string
    description: >-
      Optional UMA address identifier. If not provided during customer creation, one will be generated by the system.
      If provided during customer update, the UMA address will be updated to the provided value. This is an optional identifier to route payments to the customer.
    example: $john.doe@uma.domain.com
```

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +15 to +16
If provided during customer update, the UMA address will be updated to the provided value. This is an optional identifier to route payments to the customer.
This is an optional identifier to route payments to the customer.
Copy link
Contributor

Choose a reason for hiding this comment

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

duplicated text - "This is an optional identifier to route payments to the customer." appears twice

Suggested change
If provided during customer update, the UMA address will be updated to the provided value. This is an optional identifier to route payments to the customer.
This is an optional identifier to route payments to the customer.
If provided during customer update, the UMA address will be updated to the provided value. This is an optional identifier to route payments to the customer.
example: $john.doe@uma.domain.com
Prompt To Fix With AI
This is a comment left during a code review.
Path: openapi/components/schemas/customers/CustomerCreateRequest.yaml
Line: 15:16

Comment:
duplicated text - "This is an optional identifier to route payments to the customer." appears twice

```suggestion
      If provided during customer update, the UMA address will be updated to the provided value. This is an optional identifier to route payments to the customer.
    example: $john.doe@uma.domain.com
```

How can I resolve this? If you propose a fix, please make it concise.

@pengying pengying merged commit dde72cc into main Feb 2, 2026
8 of 13 checks passed
@pengying pengying deleted the 01-30-fix_separating_create_customer_from_customer_response_schemas branch February 2, 2026 23:18
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.

2 participants