Parameter with required and example fails valid-example rule
See original GitHub issueI’m submitting a…
- bug report
What is the current behavior?
If you have a parameter that has required: true
and an example, the valid-example
rule fails. See “Other information” for details.
What is the expected behavior?
The valid-example
rule executes successfully for a valid parameter example as it understands that required is not a list for parameters but a boolean.
What is the motivation / use case for changing the behavior?
The valid-example
rule is very helpful and it should work for parameters
Please tell us about your environment:
$ spectral --version
@stoplight/spectral/3.0.0 linux-x64 node-v12.2.0
Other information
Given this schema
openapi: "3.0.0"
info:
version: 1.0.0
title: Swagger Petstore
description: Swagger Petstore
license:
name: MIT
contact:
name: Test
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets/{petId}:
get:
summary: Info for a specific pet
operationId: showPetById
description: Get a pet
tags:
- pets
parameters:
- name: petId
in: path
required: true
description: The id of the pet to retrieve
schema:
type: string
example: "1234567890"
responses:
'200':
description: Expected response to a valid request
Running spectral lint myschema.yml
results in:
Adding OpenAPI 3.x functions
OpenAPI 3.x detected
Encountered error when running rule 'valid-example' on node at path '$,paths,/pets/{petId},get,parameters,0':
Error: schema is invalid: data/required should be array
No errors or warnings found!
As an aside, an “error” was found but yet spectral says “No errors or warnings found!” and the return code is 0
. Why the discrepancy?
Thanks a lot. Let me know if I can help!
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (8 by maintainers)
Top Results From Across the Web
aws cli - get-parameters-by-path is not working as documented
An error occurred (ValidationException) when calling the GetParametersByPath operation: The parameter doesn't meet the parameter name ...
Read more >ibm-openapi-validator - npm
The validator analyzes your API definition and reports any problems within. The validator is highly customizable, and supports both OpenAPI 3.0 and OpenAPI...
Read more >Statutory Requirements for a Valid Written Will - LawShelf
A rule of law, statutory or judicial, that accepts the validity of a fact until it is rebutted. Once accepted, the burden shifts...
Read more >13 Configuring DDL Support - Oracle Help Center
This chapter contains information to help you understand and configure DDL support in Oracle GoldenGate.
Read more >Assignment: Operational Semantics
If you need to write an implication, use the words “if” and “then.” Do not use inference-rule notation—every new inference rule risks inadvertently...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @cbautista1002, @philsturgeon.
Great conversation so far and thanks for reporting! We’ve made some progress on this but aren’t quite done yet - bear with us!
Just wanted to add my two cents here.
The OAS documentation says
Note it says “SHOULD” not “MUST”. This means that the final solution we’ll present should imo return a warning (vs error) if there is a mismatch.
@cbautista1002 FYI you can still use ‘required’ if you put the example inside the schema. The following example works:
If at all possible it should be done for v4.0 but it could be 4.0.1. This rule is broken in certain situations, but it’s not effecting too many people, and can be skipped as a workaround, so it’s not a blocker.
– Phil Sturgeon @philsturgeon