Unable to follow/detect model reference in another file ($ref)
See original GitHub issueHi!
I first created this bug in swagger-codegen project ( https://github.com/swagger-api/swagger-codegen/issues/6813 ) but then I created a small project with swagger-parser and could reproduce the issue. It is definitely a bug is swagger-parser.
The problem is that swagger-parser doesn’t seems to follow $ref in other files, thus preventing the use of multi files specs. Is is supposed to be supported? Is there a problem in my spec? Is there any workarounds?
You can reproduce easily by loading this swagger.yaml
file with swagger-parser. You will notice that there is no model in the POJO representation. Both files must be in the same folder.
This is swagger.yaml
swagger: '2.0'
info:
version: '1.0.0'
title: Swagger Petstore (Simple)
description: A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification
termsOfService: http://helloreverb.com/terms/
contact:
name: Swagger API team
email: foo@example.com
url: http://swagger.io
license:
name: MIT
url: http://opensource.org/licenses/MIT
host: petstore.swagger.io
basePath: /api
schemes:
- http
consumes:
- application/json
produces:
- application/json
paths:
/pets:
get:
description: Returns all pets from the system that the user has access to
operationId: findPets
produces:
- application/json
- application/xml
- text/xml
- text/html
parameters:
- name: tags
in: query
description: tags to filter by
required: false
type: array
items:
type: string
collectionFormat: csv
- name: limit
in: query
description: maximum number of results to return
required: false
type: integer
format: int32
responses:
'200':
description: pet response
schema:
type: array
items:
$ref: 'definitions.yaml#/definitions/pet'
default:
description: unexpected error
schema:
$ref: 'definitions.yaml#/definitions/errorModel'
post:
description: Creates a new pet in the store. Duplicates are allowed
operationId: addPet
produces:
- application/json
parameters:
- name: pet
in: body
description: Pet to add to the store
required: true
schema:
$ref: 'definitions.yaml#/definitions/newPet'
responses:
'200':
description: pet response
schema:
$ref: 'definitions.yaml#/definitions/pet'
default:
description: unexpected error
schema:
$ref: 'definitions.yaml#/definitions/errorModel'
/pets/{id}:
get:
description: Returns a user based on a single ID, if the user does not have access to the pet
operationId: findPetById
produces:
- application/json
- application/xml
- text/xml
- text/html
parameters:
- name: id
in: path
description: ID of pet to fetch
required: true
type: integer
format: int64
responses:
'200':
description: pet response
schema:
$ref: 'definitions.yaml#/definitions/pet'
default:
description: unexpected error
schema:
$ref: 'definitions.yaml#/definitions/errorModel'
delete:
description: deletes a single pet based on the ID supplied
operationId: deletePet
parameters:
- name: id
in: path
description: ID of pet to delete
required: true
type: integer
format: int64
responses:
'204':
description: pet deleted
default:
description: unexpected error
schema:
$ref: 'definitions.yaml#/definitions/errorModel'
This is definitions.yaml
definitions:
pet:
type: object
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
newPet:
type: object
required:
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
errorModel:
type: object
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
How to correct a #REF! error - Microsoft Support
The #REF! error shows when a formula refers to a cell that's not valid. This happens most often when cells that were referenced...
Read more >#REF Excel Errors - How to Find and Fix #REF Errors in Excel
Method #2. Another method is to press Ctrl + F (known as the Excel find function) and then type “#REF!” in the Find...
Read more >How to solve the #REF! error on spreadsheets - Sheetgo Blog
REF ! Learn how to resolve the REF Google spreadsheet error when linking data across sheets, even when out of your office or...
Read more >git pull fails "unable to resolve reference ... - Stack Overflow
Trying to git pull after deleting the first file returned fatal: update_ref failed for ref 'HEAD': cannot lock ref 'HEAD': unable to resolve...
Read more >Loaded external reference (xref) does not display in AutoCAD
The xref file has nothing in model space, or the wrong content is on the Model tab. The drawing elements are on a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@gracekarina Sorry for the delay, things have been crazy a little bit. So here is an update. You solution is good but I made a slight modification. In Windows, I need to put
./
instead of/
. It works with the basic Pet store samples. Final code looks like this:swagger.yaml
definitions.yaml
If I change the
errorModel
to this (pointer to another model), I get an error:Error I receive:
Is this a but or am I doing something wrong again?
Thanks!
@gracekarina Oh nice! I’m pretty busy today but next week I will try it with my real spec to see if this is working.
Thank you very much for looking into this! I’ll keep you posted