You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to create a spectral ruleset that checks whether 200 or 400 responses have a schema.$ref tag
OPEN API YAML - myapi.yaml
openapi: 3.0.3info:
title: Simple APIdescription: A simple OpenAPI specification with a single endpointversion: 1.0.0paths:
/example:
post:
summary: Example API endpointdescription: Accepts a request DTO and returns a response DTOoperationId: exampleOperationrequestBody:
required: truecontent:
application/json:
schema:
$ref: '#/components/schemas/RequestDTO'responses:
"200":
description: Successful responsecontent:
application/json:
schema:
$ref: '#/components/schemas/ResponseDTO'"400":
description: Bad requestcontent:
application/json:
schema:
$ref: '#/components/schemas/ExceptionDTO'components:
schemas:
RequestDTO:
type: objectproperties:
id:
type: stringformat: uuidname:
type: stringrequired:
- id
- nameResponseDTO:
type: objectproperties:
message:
type: stringtimestamp:
type: stringformat: date-timerequired:
- message
- timestampExceptionDTO:
type: objectproperties:
error:
type: stringdetails:
type: stringrequired:
- error
My custom spectral ruleset - .spectral.yaml
rules:
response-schema-ref-required:
description: "Responses with status codes 200, 400, or 500 must have a schema with a $ref key."message: "Response schema must reference a schema via $ref."severity: errorgiven: "$.paths[*][*].responses[200,400,500].content[*].schema"then:
field: $reffunction: truthy
run - npx spectral lint myapifile.yaml
Response -
/Users/myuser/Downloads/spectral-demo/myapifile.yaml
47:17 error response-schema-ref-required Response schema must reference a schema via $ref. components.schemas.ResponseDTO
59:18 error response-schema-ref-required Response schema must reference a schema via $ref. components.schemas.ExceptionDTO
Why is it checking in components.schemas when we have specifically mentioned - given: "$.paths ?
The text was updated successfully, but these errors were encountered:
I want to create a spectral ruleset that checks whether 200 or 400 responses have a schema.$ref tag
OPEN API YAML - myapi.yaml
My custom spectral ruleset - .spectral.yaml
run - npx spectral lint myapifile.yaml
Response -
/Users/myuser/Downloads/spectral-demo/myapifile.yaml
47:17 error response-schema-ref-required Response schema must reference a schema via $ref. components.schemas.ResponseDTO
59:18 error response-schema-ref-required Response schema must reference a schema via $ref. components.schemas.ExceptionDTO
Why is it checking in components.schemas when we have specifically mentioned - given: "$.paths ?
The text was updated successfully, but these errors were encountered: