Skip to content

[BUG] [ASPNETCORE] Dictionary parameter now generated as object #22347

@leonluc-dev

Description

@leonluc-dev

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

Originally the additionalProperties: true would generate a Dictionary parameter for the method signature. Since v7.16.0 it now just generates a generic object parameter.

openapi-generator version

v7.16.0 and up

OpenAPI declaration file content or url
 "/api/v1/example": {
	"put": {
		"operationId": "PutExample",
		"requestBody": {
			"required": true,
			"content": {
				"application/json": {
					"schema": {
						"type": "object",
						"examples": [
							{
								"example_key1": "value1",
								"example_key2": true
							}
						],
						"additionalProperties": true
					}
				}
			}
		},
		"responses": {
			"201": {
				"description": "Success (Created)"
			},
			"default": {
				"$ref": "#/components/responses/ErrorResponse"
			}
		}
	}
}
Generation Details

Command line:
java -jar openapi-generator-cli.jar generate -i swagger.json -g aspnetcore -o ./out -c generator.config.json

generator.config.json:

{
  "additionalProperties" : {
    "generateBody": false,
    "classModifier": "abstract",
    "nullableReferenceTypes": true,
    "operationResultTask": true,
    "aspnetCoreVersion": "8.0",
    "buildTarget": "library",
    "isLibrary": true,
    "useSwashbuckle": false
  }
}
Steps to reproduce

Using the openapi file + config listed above, the following method signature is generated on 7.16.0 and later:

[HttpPut]
[Route("/api/v1/example")]
[Consumes("application/json")]
[ValidateModelState]
[ProducesResponseType(statusCode: 0, type: typeof(Error))]
public abstract Task<IActionResult> PutExample([FromBody] object body);

The "addtionalproperties": true is supposed to generate a Dictionary parameter as was the case in 7.15 and earlier.

[HttpPut]
[Route("/api/v1/example")]
[Consumes("application/json")]
[ValidateModelState]
[ProducesResponseType(statusCode: 0, type: typeof(Error))]
public abstract Task<IActionResult> PutExample([FromBody]Dictionary<string, Object> requestBody);
Related issues/PRs

Potentially related?:

#22049

Suggest a fix

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