swagger-api / swagger-api/swagger-codegen
$ref for local path not working
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
I have a swagger.yaml file that is getting huge, 10K+ lines, so it makes sense to break this into logical pieces. Documentation suggests I use '$ref' for this purpose.
I tried this:
swagger: '2.0'
info:
$ref: './swagger/info.yaml'
Followed by:
java -jar swagger-codegen-cli.jar \
generate \
--input-spec doc/swagger.yaml \
--lang html \
--output ./webroot/swagger/
Rather than including the contents of the ./swagger/info.yaml file, we get this:
[main] INFO io.swagger.parser.Swagger20Parser - reading from doc/swagger.yaml
[main] WARN io.swagger.codegen.ignore.CodegenIgnoreProcessor - Output directory does not exist, or is inaccessible. No file (.swager-codegen-ignore) will be evaluated.
[main] ERROR io.swagger.codegen.DefaultGenerator - Missing required field info version. Default appVersion set to 1.0.0
[main] ERROR io.swagger.codegen.DefaultGenerator - Missing required field info version. Default version set to 1.0.0
Exception in thread "main" java.lang.NullPointerException
at io.swagger.codegen.DefaultGenerator.processPaths(DefaultGenerator.java:759)
at io.swagger.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:388)
at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:700)
at io.swagger.codegen.cmd.Generate.run(Generate.java:285)
at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)
It's similar to this issue maybe? https://github.com/swagger-api/swagger-editor/issues/233
Since I have to represent almost 100 paths, I was hoping to have a paths section that looks like:
paths:
/magic-one:
$ref: './swagger/magic-one.yaml'
./magic-two:
$ref: './swagger/magic-two.yaml'
As it stands now, even when $ref resolves information in the same file (like Models) my paths section is too dang tall; the file is getting hard to manage.
Coming from asciidoc background I miss the include::path/file.ad[] option.
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
Reproduce the command using doc/swagger.yaml and ./swagger/info.yaml, then start with Swagger20Parser and the DefaultGenerator.processPaths stack-trace location. Check how local $ref values are resolved for info and paths, including the reported NullPointerException. Done means supported local references load the split files and generation completes without the missing-field errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100