Skip to content

Open Api errors with openapi-typescript #21

Open

Description

@hannahbultra

Hi, I wanted to generate types from the provided yaml using openapi-typescript with this command:
openapi-typescript node_modules/shipengine-openapi/openapi.yaml --output src/types/ShipEngineTypes.ts

However, three types seem to have an issue, though not sure on the exact cause

  • pickup_response_body
  • get_rate_by_id_response_body
  • update_shipment_response_body

type and error for update_shipment_response_body

update_shipment_response_body: WithRequired<components["schemas"]["create_and_validate_shipment"], "errors" | "has_errors" | "address_validation" | "shipment_id" | "carrier_id" | "service_code" | "ship_date" | "created_at" | "shipment_status" | "ship_to" | "ship_from" | "return_to" | "confirmation" | "customs" | "advanced_options" | "insurance_provider" | "tags" | "packages" | "total_weight">;

Type '"created_at" | "ship_date" | "shipment_id" | "carrier_id" | "service_code" | "shipment_status" | "ship_to" | "ship_from" | "return_to" | "confirmation" | "customs" | "advanced_options" | ... 6 more ... | "address_validation"' does not satisfy the constraint '"created_at" | "modified_at" | "ship_date" | "shipment_id" | "carrier_id" | "service_code" | "shipment_status" | "ship_to" | "ship_from" | "warehouse_id" | "return_to" | "confirmation" | ... 15 more ... | "address_validation"'.
  Type '"has_errors"' is not assignable to type '"created_at" | "modified_at" | "ship_date" | "shipment_id" | "carrier_id" | "service_code" | "shipment_status" | "ship_to" | "ship_from" | "warehouse_id" | "return_to" | "confirmation" | ... 15 more ... | "address_validation"'.ts(2344)

type and error for get_rate_by_id_response_body

get_rate_by_id_response_body: WithRequired<components["schemas"]["rate"], "rates" | "invalid_rates" | "rate_request_id" | "shipment_id" | "created_at" | "status" | "errors">;

Type '"shipment_id" | "created_at" | "errors" | "rates" | "invalid_rates" | "rate_request_id" | "status"' does not satisfy the constraint '"carrier_id" | "service_code" | "ship_date" | "carrier_code" | "estimated_delivery_date" | "package_type" | "requested_comparison_amount" | "trackable" | "rate_type" | "validation_status" | ... 15 more ... | "error_messages"'.
  Type '"shipment_id"' is not assignable to type '"carrier_id" | "service_code" | "ship_date" | "carrier_code" | "estimated_delivery_date" | "package_type" | "requested_comparison_amount" | "trackable" | "rate_type" | "validation_status" | ... 15 more ... | "error_messages"'.ts(2344)

I thought it could be an issue with required fields, for example from the yaml:

    get_rate_by_id_response_body:
      title: get_rate_by_id_response_body
      type: object
      description: A rate response body
      required:
        - rates
        - invalid_rates
        - rate_request_id
        - shipment_id
        - created_at
        - status
        - errors

in this case I'm not sure if rates should be required for Get Rate By Id which should only be returning one rate based on https://shipengine.github.io/shipengine-openapi/#operation/get_rate_by_id

or in the case of pickup_response_body, pickup is required in addition to all the properties of "pickup" such as pickup_id

pickup_response_body:
      title: pickup_response_body
      type: object
      description: A pickup response body
      required:
        - pickup
        - pickup_id
        - label_ids
        - created_at
        - carrier_id
        - warehouse_id
        - pickup_address
        - contact_details
        - notes
        - pickup_window
        - confirmation_number
      additionalProperties: false
      allOf:
        - $ref: '#/components/schemas/pickup'

Activity

  1. hannahbultra commented on Feb 20, 2024

    @hannahbultra
    Author

    the following modifications do enable the types to work if this is helpful:

    • update_shipment_response_body:
      removed "has_errors" as one of the properties within the WithRequired helper type.
      this seems to be a required property of the Create Shipment api and its schema is used
      under allof for the Update Shipment api. based on the docs it seems like "has_errors" will
      not be returned by the Update Shipment api

    • pickup_response_body
      removed the "pickup" and "notes" properties used within the WithRequired helper type
      the pickup property has all the same properties that are already within the schema. I was not
      sure but is it possible the "notes" property should be the "pickup_notes" property under required?

    • get_rate_by_id_response_body
      removed the usage of WithoutRequired helper type entirely. It had the
      properties: "rates", "invalid_rates", "rate_request_id", "shipment_id", "created_at",
      "status" and "errors"

      these are all required properties returned from the Get Shipping Rates api which returns
      more than one rate and shipment info
      
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