feat(code_push_protocol): add CreatePatchResponse (#582)

This commit is contained in:
Felix Angelov
2023-06-02 09:48:49 -07:00
committed by GitHub
parent 46e66a7036
commit ff0c2fa5c1
4 changed files with 92 additions and 0 deletions
@@ -1 +1,2 @@
export 'create_patch_request.dart';
export 'create_patch_response.dart';
@@ -0,0 +1,34 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart';
part 'create_patch_response.g.dart';
/// {@template create_patch_response}
/// The response body for POST /api/v1/patches
/// {@endtemplate}
@JsonSerializable()
class CreatePatchResponse {
/// {@macro create_patch_response}
const CreatePatchResponse({
required this.id,
required this.number,
required this.artifactUploadUrls,
});
/// Converts a Map<String, dynamic> to a [CreatePatchResponse]
factory CreatePatchResponse.fromJson(Map<String, dynamic> json) =>
_$CreatePatchResponseFromJson(json);
/// Converts a [CreatePatchResponse] to a Map<String, dynamic>
Map<String, dynamic> toJson() => _$CreatePatchResponseToJson(this);
/// The unique patch identifier.
final int id;
/// The patch number.
/// A larger number equates to a newer patch.
final int number;
/// The upload urls for artifacts.
final ArtifactUploadUrls artifactUploadUrls;
}
@@ -0,0 +1,33 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: implicit_dynamic_parameter, require_trailing_commas, cast_nullable_to_non_nullable, lines_longer_than_80_chars
part of 'create_patch_response.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
CreatePatchResponse _$CreatePatchResponseFromJson(Map<String, dynamic> json) =>
$checkedCreate(
'CreatePatchResponse',
json,
($checkedConvert) {
final val = CreatePatchResponse(
id: $checkedConvert('id', (v) => v as int),
number: $checkedConvert('number', (v) => v as int),
artifactUploadUrls: $checkedConvert('artifact_upload_urls',
(v) => ArtifactUploadUrls.fromJson(v as Map<String, dynamic>)),
);
return val;
},
fieldKeyMap: const {'artifactUploadUrls': 'artifact_upload_urls'},
);
Map<String, dynamic> _$CreatePatchResponseToJson(
CreatePatchResponse instance) =>
<String, dynamic>{
'id': instance.id,
'number': instance.number,
'artifact_upload_urls': instance.artifactUploadUrls.toJson(),
};
@@ -0,0 +1,24 @@
import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart';
import 'package:test/test.dart';
void main() {
group(CreatePatchResponse, () {
test('can be (de)serialized', () {
const response = CreatePatchResponse(
id: 42,
number: 1,
artifactUploadUrls: ArtifactUploadUrls(
android: AndroidArtifactUploadUrls(
x86: 'x86',
aarch64: 'aarch64',
arm: 'arm',
),
),
);
expect(
CreatePatchResponse.fromJson(response.toJson()).toJson(),
equals(response.toJson()),
);
});
});
}