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

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

Open OnkelTem opened this issue 5 years ago • 16 comments

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.

OnkelTem avatar Mar 27 '20 08:03 OnkelTem

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.

msumit avatar Mar 22 '21 09:03 msumit

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?

wing328 avatar Mar 22 '21 10:03 wing328

@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.

rcky avatar Mar 24 '21 13:03 rcky

It worked for me with v5.1.0

msumit avatar Mar 24 '21 14:03 msumit

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 ../..).

jparise avatar Mar 24 '21 19:03 jparise

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.

mizolight avatar Mar 26 '21 04:03 mizolight

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.

pawar-ram avatar Apr 03 '21 19:04 pawar-ram

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

gpeers avatar Dec 21 '21 00:12 gpeers

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

I faced the same problem

RomanSoloweow avatar Feb 09 '22 15:02 RomanSoloweow

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

wing328 avatar Feb 09 '22 17:02 wing328

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.

dmitryerikin avatar Apr 26 '22 06:04 dmitryerikin

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/

isnikulin avatar Aug 13 '22 16:08 isnikulin

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?

mariocozta avatar Nov 07 '22 11:11 mariocozta

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.

sebinefrancis avatar Jan 16 '23 16:01 sebinefrancis

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.

thomasttvo avatar Nov 28 '23 21:11 thomasttvo

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

Pittiplatsch avatar Aug 26 '24 09:08 Pittiplatsch

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.

rupert-jung-mw avatar Oct 07 '24 10:10 rupert-jung-mw