-
-
Notifications
You must be signed in to change notification settings - Fork 346
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
TypeError: Cannot read properties of undefined (reading 'slice') #513
Comments
Hello @kubakl do you have an example for me? |
@anymaniax What type of example you want me to give you? The OpenAPI spec? |
If you can yes |
Sorry for not answering, I assume it's a config issue, I copied it from the documentation but still it may be wrong: module.exports = {
petstore: {
output: {
mode: 'tags-split',
target: 'src/petstore.ts',
schemas: 'src/model',
client: 'react-query',
mock: true,
},
input: {
target: '../schema/api-v1.yaml',
},
},
}; The schema doesn't have any issues because I also generate golang code using openapi-generator and it works just fine. |
Hi @kubakl, I would need the yaml or an example that reproduce the error with the yaml |
@anymaniax I'm reviving this thread as I am running into the same issue with orval printing out
I have created a repo with a simple example that can be used to reproduce this error: https://github.com/lmossman/orval-example To reproduce the error, you can follow these steps:
I believe this error happens when trying to reference an external json/yaml file in the OpenAPI spec, like I do on this line that I added to your I have confirmed that the Let me know if there is any other info that I can provide here! I'd love to get this fixed as we need to be able to reference external files in our production application that is using orval. Thanks! |
As @lmossman says, I also have the same structure in my OpenAPI definition, I split it across different files, paths, schemas, responses etc. This actually could be the problem. |
As temporary solution you could generate your schema with openapi-cli and then use orval with the output.
On your orval you should add the generated file.
|
@hbarrientosg nice suggestion, I will try that! Thanks Of course it would be preferred if this was fixed natively in orval, though |
Hello @lmossman, @hbarrientosg, @kubakl, I improved the parsing and everything should work as expected in the next release |
@anymaniax I have upgraded to version For components that are pointing to external JSON schema files, the typescript file that orval generates still doesn't contain classes for the referenced JSON. It just adds a type onto the field which is the capitalized version of the field name, but doesn't actually define what that type is. For example, in my orval-example repo that I created to demonstrate this behavior, I point to a breed.json JSON schema file here with a $ref: https://github.com/lmossman/orval-example/blob/ae07d4565f2851a86b211240e92259a5bfa1994d/src/petstore.yaml#L116-L117 But when I run So pointing to an external file results in broken typescript code generated from orval. |
@lmossman can you try |
@anymaniax it is a bit closer now, but I still have a couple of issues:
If orval can correctly produce an output file for that petstore_nested_json.yaml spec which contains properly-named types for |
@lmossman I fixed the two issues but still have a little problem with the relative path. Will try to fix it asap to be able to release a new alpha with it |
In the end, I found a solution quicker than I thought so you can test with |
@anymaniax I tried this out and it seems to have fixed most of the issues I was seeing. However, when I tried this out in the actual project I am using orval for, I still ran into a case where a typescript type did not properly get generated for a definition in the JSON file. I have updated my example here to demonstrate this issue. Notice that if you run I think this may be an issue with |
@lmossman can you try with |
@anymaniax thanks for the quick response! This is looking really close, but I found one more issue: it seems that two duplicate typescript types with the same name are being generated in the case that there are two fields with almost the same name (only a I've updated my repo here with an example of this: the DeclarativeStream definition in my JSON schema has a schema_loader and a _schema_loader field each with the same |
Now it works for me with no problems, thx very much! |
@anymaniax is it looking like the issue I described above is a straightforward fix? I think this is the last issue that is blocking me from using orval in our production app so I'm really looking forward it being resolved! |
@lmossman you can try with |
@anymaniax that seems to have fixed it! Thank you for the quick response. I believe all of the issues called out in this thread have been resolved in the latest version, so this issue can be closed out |
@lmossman cool don’t hesitate if you have other issues |
FYI @anymaniax I discovered another problem, so I opened an issue here: #726 |
What are the steps to reproduce this issue?
What happens?
A weird error appears, don't even know what's the issue
…
What were you expecting to happen?
Generate the models and API operations for all the enpoints
…
Any logs, error output, etc?
petstore - TypeError: Cannot read properties of undefined (reading 'slice')
…
Any other comments?
I saw there's already an issue which is really similar #494
…
What versions are you using?
Operating System: MacOS X (M1)
Package Version: v6.9.2
Browser Version: …
The text was updated successfully, but these errors were encountered: