Skip to content

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

@danielalmqvist

Description

@danielalmqvist

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

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