Skip to content

Commit

Permalink
allow schema to be null in example creation
Browse files Browse the repository at this point in the history
  • Loading branch information
dldl-cmd committed Apr 15, 2024
1 parent fa399af commit 3ca86f8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static class XmlCommentsExampleHelper
string exampleString)
{
var isStringType =
(schema.ResolveType(schemaRepository) == "string") &&
(schema?.ResolveType(schemaRepository) == "string") &&
!exampleString.Equals("null");

var exampleAsJson = isStringType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private void ApplyParamTags(OpenApiParameter parameter, ParameterFilterContext c
var example = paramNode.GetAttribute("example", "");
if (string.IsNullOrEmpty(example)) return;

parameter.Example = XmlCommentsExampleHelper.Create(context.SchemaRepository, parameter.Schema, example.ToString());
parameter.Example = XmlCommentsExampleHelper.Create(context.SchemaRepository, parameter.Schema, example);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,15 @@ public void Create_ReturnsNull_When_TypeString_and_ValueNull()

Assert.Equal(AnyType.Null, ((OpenApiNull)example).AnyType);
}

[Fact]
public void Create_AllowsSchemaToBeNull()
{
OpenApiSchema schema = null;

IOpenApiAny example = XmlCommentsExampleHelper.Create(schemaRepository, schema, "[]");

Assert.Empty((OpenApiArray)example);
}
}
}

0 comments on commit 3ca86f8

Please sign in to comment.