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.

Path item $refs override inline operations instead of merging

See original GitHub issue
Q A
Bug or feature request? Bug
Which Swagger/OpenAPI version? 2.0, 3.0.0
Which Swagger-UI version? 3.2.0
How did you install Swagger-UI? http://editor.swagger.io
Which browser & version? Chrome 61
Which operating system? Windows 7

Demonstration API definition

2.0 spec:

swagger: '2.0'
info:
  version: 0.0.0
  title: Path item $ref test

paths:
  /foo:
    get:
      responses:
        200:
          description: OK

  /foo2:
    $ref: '#/paths/~1foo'
    post:
      summary: Create a foo2
      responses:
        201:
          description: Created

3.0 spec:

openapi: 3.0.0
info:
  version: 0.0.0
  title: Path item $ref test

paths:
  /foo:
    get:
      responses:
        '200':
          description: OK

  /foo2:
    $ref: '#/paths/~1foo'
    post:
      summary: Create a foo2
      responses:
        '201':
          description: Created

Expected Behavior

/foo2 displays both GET (added by $ref) and POST (defined inline).

Current Behavior

/foo2 displays GET only.

Context

According to https://github.com/OAI/OpenAPI-Specification/issues/1038#issuecomment-295594246, when a path item contains a $ref, the referenced operation is added (merged) to other operations in this path. Unlike regular JSON references, path item $refs are not supposed to override their sibling elements.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
hkosovacommented, Nov 19, 2020

@Skeeve the next version of the OpenAPI Specification, 3.1, will support $ref siblings in schemas. Outside of schemas, $refs will allow sibling summary and description keywords. In the meantime, the workaround to add extra properties to a schema $ref is to wrap the $ref into allOf.

0reactions
Skeevecommented, Nov 20, 2020

Hmmm… Could it be, this is correct?

  /manage/client:
    post:
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Client'
    put:
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                anyOf:
                  $ref: '#/components/schemas/Client/properties'
Read more comments on GitHub >

github_iconTop Results From Across the Web

Using $ref - Swagger
OAS 3 This guide is for OpenAPI 3.0. Using $ref. When you document an API, it is common to have some features which...
Read more >
Compound paths and shapes in InDesign - Adobe Support
You can combine several paths into a single object, called a compound path. Create a compound path when you want to do any...
Read more >
Review a merge request - GitLab Docs
It allows checking out a merge request by using its ID instead of its branch. Introduced in GitLab 13.4, 14 days after a...
Read more >
OpenAPI Specification v3.0.3 | Introduction, Definitions, & More
4.7.9.1 Fixed Fields; 4.7.9.2 Path Item Object Example. 4.7.10 Operation Object ... Individual operations can override this definition.
Read more >
How to Edit, Customize, and Override Bootstrap CSS to Suit ...
You can override the default styles of Bootstrap elements using two possible methods. The first way — using CSS overrides— applies to sites ......
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