swagger-parser icon indicating copy to clipboard operation
swagger-parser copied to clipboard

'#/paths/~1path/get/requestBody/content/application~1json/schema' not resolved with ResolverFully

Open slinkydeveloper opened this issue 7 years ago • 4 comments

Bug

The local refs to another schema inside a path definition is not resolved using ResolverFully. This types of refs are discouraged, but they can be done according to spec and docs https://swagger.io/docs/specification/using-ref/

Steps to reproduce

Try to load with setResolveFully true this spec:

openapi: 3.0.0
info:
  version: 1.0.0
  title: JSON Schemas test spec
  license:
    name: MIT
paths:
  /test1:
    get:
      operationId: test1
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Person'
      responses:
        default:
          description: "OK"
  /test4:
    get:
      operationId: test4
      responses:
        default:
          description: "OK"
      requestBody:
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/paths/~1test1/get/requestBody/content/application~1json/schema'
                - $ref: '#/components/schemas/Citizen'

components:
  schemas:
    Person:
      type: object
      additionalProperties: {}
      properties:
        name:
          type: string
        surname:
          type: string
      required:
        - name
        - surname
    Citizen:
      type: object
      additionalProperties: {}
      properties:
        id_card:
          type: string
      required:
        - id_card

slinkydeveloper avatar Nov 28 '17 16:11 slinkydeveloper

Thanks for the report. Since, as you mentioned, this type of $refs is discouraged, we won't be able to prioritize a fix for this over other issues. If, however, you'd like to submit a PR that resolves it, we'd be happy to review and merge.

webron avatar Nov 28 '17 22:11 webron

My bad that PR doesn't address this issue

gracekarina avatar Dec 26 '17 17:12 gracekarina

If you can find useful, here is another reproducer: debts_manager_api.zip. The only error message is "All elements are null". I generated this spec starting with speccy.io

slinkydeveloper avatar Mar 04 '19 15:03 slinkydeveloper

Can you please provide the reference which says this type of ref is discouraged? I can't find it and I think it's still a valid usage.

xuehung avatar Jul 31 '23 17:07 xuehung