kzhang-dsg / bigcommerce-api-client

MIT License
17 stars 6 forks source link

Question: why do response types have optionals? #1

Open donferi opened 1 year ago

donferi commented 1 year ago

Hey, great library!

A quick question, i've noticed that the responses have for eg for Product where all the fields are optional, like id: string | undefined. Is this intended?

kzhang-dsg commented 1 year ago

Hi @donferi, the models are generated from the BigCommerce API spec: https://github.com/bigcommerce/api-specs. In the API spec, some of the fields are marked as optional.

For example, for the product_Full object (https://github.com/kzhang-dsg/bigcommerce-api-client/blob/master/src/model/generated/catalog.v3/models/product_Full.ts), it extends the product_Base object (https://github.com/kzhang-dsg/bigcommerce-api-client/blob/master/src/model/generated/catalog.v3/models/product_Base.ts). In the product_Base object, the name, type and weight are required according to the API spec. But other fields like sku and description are optional fields.

For id field, I agree it should not be optional for product_Full. The API spec did not mark it as required: https://github.com/bigcommerce/api-specs/blob/main/reference/catalog.v3.yml#L20038. We can create a PR to BigCommerce API Spec repo to get it fixed.