MiniProgramPublisherBackendContract.fromJson constructor
Decodes a provider-neutral Publisher API contract.
Implementation
factory MiniProgramPublisherBackendContract.fromJson(
Object? json, {
bool allowLocalHttp = false,
}) {
if (json is! Map) {
throw const FormatException(
'Publisher API contract must be a JSON object.',
);
}
final type = _readString(json, 'type');
if (type != documentType) {
throw FormatException(
'Publisher API contract type must be "$documentType".',
);
}
final backendBaseUri = Uri.tryParse(_readString(json, 'backendBaseUrl'));
if (backendBaseUri == null) {
throw const FormatException(
'Publisher API contract backendBaseUrl is invalid.',
);
}
final healthEndpoint =
_readOptionalString(json, 'healthEndpoint') ?? defaultHealthEndpoint;
return MiniProgramPublisherBackendContract(
schemaVersion: _readInt(json, 'schemaVersion'),
contractVersion: _readString(json, 'contractVersion'),
appId: _readString(json, 'appId'),
backendBaseUri: backendBaseUri,
accessMode:
_readOptionalString(json, 'accessMode') ?? accessModeProtected,
healthEndpoint: healthEndpoint,
smokeTests: _readSmokeTests(
json['smokeTests'],
healthEndpoint: healthEndpoint,
),
allowLocalHttp: allowLocalHttp,
);
}