Skip to content
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

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

Open
duncan-G opened this issue Mar 26, 2021 · 1 comment
Open

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

duncan-G opened this issue Mar 26, 2021 · 1 comment

Comments

@duncan-G
Copy link

duncan-G commented Mar 26, 2021

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.

@JamesMessinger
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants