swagger_parser
swagger_parser copied to clipboard
Wrong JsonKey generated
Steps to reproduce
generate Swagger with the following config:
swagger_parser:
enums_to_json: true
schema_path: api.json
output_directory: lib/api
language: dart Default: dart
json_serializer: freezed
global_options:
freezed:
runs_before:
- json_serializable
json_serializable:
runs_before:
- retrofit_generator
The JsonKey is wrong. It should start with a lowercase letter or even be omitted. I checked the previous versions and it seems to be related to the 1.18.0 version
Expected results
@Freezed()
class MenuItem with _$MenuItem {
const factory MenuItem({
required String title,
required LinkOptions linkOptions,
}) = _MenuItem;
factory MenuItem.fromJson(Map<String, Object?> json) => _$MenuItemFromJson(json);
}
Actual results
@Freezed()
class MenuItem with _$MenuItem {
const factory MenuItem({
required String title,
@JsonKey(name: 'LinkOptions')
required LinkOptions linkOptions,
}) = _MenuItem;
factory MenuItem.fromJson(Map<String, Object?> json) => _$MenuItemFromJson(json);
}
Your OpenApi snippet
"components": {
"schemas": {
"MenuItem": {
"type": "object",
"required": ["title"],
"properties": {
"title": { "type": "string", "example": "Test 123" },
"linkOptions": { "$ref": "#/components/schemas/linkOptions" }
}
},
"linkOptions": {
"type": "object",
"required": ["type", "title"],
"properties": {
"type": {
"enum": ["internal", "external"],
"type": "string",
"example": "internal"
}
}
}
}
},
Code sample
No response
Logs
No response
Dart version and used packages versions
Dart version
Dart 3.7.2
Packages version
swagger_parser: 1.22.0
Hey @winren9
The issue comes from here
It renames types and prop by accident
Probably the best way is not to alter file contents but handle proper class naming while creating UniversalType
May the contributor force be with you I had a time to only investigate
I also encountered the same problem. Is this a bug?