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.81k stars 6.58k forks source link

[BUG] --ignore-file-override option is ignored #5723

Open OnkelTem opened 4 years ago

OnkelTem commented 4 years ago

I run generation using openapitools/openapi-generator-cli.

const DOCKER_IMG = 'openapitools/openapi-generator-cli';
const API_PATH = 'api/api.yaml';
const TEMPLATES_PATH = 'templates';
const IGNORE_FILE = '.openapi-generator-ignore';

const child = spawn('docker', [
  'run',
  '--rm',
  '--net=host',
  `--user=${uid}:${uid}`,
  '--mount',
  `type=bind,source=${path.join(__dirname)},target=/local`,
  DOCKER_IMG,
  'generate',
  '-i',
  path.join('/local', API_PATH),
  '-t',
  path.join('/local', TEMPLATES_PATH),
  '-c',
  path.join('/local', CONFIG),
  '--ignore-file-override=' + path.join('/local', IGNORE_FILE),
  '-g',
  'typescript-fetch',
  '-o',
  path.join('/local', 'output'),
]);

And whevern I write inside .openapi-generator-ignore gets absolutely ignored.

msumit commented 3 years ago

I am too facing the same issue with openapi-generator-cli v5.0.1. It just ignores the .openapi-generator-ignore file and overwrites it as well every time.

wing328 commented 3 years ago

we just released v5.1.0 (https://twitter.com/oas_generator/status/1373636654024380423). can you give it a try to see if you're still facing the same issue?

rcky commented 3 years ago

@wing328 Imho it still does not work.

Please have a look at this repos https://github.com/rcky/openapi-generator-all-of using generate -i /local/openapi/openapi.yml -g php -o /local --ignore-file-override=/local/openapi/.openapi-generator-ignore.dist to generate the sources. As you can see in the repos, the test/ folder is still generated.

msumit commented 3 years ago

It worked for me with v5.1.0

jparise commented 3 years ago

The ignore file format doesn't appear to handle directories relative to the current working directory.

For example, you can't successfully ignore a path like ../../.dockerignore, which is useful when passing a relative parent directory to --output (like --output ../..).

mizolight commented 3 years ago

Is there a resolution for this issue please? I am facing the same thing with SpringJava generator. Whatever I put on the ignore file path is ignored and it always fall back to the original ignore file.

pawar-ram commented 3 years ago

I am also facing similar issue. I am using CLI v5.1.0 to generate aspnetcore server and created ignore file with file name entry to ignore but CLI ignoring the ignore file name and overwriting my existing file. I have ignore file in my root folder as per document.

gpeers commented 2 years ago

@pawar-ram did you ever get the aspnetcore generator to respect your ignore file? thanks...

RomanSoloweow commented 2 years ago

@pawar-ram did you ever get the aspnetcore generator to respect your ignore file? thanks...

I faced the same problem

wing328 commented 2 years ago

Here is an example no how to use .openapi-generator-ignore: https://github.com/OpenAPITools/openapi-generator/blob/master/samples/client/petstore/csharp-netcore/OpenAPIClientCore/.openapi-generator-ignore#L3

dmitryerikin commented 2 years ago

Hello! It's not about CLI tool but may be helpful. I'm using the gradle plugin org.openapi.generator version 5.0.0 My .openapi-generator-ignore is in the root of the project . In the openApiGenerate configuration I defined ignoreFileOverride.set("$rootDir/.openapi-generator-ignore") and the ignoring works if I put paths from the project root. For example. My output directory is $rootDir/backend/build/generated, so README.md generates in $rootDir/backend/build/generated/openapi/README.md. And the ignoring works if I put backend/build/generated/openapi/README.md in .openapi-generator-ignore.

isnikulin commented 2 years ago

I'm using the gradle plugin org.openapi.generator version 5.0.0 My .openapi-generator-ignore is in the root of the project . In the openApiGenerate configuration I defined ignoreFileOverride.set("$rootDir/.openapi-generator-ignore") and the ignoring works if I put paths from the project root. For example. My output directory is $rootDir/backend/build/generated, so README.md generates in $rootDir/backend/build/generated/openapi/README.md. And the ignoring works if I put backend/build/generated/openapi/README.md in .openapi-generator-ignore.

I'm using gradle plugin version '6.0.1' and your solution didn't work:

I output my files here: $buildDir/generated. Path from content root to generated README.md is build/generated/README.md. Despite specifying that in ignore file, it still appears on generation.

I also tried generated/README.md and just README.md. What did finally work was: **/README.md Here's the final example file for generating code for spring with Delegator pattern:

**/README.md
**/pom.xml
**/src/test/
**/src/main/java/**/configuration/
**/OpenApiGeneratorApplication.java
**/RFC3339DateFormat.java
**/src/main/resources/
mariocozta commented 2 years ago

I'm using the gradle plugin org.openapi.generator version 5.0.0 My .openapi-generator-ignore is in the root of the project . In the openApiGenerate configuration I defined ignoreFileOverride.set("$rootDir/.openapi-generator-ignore") and the ignoring works if I put paths from the project root. For example. My output directory is $rootDir/backend/build/generated, so README.md generates in $rootDir/backend/build/generated/openapi/README.md. And the ignoring works if I put backend/build/generated/openapi/README.md in .openapi-generator-ignore.

I'm using gradle plugin version '6.0.1' and your solution didn't work:

I output my files here: $buildDir/generated. Path from content root to generated README.md is build/generated/README.md. Despite specifying that in ignore file, it still appears on generation.

I also tried generated/README.md and just README.md. What did finally work was: **/README.md Here's the final example file for generating code for spring with Delegator pattern:

**/README.md
**/pom.xml
**/src/test/
**/src/main/java/**/configuration/
**/OpenApiGeneratorApplication.java
**/RFC3339DateFormat.java
**/src/main/resources/

I am using version 6.2.1 and generating a Java client and running it with gradle plugin. I can confirm that the solution is to use **

My .openapi-generator-ignore is just this: **build.gradle

I believe the docs should be updated?

sebinefrancis commented 1 year ago

Hello! It's not about CLI tool but may be helpful. I'm using the gradle plugin org.openapi.generator version 5.0.0 My .openapi-generator-ignore is in the root of the project . In the openApiGenerate configuration I defined ignoreFileOverride.set("$rootDir/.openapi-generator-ignore") and the ignoring works if I put paths from the project root. For example. My output directory is $rootDir/backend/build/generated, so README.md generates in $rootDir/backend/build/generated/openapi/README.md. And the ignoring works if I put backend/build/generated/openapi/README.md in .openapi-generator-ignore.

I needed the same solution but in maven. Your comment has helped me to solve my problem:

Problem: In my case, I had two folders A and B. In A I have my main project codes which uses openapi-generator-maven-plugin in pom.xml to generate source codes into the folder B (which is outside root folder A). The problem I had is that I keep a pom.xml file inside B and every time, openapi-generator-maven-plugin generates code it overwrites my pom.xml in B.

Solution I already had a '.openapi-generator-ignore' file in root folder A and I tried adding ../B/pom.xml in it. But the ignore file cannot ignore files outside the root folder A. After reading 'openapi-generator-maven-plugin' documentation and your comment, I got the solution.

  1. I added the file '.openapi-generator-ignore' inside B. And added my pom.xml for B. So B has these two files. And I don't want these files to be modified by openapi-generator while creating source files.
  2. I added inside this '.openapi-generator-ignore' inside B:

pom.xml .openapi-generator-ignore

The first one for keeping pom.xml intact and second one for keeping the ignore file intact.

  1. Now In pom.xml of A, inside the <executions><configuration> part of 'openapi-generator-maven-plugin', I added the following:

<ignoreFileOverride>../B/.openapi-generator-ignore</ignoreFileOverride>

Now the plug in will use the ignore file inside B and will use the relative paths inside B.

Thus the files inside B are not overwritten even though the generated source codes are falling inside it.

I think you can do the same for gradle as well.

thomasttvo commented 11 months ago

I ran into this issue and figured out my paths in the ignore file was wrong. I have all the generated stuff in the folder <root>/generated and my override ignore file is at <root>. The content ignore file was like this:

.npmignore
git_push.sh

It should have been like this:

generated/.npmignore
generated/git_push.sh

Once I used these new paths, it finally worked.

Pittiplatsch commented 2 months ago

For the following CLI command:

generate -i /local/_spec/openapi.yml -g php -o /local/src --ignore-file-override=/local/_spec/.openapi-generator-ignore

ignoring does not work as intended as files in /local/_spec/ and /local/src/ do not share the exactly identical hierarchical path, leading to confusing results of ‎CodegenIgnoreProcessor::allowsFile().

IMHO --ignore-file-override option (with arbitrary location, e.g. /local/_spec/.openapi-generator-ignore) should behave exactly the same as storing this very file directly file into output folder (e.g. /local/src/.openapi-generator-ignore). Especially, the behavior documented in https://openapi-generator.tech/docs/faq-extending/#how-do-i-skip-files-during-code-generation should be retained:

The contents of that file will be evaluated relative to the output directory.

Side note: The mentioned workaround of prefixing every rule with **/ is limited to trivial cases as excluding "deep paths" while including others may become tedious for paths with common sub-parts:

# Exclude general README.md
docs/README.md

# But KEEP specific ones:
# models/docs/README.md
# api/docs/README.md
rupert-jung-mw commented 1 month ago

I am at 2.13.5 and it doesn't work for me either. The option is completly ignored. I just moved the ignore file one level up to prevent it from being deleted.

Command:

rimraf ./src/openapi  && openapi-generator-cli generate --generator-key csvbe --ignore-file-override=./src/.openapi-generator-ignore && npx prettier ./src/openapi --write

Note: I have to use rimraf because the generator does not remove outdated files itself. I also need a solution which works for POSIX and Windows.