Skip to content

Commit

Permalink
Attach empty property groups instead of null for missing page info no…
Browse files Browse the repository at this point in the history
…de and empty node:

RevisionsPropertyGroup, LanguageLinksPropertyGroup, GeoCoordinatesPropertyGroup
Corresponding pageinfo node won't exist at all for pages without categories / langlinks etc.
We don't want consumers to bump into NRE in this case.
  • Loading branch information
CXuesong committed Sep 1, 2024
1 parent a6d1afc commit 0da96e7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ public class GeoCoordinatesPropertyGroup : WikiPagePropertyGroup

internal static GeoCoordinatesPropertyGroup? Create(JsonArray? jcoordinates)
{
if (jcoordinates == null) return null;
if (jcoordinates.Count == 0) return empty;
if (jcoordinates == null || jcoordinates.Count == 0) return empty;
return new GeoCoordinatesPropertyGroup(jcoordinates);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,10 @@ public class LanguageLinksPropertyGroup : WikiPagePropertyGroup

private static readonly LanguageLinksPropertyGroup Empty = new LanguageLinksPropertyGroup(Array.Empty<LanguageLinkInfo>());

internal static LanguageLinksPropertyGroup? Create(JsonObject jpage)
internal static LanguageLinksPropertyGroup Create(JsonObject jpage)
{
var jlangLinks = jpage["langlinks"];
if (jlangLinks == null) return null;
if (jpage.Count == 0) return Empty;
if (jlangLinks == null || jpage.Count == 0) return Empty;
var langLinks = jlangLinks.Deserialize<IReadOnlyCollection<LanguageLinkInfo>>(MediaWikiHelper.WikiJsonSerializerOptions);
return new LanguageLinksPropertyGroup(langLinks!);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,14 @@ public override int GetMaxPaginationSize(MediaWikiVersion version, bool apiHighL
public class RevisionsPropertyGroup : WikiPagePropertyGroup
{

private static readonly RevisionsPropertyGroup Empty = new RevisionsPropertyGroup();
private static readonly RevisionsPropertyGroup Empty = new ();

private Revision[] _Revisions;

internal static RevisionsPropertyGroup? Create(JsonObject jpage)
{
var jrevisions = jpage["revisions"]?.AsArray();
if (jrevisions == null) return null;
if (jrevisions.Count == 0) return Empty;
if (jrevisions == null || jrevisions.Count == 0) return Empty;
var stub = MediaWikiHelper.PageStubFromJson(jpage);
return new RevisionsPropertyGroup(stub, jrevisions);
}
Expand Down

0 comments on commit 0da96e7

Please sign in to comment.