OpenAPITools / OpenAPITools/openapi-generator

[BUG] [dart-dio] "additionalProperties" in dictionary with fixed keys ignored

Open
#16,722 1 comment 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 (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?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

I am using an OpenAPI declaration to generate Dart-code with Dio as the client. The API allows some text to be translated, so it uses a string dictionary for those. As fixed keys, it declares "de-DE", "en-US" and "default" (since those are the ones usually used), but since more languages should be supported when needed there is also "additionalProperties" set. This is described here:

https://swagger.io/docs/specification/data-models/dictionaries/#fixed-keys

(In the documentation the fixed keys are used to declare them as required, the API I'm using does not. But even if it did set these keys as required, the behaviour below would not change.)

When I generate my client, the generated model class only contains three fields (the fixed keys), but no way to set/get more languages. If the fixed keys were to be removed from the declaration, a string-map would be used, that way allowing all languages to be set/get.

openapi-generator version

docker latest: openapi-generator-cli 7.1.0-SNAPSHOT commit : 7087b33
and docker latest-release: openapi-generator-cli 7.0.1 commit : 6745998

OpenAPI declaration file content or url

This is the condensed version containing the relevant part of a larger declaration: https://gist.github.com/czaefferer/a215fd8472cfaf14aa7a0416c30060f9

Generation Details / Steps to reproduce

I am using the docker based generator to generate a Dart client for the declaration above:

docker run --rm \
	-v ${PWD}/test-additional-properties.json:/configuration/swagger.json \
	-v /tmp/test-gen:/output \
	openapitools/openapi-generator-cli:latest generate \
	-i /configuration/swagger.json \
	-g dart-dio \
	-o /output \
	--additional-properties=serializationLibrary=json_serializable

Ignoring all annotations and boilerplate code, this is the resulting class for the dictionary:

class TestName {
  TestName({
     this.deDE,
     this.enUS,
     this.default_,
  });

  final String? deDE;
  final String? enUS;
  final String? default_;
}

-> I cannot retrieve or set more languages than those a fixed key exists for.

I would expect to have an additional Map<String, String> containing all or all additional strings.

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 with the condensed OpenAPI declaration in the linked gist and reproduce the issue using the provided Docker command with the dart-dio generator. Inspect how fixed keys and additionalProperties are represented in the generated TestName model. Done means the generated client retains the fixed-key fields and also permits setting and retrieving other language keys through a String-to-String map.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.