swagger-api / swagger-api/swagger-parser
swagger-parser not resolving file references
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 867
- Forks
- 560
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 7
Description
Dependencies:
161 <dependency>
162 <groupId>io.swagger</groupId>
163 <artifactId>swagger-compat-spec-parser</artifactId>
164 <version>1.0.40</version>
165 </dependency>
166 <dependency>
167 <groupId>io.swagger</groupId>
168 <artifactId>swagger-models</artifactId>
169 <version>1.5.21</version>
170 </dependency>
171 <dependency>
172 <groupId>io.swagger</groupId>
173 <artifactId>swagger-parser</artifactId>
174 <version>1.0.40</version>
175 </dependency>
Excerpt from main.yaml yaml spec:
definitions:
$ref: './definitions.yaml'
definitions.yaml is in the same directory as main.yaml and looks like:
ErrorResponse:
type: object
required:
- code
- message
properties:
code:
description: The HTTP error status code
type: integer
format: int32
message:
description: The reason for the error
type: string
fields:
description: An array of strings for specific reasons for the error
type: array
items:
type: string
I have some simple code that parses the spec and the messages indicates my definitions ref is not good and the swagger object has no definitions:
319 SwaggerDeserializationResult dsr = new SwaggerParser().readWithInfo(path, null, true);
320
321 dsr.getMessages().forEach(e -> LOG.info("Message: " + e));
322 spec = dsr.getSwagger();
323 spec.getPaths().forEach((k,v) -> LOG.info("Key: " + k + " and Value: " + v));
324 spec.getDefinitions().forEach((k,v) -> LOG.info("Key: " + k + " and Value: " + v));
Messages:
[INFO] Message: attribute definitions.$ref is not of type `object`
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the main.yaml and definitions.yaml examples, then inspect the readWithInfo(path, null, true) call and its reported message. Trace how the parser handles the definitions.$ref entry and compare the resulting Swagger definitions with the referenced file. Done means the local file reference resolves without the type message and the definitions are available on the parsed Swagger object.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100