Skip to content

[BUG] Generator breaks on empty properties fields in components. #17172

@davegarred

Description

@davegarred

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
Description

Generator breaks on empty properties fields in components.

openapi-generator version

7.2.0-SNAPSHOT
commit: 0d2a016

OpenAPI declaration file content or url

The Discord API contains multiple empty properties which break in this tool but are valid. I've pushed up a simpler version taken taken from that.

Generation Details

Attempt to generate a client from a spec that includes a schema with property that is empty.
E.g.,

"components": {
  "schemas": {
    "GithubWebhook": {
      "type": "object",
      "properties": {
        "pull_request": {}
      }
    }
  }
}

A NullPointerException is produced.

Exception: null
	at org.openapitools.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:1269)
	at org.openapitools.codegen.DefaultGenerator.processPaths(DefaultGenerator.java:1163)
	at org.openapitools.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:609)
	at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:994)
	at org.openapitools.codegen.cmd.Generate.execute(Generate.java:519)
	at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
	at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
Caused by: java.lang.NullPointerException
	at org.openapitools.codegen.examples.ExampleGenerator.resolvePropertyToExample(ExampleGenerator.java:228)
	at org.openapitools.codegen.examples.ExampleGenerator.resolveModelToExample(ExampleGenerator.java:352)
	at org.openapitools.codegen.examples.ExampleGenerator.resolvePropertyToExample(ExampleGenerator.java:311)
	at org.openapitools.codegen.examples.ExampleGenerator.resolveModelToExample(ExampleGenerator.java:352)
	at org.openapitools.codegen.examples.ExampleGenerator.generate(ExampleGenerator.java:159)
	at org.openapitools.codegen.DefaultCodegen.fromOperation(DefaultCodegen.java:4673)
	at org.openapitools.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:1237)
	... 6 more
Steps to reproduce

Generate using the cli tool (any language).

docker run --rm -v ./:/local \
  openapitools/openapi-generator-cli \
  generate \
  -g rust \
  -o /local/output_directory \
  -i /local/openapi.json
Related issues/PRs

None found yet.

Suggest a fix

Edit: https://github.com/OpenAPITools/openapi-generator/pull/17173/files

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions