openapi-generator: command not found for bash script

Viewed 5730

I have a generate.sh file with below lines of code,

#!/bin/bash

openapi-generator generate -g aspnetcore \
--template-dir ${PWD}/openapi-generator-aspnetcore3-templates/ \
--additional-properties aspnetCoreVersion=3.1 \
--additional-properties classModifier=abstract \
--additional-properties operationModifier=abstract \
--additional-properties packageName=RedHat.TodoList \
--additional-properties packageTitle=TodoList \
-i todo_openapi.yaml \
-o ${PWD}

When I am trying to run it Git Bash tool it's throwing error ./generate.sh: line 3: openapi-generator: command not found, I can see openapi-generator-cli commands working fine.

enter image description here

2 Answers

In generate.sh, replace openapi-generator with openapi-generator-cli instead.

(openapi-generator is usually installed via brew on Mac)

Looks like PATH problem.

Use which openapi-generator in terminal or Git Bash, whichever works for you, to find openapi-generator path first.

$ which openapi-generator
/usr/local/bin/openapi-generator

Then add the path to PATH variable in your generate.sh, e.g. put the following line before you call openapi-generator.

PATH+=:/usr/local/bin
Related