Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger schema reference in another file

Tags:

yaml

swagger

I'm working on huge yaml schema when I'm designing my swagger API service model and emphasized textI would like to save the model part in another file in order to have more flexibility and lisibility.

Following this documentation, I used this part of code :

components:
  schemas:
    Request:
      title: Request
      type: object
      properties:
        technicalData:
          $ref: '../../schemas/foo.yaml/components/schemas/TechnicalData'

And in my foo.yaml file, I have stuff like this :

components:
  schemas:
    TechnicalData:
      type: object
      properties:
        application:
          type: string
        applicationCode:
          type: string
        userId:
          type: string

It works on localhost, but I face the following issue running my file on the enterprise deployement server :

Errors Resolver error at components.schemas.Request.properties.technicalData.$ref Could not resolve reference because of: Not Acceptable

I am sucessfully able to browse my file through the browser locally.

Checking on the internet, I found some issue related to my topic, but unfortunately not very usefull : https://github.com/swagger-api/swagger-editor/issues/1561

https://github.com/RepreZen/KaiZen-OpenAPI-Editor/issues/438

like image 304
Xavier W. Avatar asked Sep 01 '26 20:09

Xavier W.


1 Answers

Add # between the file name and /components/...:

$ref: '../../schemas/foo.yaml#/components/schemas/TechnicalData'
                             ^
like image 145
Helen Avatar answered Sep 04 '26 09:09

Helen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!