Skip to content

Commit

Permalink
ISSUE-249: [update] Spectral & OAS, add obj properties and array item…
Browse files Browse the repository at this point in the history
…s to linter + fixes (#254)

<!-- Ticket number or summary of work -->
* #249


## What changed?
<!-- Provide a bulleted list in the present tense -->
* Update spectral linter to remove old caveats
* Update spectral linter to add the following requirements
  * all objects have a properties attribute 
  * all arrays have an items attribute
  * all schemas with a properties attribute have type: object
* Update the spec files to meet the new linting requirements

## Release notes draft
<!-- Provide an entry for the release notes using simple, conversational
language. Don't be too technical. Explain how the change will benefit
the merchant and link to the feature.

Examples:
* The newly-released [X feature] is now available to use. Now, you’ll be
able to [perform Y action].
* We're happy to announce [X feature], which can help you [perform Y
action].
* [X feature] helps you to create [Y response] using the [Z query
parameter]. Now, you can deliver [ex, localized shopping experiences for
your customers].
* Fixed a bug in the [X endpoint]. Now the [Y field] will appear when
you click [Z option]. -->
* 

## Anything else?
<!-- Add related PRs, salient notes, additional ticket numbers, etc. -->

ping @jb-gourav
  • Loading branch information
Sarah Riehl authored May 6, 2024
1 parent 7a92b37 commit 20525cb
Show file tree
Hide file tree
Showing 49 changed files with 1,170 additions and 1,294 deletions.
131 changes: 41 additions & 90 deletions .spectral.yaml
Original file line number Diff line number Diff line change
@@ -1,93 +1,44 @@
extends: spectral:oas
rules:
info-contact: off
oas3-unused-component: off
oas2-unused-definition: off
except:
'reference/tax_provider.yml':
- oas3-schema
'reference/carts.v3.yml':
- oas2-oneOf
- oas2-valid-schema-example
- operation-tag-defined
'reference/catalog.v3.yml':
- oas2-operation-security-defined
- oas3-schema
- oas2-schema
- oas2-valid-media-example
- oas2-valid-schema-example
'reference/channels.v3.yml':
- oas3-schema
- oas3-valid-media-example
'reference/current_customer.yml':
- operation-success-response
'reference/custom-template-associations.v3.yml':
- openapi-tags
- operation-tag-defined
'reference/customer_login.yml':
- operation-success-response
'reference/email_templates.v3.yml':
- oas3-schema
'reference/geography.v2.yml':
- oas2-valid-media-example
'reference/orders.v2.oas2.yml':
- oas3-valid-schema-example
- oas3-valid-media-example
- oas3-schema
'reference/orders.v3.yml':
- oas2-valid-schema-example
- oas2-valid-media-example
- oas2-anyOf
'reference/settings.v3.yml':
- oas3-valid-media-example
'reference/sites.v3.yml':
- oas2-valid-media-example
'reference/store_information.v2.yml':
- oas2-valid-media-example
- oas2-valid-schema-example
'reference/themes.v3.yml':
- oas3-schema
'reference/webhooks.v3.yml':
- oas3-valid-media-example
'carts.v3.yml':
- oas2-oneOf
- oas2-valid-schema-example
'catalog.v3.yml':
- oas2-operation-security-defined
- oas3-schema
- oas2-schema
- oas2-valid-media-example
- oas2-valid-schema-example
'channels.v3.yml':
- oas3-schema
- oas3-valid-media-example
'current_customer.yml':
- operation-success-response
'customer_login.yml':
- operation-success-response
'email_templates.v3.yml':
- oas3-schema
'geography.v2.yml':
- oas2-valid-media-example
'orders.v2.oas2.yml':
- oas3-valid-schema-example
- oas3-valid-media-example
- oas3-schema
'orders.v3.yml':
- oas2-valid-schema-example
- oas2-valid-media-example
- oas2-anyOf
'settings.v3.yml':
- oas3-valid-media-example
'sites.v3.yml':
- oas2-valid-media-example
'store_information.v2.yml':
- oas2-valid-media-example
- oas2-valid-schema-example
'themes.v3.yml':
- oas3-schema
'webhooks.v3.yml':
- oas3-valid-media-example
'pages.v3.yml':
- oas3-valid-media-example
- oas3-valid-schema-example
properties-type-object:
description: "type: object must have a properties sibling."
given: "$..[?(@ && @.type == 'object')]"
severity: error
# must not be resolved because $ref-defined objects shall have its type
# defined in the referenced schema, not the referencing field (and $ref
# must be the only property, anyway)
resolved: false
# type field must be defined and contain the value object
then:
- field: "properties"
function: "truthy"
items-type-array:
description: "type: array must have an items sibling."
given: "$..[?(@ && @.type == 'array')]"
severity: error
# must not be resolved because $ref-defined objects shall have its type
# defined in the referenced schema, not the referencing field (and $ref
# must be the only property, anyway)
resolved: false
# type field must be defined and contain the value object
then:
- field: "items"
function: "truthy"
type-object-properties:
description: "Objects with properties must have type: object."
given: "$..[?(@ && @.properties)]"
severity: error
# must not be resolved because $ref-defined objects shall have its type
# defined in the referenced schema, not the referencing field (and $ref
# must be the only property, anyway)
resolved: false
# type field must be defined and contain the value object
then:
- field: "type"
function: defined
- field: "type"
function: enumeration
functionOptions:
values:
- object
4 changes: 0 additions & 4 deletions reference/.spectral.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
extends:
- spectral:oas
- ../.spectral.yaml
rules:
info-contact: off
oas3-unused-components: off
oas2-unused-definition: off
1 change: 1 addition & 0 deletions reference/abandoned_cart_emails.v3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ paths:
required:
- locale
- keys
type: object
properties:
locale:
type: string
Expand Down
3 changes: 3 additions & 0 deletions reference/abandoned_carts.v3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ components:
properties:
errors:
type: object
properties: {}
additionalProperties:
type: string
title: DetailedErrors
Expand Down Expand Up @@ -508,6 +509,8 @@ components:
type: string
errors:
type: object
properties: {}
additionalProperties: true
x-tags:
- Models

45 changes: 25 additions & 20 deletions reference/carts.sf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,9 @@ components:
requestCart:
title: Create Cart Request Object
description: Cart object used in create cart requests.
oneOf:
- properties:
anyOf:
- type: object
properties:
lineItems:
type: array
items:
Expand All @@ -391,7 +392,8 @@ components:
type: string
required:
- lineItems
- properties:
- type: object
properties:
giftCertificates:
type: array
items:
Expand All @@ -400,7 +402,8 @@ components:
type: string
required:
- giftCertificates
- properties:
- type: object
properties:
lineItems:
type: array
items:
Expand All @@ -412,8 +415,6 @@ components:
required:
- lineItems
- giftCertificates
type: object
x-internal: false
responseCartLineItemsPhysicalItemGiftWrapping:
title: Gift Wrapping
type: object
Expand Down Expand Up @@ -498,22 +499,25 @@ components:
example: Happy Birthday
LineItemsRequest:
title: requestLineItems
oneOf:
- properties:
anyOf:
- type: object
properties:
lineItems:
type: array
items:
$ref: '#/components/schemas/requestCartPostLineItem'
required:
- lineItems
- properties:
- type: object
properties:
giftCertificates:
type: array
items:
$ref: '#/components/schemas/requestLineItemGiftCertificate'
required:
- giftCertificates
- properties:
- type: object
properties:
lineItems:
type: array
items:
Expand All @@ -523,25 +527,27 @@ components:
required:
- lineItems
- giftCertificates
type: object
description: Cart object used in add items requests.
x-internal: false
requestLineItemPut:
title: requestLineItemPut
oneOf:
- properties:
anyOf:
- type: object
properties:
lineItem:
$ref: '#/components/schemas/requestCartPostLineItem'
required:
- lineItem
title: Line item
- properties:
- type: object
properties:
giftCertificates:
$ref: '#/components/schemas/requestLineItemGiftCertificate'
required:
- giftCertificates
title: Gift certificate item
- properties:
- type: object
properties:
lineItem:
$ref: '#/components/schemas/requestCartPostLineItem'
giftCertificates:
Expand All @@ -551,8 +557,6 @@ components:
- giftCertificates
title: line & gift certificate items
description: ''
type: object
x-internal: false
responseCartCurrency:
title: Currency
type: object
Expand Down Expand Up @@ -904,7 +908,8 @@ components:
requestCartPostLineItem:
title: Line Item Request Data
anyOf:
- properties:
- type: object
properties:
productId:
type: number
description: ID of the product.
Expand All @@ -917,7 +922,8 @@ components:
- productId
- quantity
title: Simple product
- properties:
- type: object
properties:
productId:
type: number
description: ID of the product.
Expand All @@ -939,7 +945,6 @@ components:
productId: 0
quantity: 0
x-internal: false
type: object
requestLineItemGiftCertificateRecipient:
title: Contact Entity
type: object
Expand Down
Loading

0 comments on commit 20525cb

Please sign in to comment.