internal static AliasPath DeserializeAliasPath(JsonElement element) { Optional <string> path = default; Optional <IReadOnlyList <string> > apiVersions = default; Optional <AliasPattern> pattern = default; Optional <AliasPathMetadata> metadata = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("path")) { path = property.Value.GetString(); continue; } if (property.NameEquals("apiVersions")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } List <string> array = new List <string>(); foreach (var item in property.Value.EnumerateArray()) { array.Add(item.GetString()); } apiVersions = array; continue; } if (property.NameEquals("pattern")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } pattern = AliasPattern.DeserializeAliasPattern(property.Value); continue; } if (property.NameEquals("metadata")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } metadata = AliasPathMetadata.DeserializeAliasPathMetadata(property.Value); continue; } } return(new AliasPath(path.Value, Optional.ToList(apiVersions), pattern.Value, metadata.Value)); }
internal static Alias DeserializeAlias(JsonElement element) { Optional <string> name = default; Optional <IReadOnlyList <AliasPath> > paths = default; Optional <AliasType> type = default; Optional <string> defaultPath = default; Optional <AliasPattern> defaultPattern = default; Optional <AliasPathMetadata> defaultMetadata = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("name")) { name = property.Value.GetString(); continue; } if (property.NameEquals("paths")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } List <AliasPath> array = new List <AliasPath>(); foreach (var item in property.Value.EnumerateArray()) { array.Add(AliasPath.DeserializeAliasPath(item)); } paths = array; continue; } if (property.NameEquals("type")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } type = property.Value.GetString().ToAliasType(); continue; } if (property.NameEquals("defaultPath")) { defaultPath = property.Value.GetString(); continue; } if (property.NameEquals("defaultPattern")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } defaultPattern = AliasPattern.DeserializeAliasPattern(property.Value); continue; } if (property.NameEquals("defaultMetadata")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } defaultMetadata = AliasPathMetadata.DeserializeAliasPathMetadata(property.Value); continue; } } return(new Alias(name.Value, Optional.ToList(paths), Optional.ToNullable(type), defaultPath.Value, defaultPattern.Value, defaultMetadata.Value)); }