Closed devpie closed 4 years ago
Hi!
There was a recent PR that improved the way additionalProperties work, see #86. Are you using a custom mustache template, or the default ones?
@Kosta-Github - Were you able to compile a migration guide for this?
Hi @mtennoe,
yes i saw this PR. No we don't use custom mustache templates. We use the default ones. As mentioned i created a test project for testing this issue in order to eliminate any side effects. Here are my package.json and my generate.js which used the swagger.json above and produced the output.ts above.
generate.js:
const fs = require('fs');
const path = require('path');
const CodeGen = require('swagger-typescript-codegen').CodeGen;
function generateSwaggerClient(swaggerFile, outputFile, moduleName) {
const swaggerJson = JSON.parse(fs.readFileSync(swaggerFile, 'UTF-8'));
const tsSourceCode = CodeGen.getTypescriptCode({
moduleName: moduleName,
className: moduleName + 'Api',
swagger: swaggerJson,
beautify: true,
});
const outputDir = path.dirname(outputFile);
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, {recursive: true});
}
fs.writeFileSync(outputFile, tsSourceCode, 'UTF-8');
}
generateSwaggerClient('./api/test.json', './src-gen/rest-client/test.ts', 'Test');
package.json
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"generate": "node generate.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"swagger-typescript-codegen": "^2.0.0"
}
}
Hm, interesting. When it's failing for you, are you using the same swagger.json as in the PR, i.e. this guy?
Yes, exactly :)
@devpie it looks like this works if you use 1.11.0. @mtennoe did anything else change between 1.11.0 and 2.0.0?
2.0.0 was just a republish of 1.11.0, so it shouldnt have, but something might have gone wrong in the process. I will take a look at that on monday
Seems like the issue was introduced in #89. To get back to a good state quickly I reverted that change and published it as 2.0.1, which seems to work in my own test environment. Does this solve it for you as well?
@bweggersen - Can you take a look to see what in the change caused the issue, and try to reintroduce it?
Yes it works again. You are the best. Thank you very much. :smile:
Great to hear! Closing the issue :)
Hi, i just updated to version 2.0.0 and now my types with additionalProperties do not get generated correctly. Here is an example based on your tests for additionalProperties. Within the tests of swagger-typescript-codegen it seems to work, but in my project and my test project it doesn't. What am i doing wrong?
swagger.json:
output.ts: