OpenAPITools / OpenAPITools/openapi-generator

[BUG][Protobuf] Generation gets Nullpointer in case of additionalProperties set to false with an allOf

Open
#21,555 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • 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?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

With the introduction of https://github.com/OpenAPITools/openapi-generator/pull/21002 we get the possibility of a nullpointer when an allOf is used.

openapi-generator version

Version 7.0.12 and before it works, after not.

OpenAPI declaration file content or url
"components": {
	"schemas": {
               "AnOldObject": {
		"allOf": [
		  {
			"$ref": "#/components/schemas/ANewObject"
		  },
		  {
			"type": "object",
			"additionalProperties": false
		  }
		]
	  },
	  "ANewObject": {
		"allOf": [
		  {
			"$ref": "#/components/schemas/AnotherObject"
		  },
		  {
			"type": "object",
			"description": "A dummy description.",
			"additionalProperties": false,
			"properties": {
			  "name": {
				"type": "string",
				"nullable": true
			  }
			}
		  }
		]
	  },
	  "AnotherObject": {
		"type": "object",
		"description": "A different description.",
		"x-abstract": true,
		"additionalProperties": false,
		"properties": {
		  "context": {
			"type": "string",
			"nullable": true
		  }
		}
	  }
}
}
Generation Details

Build with maven and protobuf-schema

Steps to reproduce

Build it with maven protobuf-schema have a allOf without additionalProperties (it set to false)

Related issues/PRs

Introduced with https://github.com/OpenAPITools/openapi-generator/pull/21002

Suggest a fix

https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ProtobufSchemaCodegen.java#L1102 will in this case get a Boolean object with false value and passes the nullcheck.

It later looks at getting the schema for it(that does not exists) with
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ProtobufSchemaCodegen.java#L1107
This will return a null. And on the line after we get a nullpointer:
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ProtobufSchemaCodegen.java#L1108

Probably should use the same ModelUtils in the outer if-statement.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ProtobufSchemaCodegen.java around lines 1102-1108 and reproduce the OpenAPI schema with Maven and protobuf-schema. Trace the allOf handling when additionalProperties is false. Done means generation completes without a NullPointerException for the supplied schema.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.