Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ private OpenApiSchema GenerateSchemaForType(Type modelType, SchemaRepository sch
if (schema.Reference == null)
{
ApplyFilters(schema, modelType, schemaRepository);
if (Nullable.GetUnderlyingType(modelType) != null)
{
schema.Nullable = true;
}
}

return schema;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,28 +161,34 @@ public void GenerateSchema_GeneratesReferencedDictionarySchema_IfDictionaryTypeI
Assert.Equal(schema.AdditionalProperties.Reference.Id, referenceSchema.Reference.Id); // ref to self
}

public static TheoryData<Type, JsonSchemaType, string> EnumerableTypeData => new()
{
{ typeof(int[]), JsonSchemaTypes.Integer, "int32" },
{ typeof(IEnumerable<string>), JsonSchemaTypes.String, null },
{ typeof(DateTime?[]), JsonSchemaTypes.String, "date-time" },
{ typeof(int[][]), JsonSchemaTypes.Array, null },
{ typeof(IList), null, null },
public static TheoryData<Type, JsonSchemaType, string, bool> EnumerableTypeData => new()
Comment thread
martincostello marked this conversation as resolved.
{
{ typeof(int[]), JsonSchemaTypes.Integer, "int32", false },
{ typeof(int?[]), JsonSchemaTypes.Integer, "int32", true },
{ typeof(double[]), JsonSchemaTypes.Number, "double", false },
{ typeof(double?[]), JsonSchemaTypes.Number, "double", true },
{ typeof(DateTime[]), JsonSchemaTypes.String, "date-time", false },
{ typeof(DateTime?[]), JsonSchemaTypes.String, "date-time", true },
{ typeof(IEnumerable<string>), JsonSchemaTypes.String, null, false },
{ typeof(int[][]), JsonSchemaTypes.Array, null, false },
{ typeof(IList), null, null, false },
};

[Theory]
[MemberData(nameof(EnumerableTypeData))]
public void GenerateSchema_GeneratesArraySchema_IfEnumerableType(
Type type,
JsonSchemaType expectedItemsType,
string expectedItemsFormat)
string expectedItemsFormat,
bool expectedItemsNullable)
{
var schema = Subject().GenerateSchema(type, new SchemaRepository());

Assert.Equal(JsonSchemaTypes.Array, schema.Type);
Assert.NotNull(schema.Items);
Assert.Equal(expectedItemsType, schema.Items.Type);
Assert.Equal(expectedItemsFormat, schema.Items.Format);
Assert.Equal(expectedItemsNullable, schema.Items.Nullable);
}

[Theory]
Expand Down