OpenAPITools / OpenAPITools/openapi-generator
[BUG][Dart][built_value] additionalProperties: true on object schema causes model-to-Builder assignment error
Nobody has claimed this yet.
- 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?
- [ x Have you searched for related issues/PRs?
- What's the actual output vs expected output?
Description
When generating a Dart client (built_value) the deserializer assigns a concrete model instance to a Builder field when the property’s schema is an object with additionalProperties: true. This causes a build error:
type 'MyOwner' is not a subtype of type 'MyOwnerBuilder?' in type cast
Root cause: in _deserializeProperties, the generated code does
result.owner = valueDes; // valueDes is KoronaOwner
instead of assigning to the builder via .replace(...) or .toBuilder().
openapi-generator version
Using this flutter package.
https://github.com/gibahjoe/openapi-generator-dart/
But using the jar version:
"openapiGeneratorVersion": "7.15.0",
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: MRE for built_value builder assignment bug
version: 1.0.0
paths: {}
components:
schemas:
MyOwner:
type: object
title: MyOwner
properties:
firstname:
type: string
nullable: true
lastname:
type: string
nullable: true
birthdate:
type: string
format: date
nullable: true
description: The birthdate of the owner
additionalProperties: true # <-- critical trigger
PersonalizationRequest:
type: object
required: [ticketNumber]
properties:
ticketNumber:
type: string
owner:
$ref: '#/components/schemas/MyOwner'
Generation Details
java -jar .dart_tool/openapi_generator_cache/openapi-generator-cli-7.15.0.jar
generate
-i ./mre.yaml
-g dart-dio
-o ./out-dart
--additional-properties=pubName=mre_client,packageName=mre_client
Steps to reproduce
Just try to compile.
void _deserializeProperties(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
required List<Object?> serializedList,
required OmniPersonalizationRequestBuilder result,
required List<Object?> unhandled,
}) {
for (var i = 0; i < serializedList.length; i += 2) {
final key = serializedList[i] as String;
final value = serializedList[i + 1];
switch (key) {
case r'ticketNumber':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.ticketNumber = valueDes;
break;
case r'owner':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(MyOwner),
) as MyOwner;
result.owner = valueDes; <---- Error
break;
default:
unhandled.add(key);
unhandled.add(value);
break;
}
}
}
Suggest a fix
Adjusting the template to use
.toBuilder in that case. I am not familiar with this code base so i didnt try.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the Dart built_value template or generation path that produces _deserializeProperties, then reproduce the issue with the provided OpenAPI YAML and the shown 7.15.0 generation command. Done means the generated Dart client compiles for the PersonalizationRequest.owner case without the model-to-Builder assignment error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100