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.

use of $ref in paths parameters errors for "in: path" parameters

See original GitHub issue

An error message is currently generated when using $ref for in: path (in: query and in: body work fine) parameters from within the paths description, e.g. - $ref: ‘#/parameters/tag-name’, where tag-name appears in the path, e.g. /tags/{tag-name}:

Q A
Bug or feature request? Bug
Which Swagger/OpenAPI version? swagger 2.0
Which Swagger-Editor version? http://editor.swagger.io/ (but not http://editor2.swagger.io)
How did you install Swagger-Editor? online editor
Which browser & version? Tried Chrome and Firefox, same error in both cases
Which operating system? Windows

Example extracted from the Instagram API example file:

swagger: '2.0'

info:
  version: v1
  title: Instagram API
host: api.instagram.com
basePath: /v1
schemes:
  - https
produces:
  - application/json
consumes:
  - application/json

parameters:
  tag-name:
    name: tag-name
    in: path
    description: Tag name
    type: string
    required: true
paths:
  /tags/{tag-name}:
    parameters:
      - $ref: '#/parameters/tag-name'
    get:
      description: Get information about a tag object.
      responses:
        200:
          description: OK
          schema:
            $ref: '#/definitions/Tag'
definitions:
  Tag:
    type: object
    properties:
      media_count:
        type: integer
      name:
        type: string

This results in the following error:

Semantic error at paths./tags/{tag-name} Declared path parameter “tag-name” needs to be defined as a path parameter at either the path or operation level Jump to line 23

However, the UI recognises what the tag-name is and allows the “Try it out” operation to be performed

To avoid the error, the parameter definition can be brought in-line (see below), but this is undesirable if many operations reference the same parameter.

paths:
  /tags/{tag-name}:
    parameters:
      - name: tag-name
        in: path
        description: Tag name
        type: string
        required: true

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:7
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
wol190commented, Jan 4, 2018

Thanks for the issue references - I’d only searched on open issues when raising this, but thankfully raising this separately has turned out to be appropriate

0reactions
CharlieReitzelcommented, Aug 27, 2019

Will do. Just wanted to be sure I wasn’t doing something wrong, first.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Swagger 2.0 semantic error with $ref to path parameter
The problem occurs when I use a reference object to define a path parameter that is shared between multiple endpoints. Example endpoints:
Read more >
Describing Parameters - Swagger
In OpenAPI 3.0, parameters are defined in the parameters section of an operation or path. To describe a parameter, you specify its name...
Read more >
OpenAPI Specification v3.1.0 | Introduction, Definitions, & More
The value for these path parameters MUST NOT contain any unescaped “generic ... General Error content: application/json: schema: $ref: ...
Read more >
Fix Swagger Validator errors in Power Platform connectors
There is a parameter in one of your operations which is marked as being in the operation path but does not exist in...
Read more >
Step 4: The paths object (OpenAPI tutorial) | Documenting APIs
Operation Objects · externalDocs (object): Links to documentation for more information about the path. · parameters (object): Parameters accepted ...
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