Skip to content

Commit

Permalink
domaindrivendev#2378 nullable issue?
Browse files Browse the repository at this point in the history
  • Loading branch information
anoordover committed Mar 30, 2022
1 parent fcbec2c commit c11f3bc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ public enum JsonConverterAnnotatedEnum
[EnumMember(Value = "X-foo")]
X = 8
}

public class EnumHolder1
{
public int? AnnotatedEnum { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,33 @@ public void GenerateSchema_HonorsSerializerAttribute_StringEnumConverter()
Assert.Equal(new[] { "\"Value1\"", "\"Value2\"", "\"X-foo\"" }, schema.Enum.Select(openApiAny => openApiAny.ToJson()));
}

[Fact]
public void GenerateSchema_NullableProperty_ShouldBeNullable()
{
var schemaRepository = new SchemaRepository();

var referenceSchema = Subject().GenerateSchema(typeof(EnumHolder1), schemaRepository);

//TODO: see https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/2378#issuecomment-1072977332
//Will this be a $ref in swagger.json?
//according to the comment a $ref cannot contain nullable: true
var schema = schemaRepository.Schemas[referenceSchema.Reference.Id];
var property = schema.Properties["AnnotatedEnum"];
Assert.True(property.Nullable);
}

[Fact]
public void GenerateSchema_QuestionmarkProperty_ShouldBeNullable()
{
var schemaRepository = new SchemaRepository();

var referenceSchema = Subject().GenerateSchema(typeof(EnumHolder1), schemaRepository);

var schema = schemaRepository.Schemas[referenceSchema.Reference.Id];
var property = schema.Properties["AnnotatedEnum"];
Assert.True(property.Nullable);
}

[Fact]
public void GenerateSchema_HonorsSerializerAttribute_JsonIgnore()
{
Expand Down

0 comments on commit c11f3bc

Please sign in to comment.