镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Name and Phone Fields On Address Model Should Not Be Required #12

Open

Description

@duncan-G

In the openapi.yaml, the name and phone fields on the partial address model as well as the address model are not nullable. This creates a problem in the validate address operation. Below you can see that the operation does not require name or phone in the request body.

    address_to_validate:
      title: address_to_validate
      type: object
      description: |
        Any residential or business mailing address, anywhere in the world.
      required:
        - address_line1
        - city_locality
        - state_province
        - country_code
      additionalProperties: false
      allOf:
        - $ref: '#/components/schemas/partial_address'

However, the response returns the original address, but the type for the original address is the address type which requires name and phone. See below.

    address:
      title: address
      type: object
      description: >
        Any residential or business mailing address, anywhere in the world.
        > **Note:** Either `name` or `company_name` must be set. Both may be
        specified, if relevant.
      required:
        - name  # <----- SHOULD NOT BE REQUIRED
        - phone # <----- SHOULD NOT BE REQUIRED
        - address_line1
        - city_locality
        - state_province
        - postal_code
        - country_code
        - address_residential_indicator
      additionalProperties: false
      allOf:
        - $ref: '#/components/schemas/partial_address'

On the partial_address, the name and phone are not set to be nullable. Maybe they should.

    partial_address:
      title: partial_address
      type: object
      description: A complete or partial mailing address.
      additionalProperties: false
      properties:
        name:
          type: string
          minLength: 1
          example: John Doe
          description: >
            The name of a contact person at this address.  This field may be set
            instead of - or in addition to - the `company_name` field.
         nullable: true # <---- MAYBE NEEDS TO BE NULLABLE
        phone:
          type: string
          minLength: 1
          nullable: true # <----  MAYBE NEEDS TO BE NULLABLE
          example: +1 204-253-9411 ext. 123
          description: >
            The phone number of a contact person at this address.  The format of
            this phone number varies depending on the country.

This error causes an issue when generating code for a strongly typed language or generating code with validation. The solution here is to make these fields not required or have separate address models.

Activity

  1. JamesMessinger commented on Mar 27, 2021

    @JamesMessinger
    Contributor

    Hi @duncan-G. Thanks for reporting this issue. This discrepancy is because we currently re-use the same address model in multiple places in the API, including both requests and responses. But in some fields are required in some places but optional in others. Same goes for nullability. So we really need to just create separate address models for each request/response rather than trying to re-use the same model everywhere. I'll file a Jira ticket for this and we'll get an engineer on it as soon as we can.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions