viceroypenguin / Going.Plaid

Plaid API .NET library
https://plaid.com
MIT License
72 stars 33 forks source link

Address Entity no longer contains AddressData #113

Closed jcoliz closed 1 year ago

jcoliz commented 1 year ago

Current State

In 66e96dc708da8f550d4af63a5e7f5b145a8bf1ca, this change was made to src/Plaid/Entity/Address.cs:

--- a/src/Plaid/Entity/Address.cs
+++ b/src/Plaid/Entity/Address.cs
@@ -1,19 +1,19 @@
-namespace Going.Plaid.Entity;
+namespace Going.Plaid.Entity;

 /// <summary>
-/// <para>A physical mailing address.</para>
+/// <para>Score found by matching address provided by the API with the address on the account at the financial institution. If the account contains multiple owners, the maximum match score is filled.</para>
 /// </summary>
 public record Address
 {
        /// <summary>
-       /// <para>Data about the components comprising an address.</para>
+       /// <para>Match score for address. 100 is a perfect match and 0 is a no match. If the address is missing from either the API or financial institution, this is empty.</para>
        /// </summary>
-       [JsonPropertyName("data")]
-       public Entity.AddressData Data { get; init; } = default!;
+       [JsonPropertyName("score")]
+       public int? Score { get; init; } = default!;

Expected

The Address entity should still contain AddressData.

Here is an API documentation link for Identity/Get which is where I encountered it: https://plaid.com/docs/api/products/identity/#identity-get-response-accounts . Address data is still included there.

Let's look at some YAML snippets:

    IdentityGetResponse:
        accounts:
          type: array
          description: The accounts for which Identity data has been requested
          items:
            $ref: '#/components/schemas/AccountIdentity'

    AccountIdentity:
      description: Identity information about an account
      title: AccountIdentity
      allOf:
      - $ref: '#/components/schemas/AccountBase'
      - type: object
        additionalProperties: true
        properties:
          owners:
            type: array
            items:
              $ref: '#/components/schemas/Owner'

    Owner:
      title: Owner
      properties:
        addresses:
          type: array
          description: Data about the various addresses associated with the account by the financial institution. May be an empty array if no relevant information is returned from the financial institution.
          items:
            $ref: '#/components/schemas/Address'

    Address:
      title: Address
      type: object
      additionalProperties: true
      description: A physical mailing address.
      properties:
        data:
          $ref: '#/components/schemas/AddressData'

    AddressData:
      title: AddressData
      type: object
      additionalProperties: true
      description: Data about the components comprising an address.
      properties:
        city:
          type: string
          description: The full city name
        street:
          type: string
          description: |-
            The full street address
            Example: `"564 Main Street, APT 15"`

Also, I could point out that the HEAD of the Plaid Quickstart still expects address data.

https://github.com/plaid/quickstart/blob/master/frontend/src/dataUtilities.ts line 423:

export const transformIdentityData = (data: IdentityData) => {
  const final: Array<DataItem> = [];
  const identityData = data.identity![0];
  identityData.owners.forEach((owner) => {
    const addresses = owner.addresses.map((address) => {
      return `${address.data.street} ${address.data.city}, ${address.data.region} ${address.data.postal_code}`;
    });

Root Cause

While I haven't inspected the generation code for this issue, do I have a suspicion.

Let's have a look at #/components/schemas/AddressMatchScore

    AddressMatchScore:
      title: address
      type: object
      nullable: true
      additionalProperties: true
      description: Score found by matching address provided by the API with the address on the account at the financial institution. If the account contains multiple owners, the maximum match score is filled.
      properties:
        score:
          type: integer
          nullable: true

Suspiciously, the title of this is address, just like the title of #/components/schemas/Address is also address. This leads me to believe the title field is being used as part of generation in a way we can't actually count on.

viceroypenguin commented 1 year ago

Oh wow. Good catch. I've submitted an issue to Plaid Open API repo to ask them to correct it (plaid/plaid-openapi#114). I'll hard-code a workaround for now.

viceroypenguin commented 1 year ago

Fixed w/ eae2af9618de465127e43bb101d3e3f23a7dd93c; released w/ v4.18.1

jcoliz commented 1 year ago

@viceroypenguin Thank you! Verified that the workaround functions as expected.