openapi-generator-cli icon indicating copy to clipboard operation
openapi-generator-cli copied to clipboard

[Feature Request] Add authentication options for the repository configuration of the openapitools.json

Open FieteO opened this issue 3 years ago • 4 comments

Currently it is possible to specify downloadUrl and queryUrl in the repository configuration block if a private repository should be used:

{
    "$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
    "spaces": 2,
    "generator-cli": {
        "version": "5.1.1",
        "storageDir": "./openapitools-download",
        "repository": {
            "queryUrl": "https://artifactory.mycorp.com/maven-central/select?q=g:${group.id}+AND+a:${artifact.id}&core=gav&start=0&rows=200",
            "downloadUrl": "https://artifactory.mycorp.com/maven-central/${groupId}/${artifactId}/${versionName}/${artifactId}-${versionName}.jar"
        }
    }
}

Unfortunately the artifact-storage of my organization requires login credentials and I can thus not use this option. It would be great if something like this could be added:

{
    "generator-cli": {
        "repository": {
            "queryUrl": "https://artifactory.mycorp.com/maven-central/select?q=g:${group.id}+AND+a:${artifact.id}&core=gav&start=0&rows=200",
            "downloadUrl": "https://artifactory.mycorp.com/maven-central/${groupId}/${artifactId}/${versionName}/${artifactId}-${versionName}.jar",
            "username":"",
            "password":"",
        }
    }
}

On a general note:
I think the documentation of these configuration options could be more extensive. I learned about the repository block via a comment on an issue as it is not in the README...

FieteO avatar Nov 19 '21 14:11 FieteO

What about?:

{
    "generator-cli": {
        "repository": {
            "queryUrl": "https://username:[email protected]/maven-central/select?q=g:${group.id}+AND+a:${artifact.id}&core=gav&start=0&rows=200",
            "downloadUrl": "https://username:[email protected]/maven-central/${groupId}/${artifactId}/${versionName}/${artifactId}-${versionName}.jar"
        }
    }
}

kay-schecker avatar Mar 17 '22 11:03 kay-schecker

Thanks, I will try this out next week.

FieteO avatar Mar 18 '22 16:03 FieteO

Okay, I think I have a more general issue here. To test if it is working, I have provided an override 127.0.0.1 repo1.maven.org in /etc/hosts.

I have then defined the following openapitools.json config:

{
    "$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json",
    "spaces": 2,
    "generator-cli": {
      "version": "5.3.0",
      "queryUrl": "https://${ART_USERNAME}:${ART_PASSWORD}@artifactory.mycorp.com/artifactory/maven-central/select?q=g:org.openapitools+AND+a:openapi-generator&core=gav&start=0&rows=200",
      "downloadUrl": "https://${ART_USERNAME}:${ART_PASSWORD}@artifactory.mycorp.com/artifactory/maven-central/org.openapitools/openapi-generator/5.3.0/openapi-generator-5.3.0.jar"
    }
}

and use that with the following scripts block in the package.json:

"scripts": {
    "openapi": "rm -rf ./openapi/output && npx openapi-generator-cli generate -i ./openapi/input/api.yaml -g typescript-angular -o ./openapi/output -c ./openapi/config.json",
    "start": "ng serve -- --proxy-config staging.proxy.config.json --host 0.0.0.0 --port 80 --disable-host-check",

The custom urls seem to be ignored:

ubuntu@dev ~/Documents/development/frontend (dev)$ npm start

> [email protected] prestart
> npm run openapi


> [email protected] openapi
> rm -rf ./openapi/output && npx openapi-generator-cli generate -i ./openapi/input/api.yaml -g typescript-angular -o ./openapi/output -c ./openapi/config.json

Download 5.3.0 ...
Download failed, because of: "connect ECONNREFUSED 127.0.0.1:443"

Response:
/home/ubuntu/Documents/development/frontend/node_modules/@openapitools/openapi-generator-cli/main.js:956
            Object.entries(error.response.headers).forEach(a => this.logger.log(...a));
                                          ^

TypeError: Cannot read properties of undefined (reading 'headers')
    at VersionManagerService.printResponseError (/home/ubuntu/Documents/development/frontend/node_modules/@openapitools/openapi-generator-cli/main.js:956:43)
    at VersionManagerService.<anonymous> (/home/ubuntu/Documents/development/frontend/node_modules/@openapitools/openapi-generator-cli/main.js:921:22)
    at Generator.throw (<anonymous>)
    at rejected (/home/ubuntu/Documents/development/frontend/node_modules/@openapitools/openapi-generator-cli/node_modules/tslib/tslib.js:112:69)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Any idea why the settings are ignored?

FieteO avatar Mar 25 '22 08:03 FieteO

What about?:

{
    "generator-cli": {
        "repository": {
            "queryUrl": "https://username:[email protected]/maven-central/select?q=g:${group.id}+AND+a:${artifact.id}&core=gav&start=0&rows=200",
            "downloadUrl": "https://username:[email protected]/maven-central/${groupId}/${artifactId}/${versionName}/${artifactId}-${versionName}.jar"
        }
    }
}

Also this has the general issue of hardcoding secrets. There needs to be a way to pass the credentials in either via cli params on invoking the openapi-generator-cli command or via environment variables

FieteO avatar Sep 26 '23 12:09 FieteO