Skip to content
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

Cannot read property 'imports' of undefined #13

Closed
lamuertepeluda opened this issue Feb 27, 2019 · 13 comments
Closed

Cannot read property 'imports' of undefined #13

lamuertepeluda opened this issue Feb 27, 2019 · 13 comments

Comments

@lamuertepeluda
Copy link
Contributor

Hi,

I think you should add a check at this line of code https://github.com/Manweill/swagger-axios-codegen/blob/master/src/requestCodegen/index.ts#L54 and line above, like

if(refResponseType && parsedParameters && Array.isArray(parsedParameters.imports)){
  parsedParameters.imports.push(responseType)
}

I get this error

error TypeError: Cannot read property 'imports' of undefined
    at Object.requestCodegen (/Users/vito/Development/JavaScript/VISCA/swagger-codegen/node_modules/swagger-axios-codegen/dist/requestCodegen/index.js:40:34)
    at codegen (/Users/vito/Development/JavaScript/VISCA/swagger-codegen/node_modules/swagger-axios-codegen/dist/index.js:140:45)
    at generateApi (/Users/vito/Development/JavaScript/VISCA/swagger-codegen/apigen.js:24:11)
    at process._tickCallback (internal/process/next_tick.js:68:7)

which is also swallowed, i.e. codegen() does not throw, but also does not generate the api.

@Manweill
Copy link
Owner

@lamuertepeluda
Hi, can you send your swagger.json to me

@lamuertepeluda
Copy link
Contributor Author

hi @Manweill , it's at this URL. I tried with both remoteURL and file options, same result.

@Manweill
Copy link
Owner

Manweill commented Mar 1, 2019

@lamuertepeluda
Hei, you can try swagger-axios-codegen@v0.5.1 again.

@Manweill
Copy link
Owner

Manweill commented Mar 1, 2019

@lamuertepeluda
Hi, I fix imports bug in v0.5.1.
BTW, when I try with your swagger-spec.json file, I find another problem.
One tag like Irrigation Block , it has whitespace.
One type like this :

"geometry": {
          "type": "geoJSON geometry"
},

@lamuertepeluda
Copy link
Contributor Author

Hi @Manweill,

thanks for investigating.
I downloaded the latest version an it still occurs that it's swallowing exception, making it harder to debug, i.e. this line should definitely throw the error, in a way that a user program can detect its failure state.

Maybe even better storing in a local variable and throwing it after unlinking files and the console.timeEnd() of line 177, like

let err = null
/*... do things */
catch(error){
   err = error
}
/*... do other things */
if(err){
   throw err;
}

Regarding the type name, they are autogenerated using nest-swagger using TS definitions and reflect-metadata (our server is written entirely in TypeScript with nestjs).

Although we know that this nest-swagger module has for sure its good share of issues, we currently auto-generate client-side api module with this other generator named swagger-es6, and it's not having troubles with entity names.

I liked more your approach since your library is entirely in TS, and it also easily allows for using a separate axios instance, so I'm trying it. But I got stuck 😅

Debugging with VSCode I found 2 different errors when running the codegen script, depending on methodNameMode

operationId leads to an error on this line

path leads to an error here, that is the formatter fails because the class name is "Irrigation Block" instead of "IrrigationBlock"

Could calling camelcase at this line help dealing with spaces tags and therefore in generated class names?

@Manweill
Copy link
Owner

Manweill commented Mar 1, 2019

Thanks for suggestion.
Let's look at each problem.
First, we can also replace spaces when the classname had whitespace.
Then, I search geoJSON geometry type. It dose not a base type in JS/TS. It need a method to tell the codegen, how it transform this type.
If these two problems are solved, continue to.

@lamuertepeluda
Copy link
Contributor Author

While the spaces problems looks simpler to be solved, how about setting a default type for all non-base JS/TS types?
I know it is less accurate, but Object or any should work.
Sadly I don't think it's feasible to include type definitions through swagger.

Another solution may be using some generic, like GeneratedClass<T>, but it is not really easy to think about it in a way that actually works...

@Manweill
Copy link
Owner

Manweill commented Mar 1, 2019

emm...
In Utils.toBaseType, return default type any .
You can do this for the time being.

BTW, what do you think I have to provide a conversion entrance?

@lamuertepeluda
Copy link
Contributor Author

this could definitely work, if you know the generated types in advance. But I would fallback with Object or any when not transformer is provided.

@Manweill
Copy link
Owner

Manweill commented Mar 2, 2019

Test in your project and commit PRs

@Manweill
Copy link
Owner

Manweill commented Mar 3, 2019

Hi @lamuertepeluda

I double check your swagger.json. Your api was RESTful api. But it doesn't had operationId in the swagger.json

@lamuertepeluda
Copy link
Contributor Author

lamuertepeluda commented Mar 4, 2019

Hi @Manweill you are indeed right, we are not (yet) using operationId in that API.
I must definitely rely on the path parameter

@Manweill
Copy link
Owner

Manweill commented May 9, 2019

The issue was too long

@Manweill Manweill closed this as completed May 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants