pythonopenapi

OpenAPI $ref not working in outside folder Error: "Could not resolve reference: undefined undefined"


I cannot to use $ref outside other folder, it only use inside the same folder, i use relative path not work I try many solution and search many post, but they not work

Structure Folder:

-src 
   -common
      -responses.yaml
   -company
      -base_compamy.yaml
      -company_list.yaml
      -response.yaml
      -...

company_list.yaml

  ...
  200:
    401:
      $ref: '../common/responses.yaml/#/status/401'
    404:
      $ref: 'responses.yaml/#/status/404'
    405:
      $ref: 'responses.yaml/#/status/405'
    412:
      $ref: 'responses.yaml/#/status/412'
    500:
      $ref: 'responses.yaml/#/status/500'

responses.yaml

...
status:
  401:
    description: "Token is invalid or is expired. Please login again."
    content:
      application/json:
        schema:
          type: object
          properties:
            code:
              type: integer
              example: 401
            message:
              type: string
              example: "Token is invalid or is expired. Please login again."
  404:
    description: "Not Found"
    content:
      application/json:
        schema:
          type: object
          properties:
            code:
              type: integer
              example: 404
            message:
              type: string
  

How to fix it? thanks for readinggg!!!!!!!!!!!!!!!!!!!!!!


Solution

  • The anchor # should be after the file type which indicates the root of the file you are referencing.

    $ref: '../common/responses.yaml#/status/401'