-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
[BUG] Error processing OpenAPI json file for python client #11763
Comments
Your spec is missing a response schema definition in your endpoints:
Please include the schema definition under |
@spacether Thank you for clarifying that. I have some better thoughts in a comment I will add below; please ignore this for now. I think there is still an argument to be made that
...could be improved as an error message. Something seems to be going wrong in exception handling, because the lines generating the exception should be printing the exception: Lines 1157 to 1165 in edfb3e1
But in the above printout, the string on the I'm not sure why the output from the local generator is different; I suppose it's just more up-to-date?
I'm not enough of a Java programmer to fully understand the lines that check the tags, but if there are mandatory tags, wouldn't it make sense to raise an exception for empty values in that code block, instead of waiting till we loop over the tags and try to unpack values from a missing tag? Lines 1079 to 1104 in edfb3e1
I wish I could help more with a solution, but the flow of control here is hard for me to understand, so I don't see where that exception was originally raised, and searching for "Cannot read field" in this repo on GitHub gives me nothing. |
It occurs to me now that I have been thinking about this all wrong: the problem here was that the OpenAPI spec that I was working from was ill-formed, and the openapi-generator isn't telling me. But this means that my process for generating the API is defective (in this case because I assumed I had been given a well-formed spec): instead it needs a step that checks to make sure that the specification is well-formed, and not feed to the openapi-generator unless the checker terminates successfully. It would be great if the generator would do this for us, so users don't have to compose tools themselves, but I should be able to also set up a pipeline for myself, if I can find a good way to run the validator and get good error messages. Given that framework, we can probably close this issue. |
TL;DRIt appears that the online OpenAPI validators accept response specifications without a DetailsWhen I fix that API spec, and validate it using the online swagger editor and the online swagger validator I still get errors from the openapi-generator:
Testing with
Looking at the spec, it appears that the validators accept response specifications without a Media type objects in the textual specification doesn't annotate |
Sorry to keep on at this, but I have added schemas to all responses, and validated the openapi spec using the online editor. The resulting file successfully generates a python client API using
In case it's helpful, here are some relevant bits of the verbose output. First the schema that the error message says is untranslatable:
then the referenced named schema:
I see these warnings, but they do not appear to be relevant:
Perhaps this is related to the API in lines 608-623, which defines two alternative body formats, |
I am working on allowing the python-experimental generator to ingest responses where schema is unset in: |
Thanks, @spacether A quick couple of notes:
|
Aha! For my sub-issue 2 above, the magical answer is to prepend
to the invocation of
Then it runs to completion successfully. |
You can ignore the warning message. The multiple content types are stored and used with python-experimental. There are two problems currently.
The PR that I am working on will fix both of those issues and this use case for python-experimental. You can see generation of your spec working in the commits iny PR. |
Great, thanks. I have worked around that for now by adding schemas everywhere. I was having the error reported above when using |
This now works on master branch in python-experimental |
@spacether I'm facing the same issue. Is there a quick way to test your fix with openapi-generator-cli? Alternatively, since I'm just looking for a functional handlebars based generator, is there any other I could use? |
You need to pull down the latest master and build it using the instructions in the Readme to use it. Python-experimental is the only handlebars generator as far as I know. Also what's your reason for using handlebars? I am curious about your use case. |
Thanks. About my use case, I'm generating some react components for a backoffice. It's a "bring your own API" backoffice (react-admin). So per each model of the API I'd need some CRUD components for the backoffice, which I'd rather generate as much as possible. Most of the times I needed to generate something from an API spec, the available templates have sufficed. Now I want something a bit further from a simple customization and honestly I'd rather work it out on the template side, rather than going the more involved way of making a custom generator. Unfortunately mustache logicless templating won't let me even customize a model name. I feel handlebars could unlock a lot of possibilities in this project when it gets more support / generators. I've seen some comments aligned with that idea (like this one), but the reality is that generators aint't adopting handlebars (at least yet). Can't really understand why. Yours is the only one. Maybe I'm overlooking it but it almost feels to me that with handlebars and a single good generator, the Java part of the current generators could be ditched in favor of purely template-based ones. Thanks for your work on this! |
If you wanted you could convert another generator to use handlebars. I made a tool to convert from mustache to handlebar templates. Sadly our schema interfaces in the Java layer are not as simple and self similar as your comment implies. Through great effort I have made them close enough and added missing schema info. If you look at the python-experimental model templates you will see that they recursively call each other to render any schema and create model classes at any depth of schema inlinining. Using handlebars definitely allows one to use fancier if else not and or conditionals which I made use of. |
Just leaving this here, mainly in case it helps someone or might provide a clue. So, I was using Java 17 with the python generator with the petstore.json and got the I was able to run other generators, confirmed this by testing with the Then I swapped to Java 11 and was able to generate a python SDK when using Java 11, haven't tried other versions of Java, but perhaps someone might be able to comment on the Java version compatibility.. |
Bug Report Checklist
Description
Trying to process the OpenAPI spec from the Owlery system, https://github.com/phenoscape/owlery (spec posted below) with the python and python-experimental systems, I get errors processing the files.
Using the command-line locally I get:
Using the docker image I get:
openapi-generator version
5.4.0
OpenAPI declaration file content or url
YAML is available here: https://gist.github.com/rpgoldman/a65d85f15a9f8b08298cb19446c1b7f0
Generation Details
I believe "steps to reproduce," below, has all the required information, but happy to collect more if needed.
Steps to reproduce
CLI:
Docker:
Related issues/PRs
Suggest a fix
The text was updated successfully, but these errors were encountered: