From 5915c57035879db20ba7700924dffaf70255b549 Mon Sep 17 00:00:00 2001 From: provokateurin Date: Wed, 14 Aug 2024 11:07:45 +0200 Subject: [PATCH] fix(dynamite): Escape wireNames Signed-off-by: provokateurin --- .../lib/src/builder/resolve_interface.dart | 3 +- .../lib/interfaces.openapi.dart | 2 ++ .../lib/interfaces.openapi.g.dart | 31 ++++++++++++++++--- .../lib/interfaces.openapi.json | 3 ++ 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/packages/dynamite/lib/src/builder/resolve_interface.dart b/packages/dynamite/lib/src/builder/resolve_interface.dart index f3b2b9b294a..50ac3821627 100644 --- a/packages/dynamite/lib/src/builder/resolve_interface.dart +++ b/packages/dynamite/lib/src/builder/resolve_interface.dart @@ -9,6 +9,7 @@ import 'package:dynamite/src/helpers/dynamite.dart'; import 'package:dynamite/src/helpers/pattern_check.dart'; import 'package:dynamite/src/models/json_schema.dart' as json_schema; import 'package:dynamite/src/models/type_result.dart'; +import 'package:source_helper/source_helper.dart'; Spec buildInterface( State state, @@ -245,7 +246,7 @@ void _generateProperty( final builtValueFieldAnnotations = {}; if (dartName != propertyName) { - builtValueFieldAnnotations['wireName'] = literalString(propertyName); + builtValueFieldAnnotations['wireName'] = refer(escapeDartString(propertyName)); } if (builtValueFieldAnnotations.isNotEmpty) { diff --git a/packages/dynamite/packages/dynamite_end_to_end_test/lib/interfaces.openapi.dart b/packages/dynamite/packages/dynamite_end_to_end_test/lib/interfaces.openapi.dart index cfccf58b92e..25f3c366e1b 100644 --- a/packages/dynamite/packages/dynamite_end_to_end_test/lib/interfaces.openapi.dart +++ b/packages/dynamite/packages/dynamite_end_to_end_test/lib/interfaces.openapi.dart @@ -68,6 +68,8 @@ abstract class Base implements $BaseInterface, Built { @BuiltValue(instantiable: false) sealed class $BaseInterfaceInterface { String? get attribute; + @BuiltValueField(wireName: r'$property') + String? get property; /// Rebuilds the instance. /// diff --git a/packages/dynamite/packages/dynamite_end_to_end_test/lib/interfaces.openapi.g.dart b/packages/dynamite/packages/dynamite_end_to_end_test/lib/interfaces.openapi.g.dart index 022083850d1..accd3bbade9 100644 --- a/packages/dynamite/packages/dynamite_end_to_end_test/lib/interfaces.openapi.g.dart +++ b/packages/dynamite/packages/dynamite_end_to_end_test/lib/interfaces.openapi.g.dart @@ -66,6 +66,12 @@ class _$BaseInterfaceSerializer implements StructuredSerializer { ..add('attribute') ..add(serializers.serialize(value, specifiedType: const FullType(String))); } + value = object.property; + if (value != null) { + result + ..add('\$property') + ..add(serializers.serialize(value, specifiedType: const FullType(String))); + } return result; } @@ -83,6 +89,9 @@ class _$BaseInterfaceSerializer implements StructuredSerializer { case 'attribute': result.attribute = serializers.deserialize(value, specifiedType: const FullType(String)) as String?; break; + case '\$property': + result.property = serializers.deserialize(value, specifiedType: const FullType(String)) as String?; + break; } } @@ -178,16 +187,21 @@ abstract mixin class $BaseInterfaceInterfaceBuilder { void update(void Function($BaseInterfaceInterfaceBuilder) updates); String? get attribute; set attribute(String? attribute); + + String? get property; + set property(String? property); } class _$BaseInterface extends BaseInterface { @override final String? attribute; + @override + final String? property; factory _$BaseInterface([void Function(BaseInterfaceBuilder)? updates]) => (BaseInterfaceBuilder()..update(updates))._build(); - _$BaseInterface._({this.attribute}) : super._(); + _$BaseInterface._({this.attribute, this.property}) : super._(); @override BaseInterface rebuild(void Function(BaseInterfaceBuilder) updates) => (toBuilder()..update(updates)).build(); @@ -198,20 +212,24 @@ class _$BaseInterface extends BaseInterface { @override bool operator ==(Object other) { if (identical(other, this)) return true; - return other is BaseInterface && attribute == other.attribute; + return other is BaseInterface && attribute == other.attribute && property == other.property; } @override int get hashCode { var _$hash = 0; _$hash = $jc(_$hash, attribute.hashCode); + _$hash = $jc(_$hash, property.hashCode); _$hash = $jf(_$hash); return _$hash; } @override String toString() { - return (newBuiltValueToStringHelper(r'BaseInterface')..add('attribute', attribute)).toString(); + return (newBuiltValueToStringHelper(r'BaseInterface') + ..add('attribute', attribute) + ..add('property', property)) + .toString(); } } @@ -222,6 +240,10 @@ class BaseInterfaceBuilder implements Builder _$this._attribute; set attribute(covariant String? attribute) => _$this._attribute = attribute; + String? _property; + String? get property => _$this._property; + set property(covariant String? property) => _$this._property = property; + BaseInterfaceBuilder() { BaseInterface._defaults(this); } @@ -230,6 +252,7 @@ class BaseInterfaceBuilder implements Builder