diff --git a/swagger_parser/CHANGELOG.md b/swagger_parser/CHANGELOG.md index 2742ce31..c38b48de 100644 --- a/swagger_parser/CHANGELOG.md +++ b/swagger_parser/CHANGELOG.md @@ -1,7 +1,7 @@ ## 1.18.0 +- Handle empty enum value case ([#238](https://github.com/Carapacik/swagger_parser/pull/238)) - Some fixes for the replacement rules - Support for nullable lists and maps -- Handle empty enum value case (thanks to @Sadhorsephile) - Remove config parameter `required_by_default`, behaviour is now consistent `required_by_default: false` ## 1.17.3 diff --git a/swagger_parser/analysis_options.yaml b/swagger_parser/analysis_options.yaml index 42cbee14..511d8651 100644 --- a/swagger_parser/analysis_options.yaml +++ b/swagger_parser/analysis_options.yaml @@ -8,3 +8,4 @@ linter: avoid_equals_and_hash_code_on_mutable_classes: false package_api_docs: true prefer_relative_imports: true + unnecessary_library_name: false diff --git a/swagger_parser/lib/src/generator/templates/dart_dart_mappable_dto_template.dart b/swagger_parser/lib/src/generator/templates/dart_dart_mappable_dto_template.dart index aaabd78d..2e85364e 100644 --- a/swagger_parser/lib/src/generator/templates/dart_dart_mappable_dto_template.dart +++ b/swagger_parser/lib/src/generator/templates/dart_dart_mappable_dto_template.dart @@ -26,7 +26,9 @@ ${indentation(2)}const $className(${getParameters(dataClass)}); ${getFields(dataClass)} -${indentation(2)}static $className fromJson(Map json) => ${className}Mapper.ensureInitialized().decodeMap<$className>(json); +${indentation( + 2, + )}static $className fromJson(Map json) => ${className}Mapper.ensureInitialized().decodeMap<$className>(json); } '''; } @@ -90,4 +92,7 @@ String _required(UniversalType t) => /// return defaultValue if have String _defaultValue(UniversalType t) => - '${t.enumType != null ? '${t.type}.${protectDefaultEnum(t.defaultValue)?.toCamel}' : protectDefaultValue(t.defaultValue, type: t.type)}'; + '${t.enumType != null ? '${t.type}.${protectDefaultEnum(t.defaultValue)?.toCamel}' : protectDefaultValue( + t.defaultValue, + type: t.type, + )}'; diff --git a/swagger_parser/lib/src/generator/templates/dart_enum_dto_template.dart b/swagger_parser/lib/src/generator/templates/dart_enum_dto_template.dart index b9de30a1..ecdf8fc5 100644 --- a/swagger_parser/lib/src/generator/templates/dart_enum_dto_template.dart +++ b/swagger_parser/lib/src/generator/templates/dart_enum_dto_template.dart @@ -57,7 +57,9 @@ String _dartEnumDartMappableTemplate( final jsonParam = unknownEnumValue || enumsToJson; final values = - '${enumClass.items.mapIndexed((i, e) => _enumValueDartMappable(i, enumClass.type, e, jsonParam: jsonParam)).join(',\n')}${unknownEnumValue ? ',' : ';'}'; + '${enumClass.items.mapIndexed((i, e) => _enumValueDartMappable(i, enumClass.type, e, jsonParam: jsonParam)).join( + ',\n', + )}${unknownEnumValue ? ',' : ';'}'; return ''' ${generatedFileComment( diff --git a/swagger_parser/lib/src/generator/templates/dart_freezed_dto_template.dart b/swagger_parser/lib/src/generator/templates/dart_freezed_dto_template.dart index 6c857bac..2bcffafb 100644 --- a/swagger_parser/lib/src/generator/templates/dart_freezed_dto_template.dart +++ b/swagger_parser/lib/src/generator/templates/dart_freezed_dto_template.dart @@ -22,7 +22,9 @@ part '${dataClass.name.toSnake}.g.dart'; ${descriptionComment(dataClass.description)}@Freezed() class $className with _\$$className { - const factory $className(${dataClass.parameters.isNotEmpty ? '{' : ''}${_parametersToString(dataClass.parameters)}${dataClass.parameters.isNotEmpty ? '\n }' : ''}) = _$className; + const factory $className(${dataClass.parameters.isNotEmpty ? '{' : ''}${_parametersToString( + dataClass.parameters, + )}${dataClass.parameters.isNotEmpty ? '\n }' : ''}) = _$className; \n factory $className.fromJson(Map json) => _\$${className}FromJson(json); } '''; @@ -62,4 +64,7 @@ String _required(UniversalType t) => /// return defaultValue if have String _defaultValue(UniversalType t) => - '${t.enumType != null ? '${t.type}.${protectDefaultEnum(t.defaultValue)?.toCamel}' : protectDefaultValue(t.defaultValue, type: t.type)}'; + '${t.enumType != null ? '${t.type}.${protectDefaultEnum(t.defaultValue)?.toCamel}' : protectDefaultValue( + t.defaultValue, + type: t.type, + )}'; diff --git a/swagger_parser/lib/src/generator/templates/dart_json_serializable_dto_template.dart b/swagger_parser/lib/src/generator/templates/dart_json_serializable_dto_template.dart index 9698e002..b14c3ce1 100644 --- a/swagger_parser/lib/src/generator/templates/dart_json_serializable_dto_template.dart +++ b/swagger_parser/lib/src/generator/templates/dart_json_serializable_dto_template.dart @@ -21,7 +21,9 @@ part '${dataClass.name.toSnake}.g.dart'; ${descriptionComment(dataClass.description)}@JsonSerializable() class $className { - const $className(${dataClass.parameters.isNotEmpty ? '{' : ''}${_parametersInConstructor(dataClass.parameters)}${dataClass.parameters.isNotEmpty ? '\n }' : ''}); + const $className(${dataClass.parameters.isNotEmpty ? '{' : ''}${_parametersInConstructor( + dataClass.parameters, + )}${dataClass.parameters.isNotEmpty ? '\n }' : ''}); factory $className.fromJson(Map json) => _\$${className}FromJson(json); ${_parametersInClass(dataClass.parameters)}${dataClass.parameters.isNotEmpty ? '\n' : ''} @@ -62,5 +64,8 @@ String _required(UniversalType t) => String _defaultValue(UniversalType t) => t.defaultValue != null ? ' = ' '${t.wrappingCollections.isNotEmpty ? 'const ' : ''}' - '${t.enumType != null ? '${t.type}.${protectDefaultEnum(t.defaultValue)?.toCamel}' : protectDefaultValue(t.defaultValue, type: t.type)}' + '${t.enumType != null ? '${t.type}.${protectDefaultEnum(t.defaultValue)?.toCamel}' : protectDefaultValue( + t.defaultValue, + type: t.type, + )}' : ''; diff --git a/swagger_parser/lib/src/generator/templates/dart_retrofit_client_template.dart b/swagger_parser/lib/src/generator/templates/dart_retrofit_client_template.dart index a8b69bd5..9bff72a0 100644 --- a/swagger_parser/lib/src/generator/templates/dart_retrofit_client_template.dart +++ b/swagger_parser/lib/src/generator/templates/dart_retrofit_client_template.dart @@ -17,7 +17,9 @@ String dartRetrofitClientTemplate({ }) { final sb = StringBuffer( ''' -${generatedFileComment(markFileAsGenerated: markFileAsGenerated)}${_convertImport(restClient)}${_fileImport(restClient)}import 'package:dio/dio.dart'${_hideHeaders(restClient, defaultContentType)}; +${generatedFileComment(markFileAsGenerated: markFileAsGenerated)}${_convertImport(restClient)}${_fileImport( + restClient, + )}import 'package:dio/dio.dart'${_hideHeaders(restClient, defaultContentType)}; import 'package:retrofit/retrofit.dart'; ${dartImports(imports: restClient.imports, pathPrefix: '../models/')} part '${name.toSnake}.g.dart'; diff --git a/swagger_parser/lib/src/generator/templates/kotlin_enum_dto_template.dart b/swagger_parser/lib/src/generator/templates/kotlin_enum_dto_template.dart index 831cbf4f..1298aeea 100644 --- a/swagger_parser/lib/src/generator/templates/kotlin_enum_dto_template.dart +++ b/swagger_parser/lib/src/generator/templates/kotlin_enum_dto_template.dart @@ -23,7 +23,9 @@ String _parameters(UniversalEnumClass dataClass) => dataClass.items .mapIndexed( (i, e) => '${i != 0 && e.description != null ? '\n\n' : '\n'}${descriptionComment(e.description, tab: ' ')}' - '${dataClass.type != 'string' || e.jsonKey != e.name.toScreamingSnake ? ' @Json("${protectJsonKey(e.jsonKey)}")' : ''}\n ' + '${dataClass.type != 'string' || e.jsonKey != e.name.toScreamingSnake ? ' @Json("${protectJsonKey( + e.jsonKey, + )}")' : ''}\n ' '${e.name.toScreamingSnake},', ) .join(); diff --git a/swagger_parser/lib/src/generator/templates/kotlin_typedef_template.dart b/swagger_parser/lib/src/generator/templates/kotlin_typedef_template.dart index c8415760..ea12f927 100644 --- a/swagger_parser/lib/src/generator/templates/kotlin_typedef_template.dart +++ b/swagger_parser/lib/src/generator/templates/kotlin_typedef_template.dart @@ -16,6 +16,8 @@ String kotlinTypeDefTemplate( if (type == null) { return ''; } - return '${generatedFileComment(markFileAsGenerated: markFileAsGenerated, ignoreLints: false)}${descriptionComment(dataClass.description)}' + return '${generatedFileComment(markFileAsGenerated: markFileAsGenerated, ignoreLints: false)}${descriptionComment( + dataClass.description, + )}' 'typealias $className = ${type.toSuitableType(ProgrammingLanguage.kotlin)};\n'; }