Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only set Exclusive Range when they are, do not set them when they are… #2960

Merged
Show file tree
Hide file tree
Changes from 1 commit
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,8 +183,15 @@ private static void ApplyRangeAttribute(OpenApiSchema schema, RangeAttribute ran
{
#if NET8_0_OR_GREATER

schema.ExclusiveMinimum = rangeAttribute.MinimumIsExclusive;
schema.ExclusiveMaximum = rangeAttribute.MaximumIsExclusive;
if(rangeAttribute.MinimumIsExclusive)
jgarciadelanoceda marked this conversation as resolved.
Show resolved Hide resolved
{
schema.ExclusiveMinimum = true;
}

if(rangeAttribute.MaximumIsExclusive)
jgarciadelanoceda marked this conversation as resolved.
Show resolved Hide resolved
{
schema.ExclusiveMaximum = true;
}

#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,15 @@ public void GenerateSchema_SetsValidationProperties_IfComplexTypeHasValidationAt
Assert.Equal(3, schema.Properties["StringWithLength"].MaxLength);
Assert.Equal(1, schema.Properties["ArrayWithLength"].MinItems);
Assert.Equal(3, schema.Properties["ArrayWithLength"].MaxItems);
Assert.Equal(true, schema.Properties["IntWithRange"].ExclusiveMinimum);
Assert.Equal(true, schema.Properties["IntWithRange"].ExclusiveMaximum);
Assert.Equal("byte", schema.Properties["StringWithBase64"].Format);
Assert.Equal("string", schema.Properties["StringWithBase64"].Type);
Assert.Null(schema.Properties["IntWithRange"].ExclusiveMinimum);
Assert.Null(schema.Properties["IntWithRange"].ExclusiveMaximum);
Assert.Equal(true, schema.Properties["IntWithExclusiveRange"].ExclusiveMinimum);
Assert.Equal(true, schema.Properties["IntWithExclusiveRange"].ExclusiveMaximum);
#else
Assert.Null(schema.Properties["IntWithRange"].ExclusiveMinimum);
jgarciadelanoceda marked this conversation as resolved.
Show resolved Hide resolved
Assert.Null(schema.Properties["IntWithRange"].ExclusiveMaximum);
#endif
Assert.Equal(1, schema.Properties["IntWithRange"].Minimum);
Assert.Equal(10, schema.Properties["IntWithRange"].Maximum);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,15 @@ public void GenerateSchema_SetsValidationProperties_IfComplexTypeHasValidationAt
Assert.Equal(3, schema.Properties["StringWithLength"].MaxLength);
Assert.Equal(1, schema.Properties["ArrayWithLength"].MinItems);
Assert.Equal(3, schema.Properties["ArrayWithLength"].MaxItems);
Assert.Equal(true, schema.Properties["IntWithRange"].ExclusiveMinimum);
Assert.Equal(true, schema.Properties["IntWithRange"].ExclusiveMaximum);
Assert.Equal("byte", schema.Properties["StringWithBase64"].Format);
Assert.Equal("string", schema.Properties["StringWithBase64"].Type);
Assert.Null(schema.Properties["IntWithRange"].ExclusiveMinimum);
jgarciadelanoceda marked this conversation as resolved.
Show resolved Hide resolved
Assert.Null(schema.Properties["IntWithRange"].ExclusiveMaximum);
Assert.Equal(true, schema.Properties["IntWithExclusiveRange"].ExclusiveMinimum);
Assert.Equal(true, schema.Properties["IntWithExclusiveRange"].ExclusiveMaximum);
#else
Assert.Null(schema.Properties["IntWithRange"].ExclusiveMinimum);
Assert.Null(schema.Properties["IntWithRange"].ExclusiveMaximum);
#endif
Assert.Equal(1, schema.Properties["IntWithRange"].Minimum);
Assert.Equal(10, schema.Properties["IntWithRange"].Maximum);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,16 @@ public class TypeWithValidationAttributes
public string[] ArrayWithLength { get; set; }

[Range(1, 10, MinimumIsExclusive = true, MaximumIsExclusive = true)]
public int IntWithRange { get; set; }
public int IntWithExclusiveRange { get; set; }

[Base64String]
public string StringWithBase64 { get; set; }

#else
#endif

[Range(1, 10)]
public int IntWithRange { get; set; }

#endif

[RegularExpression("^[3-6]?\\d{12,15}$")]
public string StringWithRegularExpression { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class TypeWithValidationAttributesViaMetadataType

public string StringWithBase64 { get; set; }

public double IntWithExclusiveRange { get; set; }

#endif

public int IntWithRange { get; set; }
Expand Down Expand Up @@ -53,18 +55,16 @@ public class MetadataType
public string[] ArrayWithLength { get; set; }

[Range(1, 10, MinimumIsExclusive = true, MaximumIsExclusive = true)]
public int IntWithRange { get; set; }
public int IntWithExclusiveRange { get; set; }

[Base64String]
public string StringWithBase64 { get; set; }

#else
#endif

[Range(1, 10)]
public int IntWithRange { get; set; }

#endif

[RegularExpression("^[3-6]?\\d{12,15}$")]
public string StringWithRegularExpression { get; set; }

Expand Down
Loading