Skip to content

Commit

Permalink
Check null reference in PropertiesTreeBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
pszybiak committed Oct 21, 2024
1 parent 7118351 commit ae357ad
Showing 1 changed file with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,20 @@ public void AddPropertiesTreeForMediaTypes(RowPointer actualRow, IDictionary<str
Worksheet.Cell(ActualRow, 1).SetTextBold($"Body format: {mediaType.Key}");
ActualRow.MoveNext();

using (var _ = new Section(Worksheet, ActualRow))
if (mediaType.Value.Schema != null)
{
var columnCount = AddPropertiesTree(ActualRow, mediaType.Value.Schema, options);
Worksheet.Cell(bodyFormatRowPointer, 1).SetBackground(columnCount, HeaderBackgroundColor);
ActualRow.MovePrev();
using (var _ = new Section(Worksheet, ActualRow))
{
var columnCount = AddPropertiesTree(ActualRow, mediaType.Value.Schema, options);
Worksheet.Cell(bodyFormatRowPointer, 1).SetBackground(columnCount, HeaderBackgroundColor);
ActualRow.MovePrev();
}
ActualRow.MoveNext(2);
}
else
{
ActualRow.MoveNext();
}
ActualRow.MoveNext(2);
}
}

Expand All @@ -53,8 +60,11 @@ protected bool CorrectRootElementIfArray(OpenApiSchema schema)
return true;
}

protected void AddProperties(OpenApiSchema schema, int level, OpenApiDocumentationOptions options)
protected void AddProperties(OpenApiSchema? schema, int level, OpenApiDocumentationOptions options)
{
if (schema == null)
return;

if (schema.Items != null)
{
AddPropertiesForArray(schema, level, options);
Expand Down Expand Up @@ -87,11 +97,11 @@ private void AddPropertiesForArray(OpenApiSchema schema, int level, OpenApiDocum
}
}

protected void AddProperty(string name, OpenApiSchema schema, bool required, int level, OpenApiDocumentationOptions options)
protected void AddProperty(string name, OpenApiSchema? schema, bool required, int level, OpenApiDocumentationOptions options)
{
if (level >= options.MaxDepth)
if (schema == null || level >= options.MaxDepth)
{
return;
return;
}

AddPropertyRow(name, schema, required, level++);
Expand Down

0 comments on commit ae357ad

Please sign in to comment.