Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
Carapacik committed Jun 6, 2024
1 parent 9694a23 commit 88d9f91
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 11 deletions.
2 changes: 1 addition & 1 deletion swagger_parser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions swagger_parser/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ ${indentation(2)}const $className(${getParameters(dataClass)});
${getFields(dataClass)}
${indentation(2)}static $className fromJson(Map<String, dynamic> json) => ${className}Mapper.ensureInitialized().decodeMap<$className>(json);
${indentation(
2,
)}static $className fromJson(Map<String, dynamic> json) => ${className}Mapper.ensureInitialized().decodeMap<$className>(json);
}
''';
}
Expand Down Expand Up @@ -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,
)}';
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object?> json) => _\$${className}FromJson(json);
}
''';
Expand Down Expand Up @@ -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,
)}';
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object?> json) => _\$${className}FromJson(json);
${_parametersInClass(dataClass.parameters)}${dataClass.parameters.isNotEmpty ? '\n' : ''}
Expand Down Expand Up @@ -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,
)}'
: '';
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

0 comments on commit 88d9f91

Please sign in to comment.