wemogy / generator

A yeoman code generator for common wemogy templates

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ship Open API CLI as NPM package with generator

robinmanuelthiel opened this issue · comments

Different locally installed opencli-generator can lead to errors (see https://github.com/wemogy/authorization/issues/534)

Options

  • Ship the CLI as a generator dependnecy (preferred)
  • Check the locally installed CLI version

The OpenAPI Generator is a Java project. openapi-generator-cli will download the appropriate JAR file and invoke the java executable to run the OpenAPI Generator. You must have the java binary executable available on your PATH for this to work. (https://www.npmjs.com/package/@openapitools/openapi-generator-cli)

I don't like that a user can't use this NPM package without having Java installed and added to path.

image

For that reason I would vote for checking the OpenAPI generator version and showing an error, if the installed major version is not the expected one. (If generator expect version 6.X, but you have 7.X installed, you get a proper warning for this)

When we check the version, we can let it up to the user how to install the OpenAPI generator - for example I like the Homebrew way, which is just working.

When we check for the version and the OpenAPI generator is not installed, we ask the user to install it and give the link https://openapi-generator.tech/docs/installation to him.

What do you think?

@robinmanuelthiel added the openapi-generator check:

# Verify that openapi-generator is installed
if ! command -v openapi-generator &> /dev/null
then
echo "openapi-generator could not be found"
exit
fi
# Verify that openapi-generator version is 7.0.X
if [[ $(openapi-generator version) != 7.0.* ]];
then
echo "openapi-generator version 7.0.X is required"
exit
fi

@robinmanuelthiel added the openapi-generator check:

# Verify that openapi-generator is installed
if ! command -v openapi-generator &> /dev/null
then
echo "openapi-generator could not be found"
exit
fi
# Verify that openapi-generator version is 7.0.X
if [[ $(openapi-generator version) != 7.0.* ]];
then
echo "openapi-generator version 7.0.X is required"
exit
fi

As far as I can tell, this script checks the Major AND Minor version whereas you only wanted to pin the Major Version, right?

Was not sure, if a change in minor could also be a breaking change - but if this is not the case we could replace it with sth. like 7.*.* to only check for Major

I don't like that a user can't use this NPM package without having Java installed and added to path.

image

Yes the CLI is Java and the user needs to have Java installed. But why is it a difference from installing it via Homebrew? Does Homebrew install Java automatically, whenever I install the OpenAPI CLI?

If it doesn't, I would say it's same same and I like the Idea that installing our Generator via NPM is all we need to ensure it is running as expected, because it brings the EXACT version of the CLI that we tested

For this reason, that we exactly know the version of the CLI that is used, I would still vote for adding it as a dependency as discussed in this issue from the beginning

I don't know where the requirement comes from...
I would say we have a solution for our other topic now and keep this issue here open for shipping the npm dependency. Because it's better to install everything at once and don't tell the user that a dependency is incorrect or missing.

The requirement is the whole reason we have this issue. I had a different version of the CLI installed than you. This cannot happen anymore, when we ship the CLI with the generator.

I don't know where the requirement comes from... I would say we have a solution for our other topic now and keep this issue here open for shipping the npm dependency. Because it's better to install everything at once and don't tell the user that a dependency is incorrect or missing.

This doens't make sense to me. Telling the user that something is missing is EXACTLY what we do with the script you wrote...

(Just a sum-up for the next person who picks it up)

TLDR: Remove Open API CLI version check from Script and ship it as an NPM dependency and make sure that the version of the Open API CLI gets used that comes from the NPM dependency, even if a different version of the NPM Open API CLI is installed locally.

// If the user has installed the Open API CLI not via NPM (e.g. via Homebrew) we don't care, because only the NPM version has the name openapi-generator-cli the normal version is called openapi-generator only.