question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Parameter with required and example fails valid-example rule

See original GitHub issue

I’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:closed
  • Created 4 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
chris-miaskowskicommented, Jun 13, 2019

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

The example SHOULD match the specified schema and encoding properties if present.

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:

parameters:
        - name: petId
          in: path
          required: true
          description: The id of the pet to retrieve
          schema:
            type: string
            example: "1234567890"
0reactions
philsturgeoncommented, Jul 7, 2019

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

On Jul 6, 2019, at 20:32, Brian Rock notifications@github.com wrote:

@philsturgeon I have this tagged for next sprint, but if its not needed fro v4.0 release, lets leave it on the backlog.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found