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 fails to validate when specified as a $ref

See original GitHub issue

Parameters specified as a $ref are not validated

Here is an example

Define the following parameter under components.parameters

components:
  parameters:
    id:
      name: id
      in: path
      description: ID of pet to fetch
      required: true
      schema:
        type: integer
        format: int64

Use the parameter in a route:

paths:
  /pets/{id}:
    get:
      description: Returns a user based on a single ID, if the user does not have access to the pet
      operationId: find pet by id
      parameters:
        - $ref: '#/components/parameters/id'

The component #/components/parameters/id' is not validated. It works if the component is placed inline without using a ref. This is not desirable given parameters may be specified generally as a ref

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
jbergercommented, Feb 17, 2020

I had assumed there was a centralized $ref parser in action somewhere. After finding a series of commits that enabled $ref in response bodies (I think it was) I’ve decided that I’m not the right person to poke this particular $ref bug. For the future reader, I’ve switched to pre-parsing my schema doc with json-schema-ref-parser and then passing that to express-openapi. It seems to work well for me so far. Cheers.

0reactions
Gabrirfcommented, Sep 10, 2021

I think this is another case of this kind of error, since @jberger said that is a centralized error.

openapi: 3.0.1
info:
  title: Herency Example
  version: 1.0.0
paths: {}
components:
  schemas:
    ItemBase:
      type: object
      properties:
        name:
          type: string
    Item:
      allOf:
        - $ref: '#/components/schemas/ItemBase'
        - type: object
          properties:
            color:
              type: string
        - required: [name]
        - additionalProperties: false

If I try to validate a body with the key name it fails because additionalProperties: false. But if I don’t send name, it fails because it’s required.

I guess that is because is reading only in his schema level, and is not recursive the validation.

But the schema is well formed, in the Swagger UI you can see it full.

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolve the "Parameter validation failed" error in AWS ...
You can receive this error when you use an AWS-specific parameter: To pass a value that doesn't exist in the AWS Region or...
Read more >
[BUG] $ref to common parameter not being resolved #1714
Description. Validation is failing to resolve a $ref in the parameter list to a common parameter defined outside the operation.
Read more >
Validating parameters (“input rules”)
Input rules define whether or not parameters are required, and their maximum allowed length, for requests that match: Host: field in the HTTP...
Read more >
What is wrong with Parameter validation failed. It is not ...
Parameter validation failed. It is not possible to provide valid values for all parameters. (rsParameterError).
Read more >
Parameter validation failed: parameter value for parameter ...
The Subnets Parameter in your template has a type List<AWS::EC2::Subnet::Id> , which requires a reference to a list of valid Subnet IDs. The...
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