In the accounting-service-project we use openapi-generator-cli to generate source code for accessing the finapi. We use the typescript-nestjs-generator which is considered ‘experimental’. We encountered a situation where generating the code for the finapi-access-service produces code that does not compile giving errors (at 80 different spots) in the following form:
The resulting generated code looks like this:
The problem is that queryParameters does not have an append function. This problem only arises when
Therefore the former dev-team changed all occurrences of line 3 to
let queryParameters = new URLSearchParams();
and then committed the generated code.
In order to generate code that compiles, and in order to remove the generated code from git, we can customize the way openapi-generator-cli generates code.
OpenAPI Generator · Generate clients, servers, and documentation from OpenAPI 2.0/3.x documents )
The typescript-nestjs-generator uses moustache-template files. First we need to to extract the template files which are currently used by the typescript-nestjs-generator.
yarn openapi-generator-cli author template -g typescript-nestjs
The files are written to a newly created folder ‘out’ Then we change the file ‘api-service.moustache’:
Then we create a new folder called custom-template and copy the modified .moustache-file to it.
When generating code we need to pass the new template folder:
yarn openapi-generator-cli generate -g typescript-nestjs -o generated_sources/finapi/access-service -i resources/finapi/openapi-access-latest.yaml --additional-properties=supportsES6=true -t ./openapi-customtemplate
Now the generated code compiles again.🕺🏽
There seems to be a discrepancy between the formal description of the finapi-access-api
The API-Documentation for example for deleteAllAccounts states, that the accountIds are passed as csv:
The definition in the yaml-file however does not explicitly state any serialization-parameters.
So the following default values apply:
So instead of single parameter with comma separated values, there should be parameter for each value. If this discrepancy turns out to be a problem (and its not just that the prosaic description is wrong) then a solution could be to add ‘explode=false’ to all properties in the openapi-access-latest.yaml.
Daniel bringt rund 20 Jahre Erfahrung im Bereich IT mit. In den letzten 10 Jahren war er selbst CTO in seinem eigenen CRM-Software Unternehmen. Bei SCALARA hält der studierte Informatiker nun alle Fäden in der Softwareentwicklung zusammen und ist Sparringpartner von unserem CTO Alex. Daniel ist erster Ansprechpartner für das Entwicklerteam ist für den Aufbau der weiteren Teams zuständig und brennt für neue Technologien.