mirror of
https://github.com/adidas/api-guidelines.git
synced 2025-10-25 15:19:19 +00:00
Split example validation for different spec versions. OAS2 One WiP
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
extends: [spectral:oas2, spectral:oas3]
|
||||
rules:
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# General OAS rules
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
operation-operationId: false
|
||||
operation-tags: info
|
||||
operation-2xx-response: error
|
||||
@@ -57,6 +61,7 @@ rules:
|
||||
# ---------------------------------------------------------------------------
|
||||
# Only OAS2 rules
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
protocol-https-only:
|
||||
description: "ALL requests MUST go through `https` protocol only"
|
||||
formats:
|
||||
@@ -93,19 +98,29 @@ rules:
|
||||
type: string
|
||||
enum:
|
||||
- application/json
|
||||
# valid-example-in-definitions: has to be turned off for oas2 but not for oas3
|
||||
example-exists:
|
||||
description: All models MUST have a valid example.
|
||||
severity: error
|
||||
recommended: true
|
||||
formats:
|
||||
- oas2
|
||||
message: "{{ property }} MUST have a valid example."
|
||||
given: $.definitions[?(!@.example)]
|
||||
then:
|
||||
function: falsy
|
||||
# example-exists-in-parameters:
|
||||
# description: All models MUST have a valid example.
|
||||
# severity: error
|
||||
# recommended: true
|
||||
# formats:
|
||||
# - oas2
|
||||
# message: "{{ property }} MUST have a valid example."
|
||||
# given: "$..parameters..[?(@.in == 'body' && ( !@.example || !@..$ref))]"
|
||||
# then:
|
||||
# function: falsy
|
||||
# example-exists-in-definitions:
|
||||
# description: All models MUST have a valid example.
|
||||
# severity: error
|
||||
# recommended: true
|
||||
# formats:
|
||||
# - oas2
|
||||
# message: "{{ property }} MUST have a valid example."
|
||||
# given: "$..definitions..[?(!@.example || !@..$ref)]"
|
||||
# then:
|
||||
# function: falsy
|
||||
# "$..parameters..[?(@.in == 'body')]..[?(@property !== 'properties' && @.example && ( @.type || @.format || @.$ref ))]"
|
||||
response-success-hal: # schemes and/or produces
|
||||
description: All success responses MUST be of media type `application/hal+json`
|
||||
description: "All success responses MUST be of media type `application/hal+json`"
|
||||
severity: error
|
||||
given: $.paths..responses[?( @property >= 200 && @property < 300 && @property != 204)]
|
||||
recommended: true
|
||||
@@ -118,8 +133,8 @@ rules:
|
||||
function: schema
|
||||
functionOptions:
|
||||
schema:
|
||||
$ref: ./supermodel/adidas/api/HAL.yaml
|
||||
response-error-problem: # schemes and/or produces
|
||||
$ref: "./supermodel/adidas/api/HAL.yaml"
|
||||
response-error-problem: # schemas and/or produces
|
||||
description: All error responses MUST be of media type `application/problem+json`
|
||||
severity: error
|
||||
formats:
|
||||
@@ -133,11 +148,12 @@ rules:
|
||||
function: schema
|
||||
functionOptions:
|
||||
schema:
|
||||
$ref: ./supermodel/adidas/api/ProblemDetail.yaml
|
||||
$ref: "./supermodel/adidas/api/ProblemDetail.yaml"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Only OAS3 rules
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
#request-support-json-oas3: # this needs check the body parameter for content property and its value
|
||||
# description: Every request SHOULD support `application/json` media type
|
||||
# formats:
|
||||
@@ -150,6 +166,36 @@ rules:
|
||||
# function: pattern
|
||||
# functionOptions:
|
||||
# match: "/^https:[a-zA-Z0-9./_@-~]+/"
|
||||
valid-example-in-parameters:
|
||||
description: Examples must be valid against their defined schema.
|
||||
message: "{{error}}"
|
||||
recommended: true
|
||||
formats:
|
||||
- oas3
|
||||
severity: 0
|
||||
type: validation
|
||||
given: "$..parameters..[?(@.in == 'body')]..[?(@property !== 'properties' && @.example
|
||||
&& ( @.type || @.format || @.$ref ))]"
|
||||
then:
|
||||
function: schemaPath
|
||||
functionOptions:
|
||||
field: example
|
||||
schemaPath: "$"
|
||||
valid-example-in-definitions:
|
||||
description: Examples must be valid against their defined schema.
|
||||
message: "{{error}}"
|
||||
recommended: true
|
||||
formats:
|
||||
- oas3
|
||||
severity: 0
|
||||
type: validation
|
||||
given: "$..definitions..[?(@property !== 'properties' && @.example && (@.type ||
|
||||
@.format || @.$ref))]"
|
||||
then:
|
||||
function: schemaPath
|
||||
functionOptions:
|
||||
field: example
|
||||
schemaPath: "$"
|
||||
protocol-https-only-oas3: # checks how does the servers array values start
|
||||
description: "ALL requests MUST go through `https` protocol only"
|
||||
formats:
|
||||
|
||||
Reference in New Issue
Block a user