swagger-api / swagger-api/swagger-parser

Invalid references do not throw parser error

Open
#1,396 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
867
Forks
560
Avg merge
2d 21h
Merged PRs (30d)
7

Description

In the attached open API document, the response schema is referencing a parameter rather than a schema. This is an invalid use case and should throw an error during parsing. I noticed when $refs are invalid, they usually are not validated correctly.

How should the implementation handle this scenario? Should it throw an error? Should it ignore that response or schema?

There needs to be a consistent approach in handling this, and hence I'm asking this question.

openapi: 3.0.1
info:
title: Swagger Petstore
description: 'This is a sample server Petstore server'
version: 1.0.0
servers:

  • url: http://mytestServer/{v1}
    variables:
    v2:
    default: 'd'
    paths:
    '/pet/{petId}':
    get:
    parameters:
    - $ref: '#/components/parameters/P1'
    responses:
    '200':
    $ref: '#/components/responses/R1'
    components:
    responses:
    R1:
    description: The specified resource was not found
    content:
    application/json:
    schema:
    $ref: '#/components/parameters/P1'
    parameters:
    P1:
    in: path
    name: petId
    schema:
    type: string
    required: true

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the embedded OpenAPI 3.0.1 document in the parser and trace how the response schema resolves its $ref to components/parameters/P1. Determine the consistent behavior for this invalid reference, then verify that parsing handles it accordingly for the response schema and related invalid references.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.