OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.82k stars 6.58k forks source link

[BUG] Dockerfile for Bash language not populated correctly #10589

Open jeeftor opened 3 years ago

jeeftor commented 3 years ago

Bug Report Checklist

Description

When using what I think is valid commands with the bash generator I'm getting an invalid Dockerfile

openapi-generator version

5.2.1

OpenAPI declaration file content or url

I'm using the sample pet store api: https://petstore.swagger.io/v2/swagger.json

Generation Details

I run the following:

#!/bin/bash
LANG=bash
mkdir -p out/$LANG

curl https://petstore.swagger.io/v2/swagger.json >pet.json

openapi-generator generate \
    -i pet.json \
    -o out/$LANG \
    -g $LANG

Resultant Dockerfile looks like this:

image

this implies to me the template https://github.com/OpenAPITools/openapi-generator/blob/0204bf4ae284d936e4f7cb1ffad314c04d5df9db/modules/openapi-generator/src/main/resources/bash/Dockerfile.mustache is not filling out the variable {{scriptName}} correctly

image
Related issues/PRs

Active PR to fix this issue https://github.com/OpenAPITools/openapi-generator/pull/10594

Suggest a fix

I'll try to track down the code somehow - but obviously the SCRIPT_NAME variable isn't being populated correctly for some reason

jeeftor commented 3 years ago
image

I've downloaded the code and started digging around ... it does look like the template is asking for scriptName which doesn't appear to be a valid value in the templateData fed into the Dockerfile template....

image
jeeftor commented 3 years ago

So x-codegen-script-name is getting set...

image

And here is a potential (maybe) fix:

In BashClientCodegen.java if we add scriptName as something set it DOES show up successfully in the Dockerfile

image

Additionally - we then get this working code block in docker:

image

I'm not sure what the correct fix is - however - whether the DockerTemplate should be updated or this is a specific Bash issue and the scriptName variable isn't being set...

I may put together a PullRequest anyways and we'll see what happens