Openapi-generator: [QUESTION] Why do error occur with `--ignore-file-override` option ?

Created on 14 Jul 2019  路  3Comments  路  Source: OpenAPITools/openapi-generator

Bug Report Checklist

  • [x] Have you provided a full/minimal spec to reproduce the issue?
  • [x] Have you validated the input using an OpenAPI validator (example)?
  • [x] What's the version of OpenAPI Generator used?
  • [ ] Have you search for related issues/PRs?
  • [x] What's the actual output vs expected output?
  • [ ] [Optional] Bounty to sponsor the fix (example)
Description

When I execute generate subcommand with --ignore-file-override option, the following error occurred.
Why did error occurr ?
Removing --ignore-file-override option, error did not occur.

$ java -Dapis   -DapiTests=false -DapiDocs=false -jar openapi-generator-cli-4.0.0.jar generate -g python -i petstore-simple.yaml -o out --ignore-file-override=openapi-generator-ignore
[main] INFO  o.o.codegen.DefaultGenerator - OpenAPI Generator: python (client)
[main] INFO  o.o.codegen.DefaultGenerator - Generator 'python' is considered stable.
[main] INFO  o.o.c.languages.PythonClientCodegen - Environment variable PYTHON_POST_PROCESS_FILE not defined so the Python code may not be properly formatted. To define it, try 'export PYTHON_POST_PROCESS_FILE="/usr/local/bin/yapf -i"' (Linux/Mac)
[main] INFO  o.o.c.languages.PythonClientCodegen - NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI). Exception in thread "main" java.lang.RuntimeException: Could not generate api file for 'animals'
        at org.openapitools.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:666)
        at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:922)
        at org.openapitools.codegen.cmd.Generate.run(Generate.java:396)
        at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:60)
Caused by: java.lang.NullPointerException
        at org.openapitools.codegen.ignore.CodegenIgnoreProcessor.allowsFile(CodegenIgnoreProcessor.java:145)
        at org.openapitools.codegen.DefaultGenerator.processTemplateToFile(DefaultGenerator.java:955)
        at org.openapitools.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:617)
        ... 3 more
openapi-generator version
  • openapi-generator-cli-4.0.0.jar
  • java version "1.8.0_162"
OpenAPI declaration file content or url

petstore-simple.yaml

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
  license:
    name: MIT
servers:
  - url: http://petstore.swagger.io/v1
paths:
  /pets/{petId}:
    get:
      summary: Info for a specific pet
      operationId: showPetById
      tags:
        - pets
        - animals
      parameters:
        - name: petId
          in: path
          required: true
          description: The id of the pet to retrieve
          schema:
            type: string
      responses:
        '200':
          description: Expected response to a valid request
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Pet"
components:
  schemas:
    Pet:
      type: object
      required:
        - id
        - name
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
        tag:
          type: string

openapi-generator-ignore file

openapi_client/api/pets_api.py
Command line used for generation
$ java -Dapis -DapiTests=false -DapiDocs=false \
 -jar openapi-generator-cli-4.0.0.jar generate \
 -g python -i petstore-simple.yaml \
 -o out --ignore-file-override=openapi-generator-ignore
Steps to reproduce
Related issues/PRs

I referred to Ignore file format

Python Bug

All 3 comments

馃憤 Thanks for opening this issue!
馃彿 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

I had the same issue with csharp-netcore generation. Try to provide the absoulte (full) path to the ignore file, that helped me.

This is the line it's erroring on (CodegenIgnoreProcessor.java:145):

File file = new File(this.ignoreFile.getParentFile().toURI().relativize(targetFile.toURI()).getPath());

I suspect it's the call to getParentFile(), which returns null if the file has no parent. The fix should be as simple as adding getAbsoluteFile() before the getParentFile() call:

File file = new File(this.ignoreFile.getAbsoluteFile().getParentFile().toURI().relativize(targetFile.toURI()).getPath());

This is still an issue in the latest version of the code, as of 2020-10-30.

Was this page helpful?
0 / 5 - 0 ratings