OpenAPITools / OpenAPITools/openapi-generator

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

Open
#22,347 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

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

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

Use the supplied OpenAPI declaration, generator.config.json, and Java CLI command to reproduce output with the aspnetcore generator on v7.16.0 and compare it with v7.15. Inspect the handling of an object schema with additionalProperties: true. Done means the generated PutExample signature uses Dictionary<string, Object> as it did in v7.15 and earlier.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.