-
Notifications
You must be signed in to change notification settings - Fork 6k
Unable to generate anything with multiple files yaml spec #5753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'd never seen external refs defined outside of a I ran the following against the swagger.yaml:
definitions.yaml:
When I run without the parent
It seems to me like this would be covered by the tests hitting relative-file-references in swagger-parser, although those are json-only and this could be a yaml issue. You may want to track swagger-api/swagger-parser#342, as it looks like it's missing functionality (or perhaps a bug) in the YAML processing. |
I should mention, current master was updated today (9 hours ago, issue reported 7 hours ago) to use swagger-parser 1.0.29. I tested this both with 1.0.28 and 1.0.29 and received the same error when there's no parent |
Could be the case that we need to add a test to the parser for this. It should be handled... |
@jimschubert and @fehguy : I'm pretty sure it should be supported by swagger-codegen because it seems to be supported by the swagger-editor and swagger-ui (and probably by the OpenApi spec itself). I followed this article on how to split a single yaml file into multiple files and as you can see, there is no more "definitions" key once it is split and it make sense. I'm pretty sure more and more people will start to split their files and will follow this blog post and swagger-codegen must be compliant. Is this an easy fix? I don't know anything about the parser unfortunately so I don't think I can contribute myself. |
@JFCote I don't think it's a swagger-codegen issue. The third line from the bottom of my stack trace is in CodegenConfigurator, which calls
The exception that's thrown is in swagger-core, and looks like it has to do with getting the name of a reference. As @fehguy said, it should be covered. I'm heading out on vacation today, but I'll try to look later. |
@fehguy I tracked down the problem. This is an issue with swagger-parser. I'm on vacation for a week, so I was wondering if you could look into a fix? The issue is that the code is getting into
Throws an error. For example, n the sample case of this issue, it's doing It's weird to me that swagger-parser loosely allows external refs to be defined as If I rename I haven't worked in the swagger-parser codebase, so I wouldn't really know where to start with the fix. Intuitively, I'd think the fix would be to just strictly enforce the prefix. However, I'm not too familiar with the spec on external refs and it looks like the test files aren't prefixed with |
Hi Jim, I added the "definitions:" in the parent hierarchy as mentioned above. In the UI I was able to display my api, but when I ran the code generator in java, everything ran and the response models were not created. They were referenced in the other models but not created. They would have this name: SnapAdYamldefinitionssnapAd. Is this related? Does the code-gen not support multiple files? Greg |
@2ricecrackerfolder the external yaml generated for me in the local filesystem with the examples above. I didn't test it with hosted specs and external definitions Is that how you're generating? |
@jimschubert Thanks for your quick reply! I also modified my configuration to what they have above. The yaml did generate with no errors but was missing the response model files when i dug through the generated src. |
I have a large api with a lot of definitions. I am splitting the files, and it seems like the response models would not generate. |
@2ricecrackerfolder my assumption would be that you may have a validation error somewhere. You can check with the online validator by appending your url: For example, here's a swagger definition with a validation error: https://online.swagger.io/validator/debug?url=https://quay.io/api/v1/discovery I don't think the above definition would have a problem when generating client code, but if you have lots of errors it's more likely. |
@jimschubert looks like a bug in swagger-core is triggering this. Bummer, we just did a release today! But please see here: |
Updating to swagger-parser 1.0.30-SNAPSHOT to see if this fixes the issue |
@fehguy : Let me know when it's in the master, I will do some testing. |
You should be able to update this: https://github.com/swagger-api/swagger-codegen/blob/master/pom.xml#L890 to |
@fehguy : I have tested it with the example I give above and the generation was successful! So I'm pretty sure we have a good fix with the new swagger-parser version. Please update this bug when you will update the parser in the master! Thanks! |
OK Great! I'll do the release today. We have to do the whole gamut including swagger-core too... |
@JFCote @jimschubert @fehguy I sugget to build file using command line toolkit that link multiple yaml files with $include tag . Look this https://github.com/javanile/yamlinc add in build task on gulp or grunt |
@francescobianco It's already fixed |
Hi @JFCote , Which version of swagger-codegen is this fixed in ? I am still getting the same error for swagger-codegen-maven-plugin 2.2.2 version |
Hi @rajkash please use https://github.com/javanile/yamlinc to build your multiple Yaml files documentation
|
Description
I'm trying to generate the JavaPlayFramework with a very simple multiple files yaml spec but it doesn't work. I also tried with other server and I receive the same error. I was advised to try to validate the spec using the brand new "validate" function but I still receive the same error.
What is strange is that I am able to look at this spec using swagger-editor in local. There is not error at all. Just put both file in the swagger-editor folder and see for yourself.
There are 2 files (find the content of them below):
Here is the error I get every time
Swagger-codegen version
Latest master
Swagger declaration file content or url
swagger.yaml
definitions.yaml
Command line used for generation
java -jar swagger-codegen.jar generate -i swagger-editor/swagger.yaml -l java-play-framework -o generatedServer -DhideGenerationTimestamp=true
Steps to reproduce
Just run the command line above
The text was updated successfully, but these errors were encountered: