Skip to content

Commit ca6025d

Browse files
committed
Add formatOutput param to jsonPartBuilder
Mirrors param in source_gen PartBuilder
1 parent 56d65fa commit ca6025d

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

json_serializable/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.5.5
2+
3+
* Added named `formatOutput` parameter to `jsonPartBuilder`.
4+
15
## 0.5.4
26

37
* Add `checked` configuration option. If `true`, generated `fromJson` functions

json_serializable/lib/src/json_part_builder.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,20 @@ import 'json_serializable_generator.dart';
1515
/// If `null`, the content of [defaultFileHeader] is used.
1616
/// If [header] is an empty `String` no header is added.
1717
///
18+
/// [formatOutput] is called to format the generated code. If not provided,
19+
/// the default Dart code formatter is used.
20+
///
1821
/// For details on [useWrappers], [anyMap], and [checked] see
1922
/// [JsonSerializableGenerator].
2023
Builder jsonPartBuilder(
2124
{String header,
25+
String formatOutput(String code),
2226
bool useWrappers: false,
2327
bool anyMap: false,
2428
bool checked: false}) {
2529
return new PartBuilder([
2630
new JsonSerializableGenerator(
2731
useWrappers: useWrappers, anyMap: anyMap, checked: checked),
2832
const JsonLiteralGenerator()
29-
], header: header);
33+
], header: header, formatOutput: formatOutput);
3034
}

json_serializable/tool/build.dart

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,24 @@ import 'package:json_serializable/src/json_part_builder.dart' as jpb;
1414
import 'builder.dart';
1515

1616
Builder _jsonPartBuilder(
17-
{bool useWrappers: false, bool anyMap: false, bool checked: false}) =>
18-
jpb.jsonPartBuilder(
19-
header: copyrightHeader,
20-
useWrappers: useWrappers,
21-
anyMap: anyMap,
22-
checked: checked);
17+
{bool useWrappers: false,
18+
bool anyMap: false,
19+
bool checked: false,
20+
bool format}) {
21+
format ??= true;
22+
String Function(String code) formatOutput;
23+
24+
if (!format) {
25+
formatOutput = (s) => s;
26+
}
27+
28+
return jpb.jsonPartBuilder(
29+
header: copyrightHeader,
30+
formatOutput: formatOutput,
31+
useWrappers: useWrappers,
32+
anyMap: anyMap,
33+
checked: checked);
34+
}
2335

2436
final List<BuilderApplication> builders = [
2537
applyToRoot(nonNull(),

0 commit comments

Comments
 (0)