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

Range Attribute to specify a value inside an array max/min lengths #58993

Open
1 task done
jgarciadelanoceda opened this issue Nov 15, 2024 · 0 comments
Open
1 task done
Labels
area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels

Comments

@jgarciadelanoceda
Copy link
Contributor

jgarciadelanoceda commented Nov 15, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

In this issue domaindrivendev/Swashbuckle.AspNetCore#3120 I thought at first of the RangeAttribute to specify the array min/maxLength, but I do not know if it's the right solution for this matter. I have tested with this property:

[FromQuery, Length(2, 10), Range(-1, 2)]
public int[] Array { get; set; }

The issue at hand is that if you set the RangeAttribute over an array of integer then the model validation does not allow you to put any value:

{
  "type": "https://tools.ietf.org/html/rfc9110#section-15.5.1",
  "title": "One or more validation errors occurred.",
  "status": 400,
  "errors": {
    "Array": [
      "The field Array must be between -1 and 2."
    ]
  },
  "traceId": "00-2553c36e9a1043817d97dfe2746bbb9b-1404e652aadda666-00"
}

And also the OpenApi spec generated by the package Microsoft.AspNetCore.OpenApi does not put the maximum or minimun over the items and it does it over the schema(It writes):

{
	"name": "Array",
	"in": "query",
	"schema": {
		"maximum": 2,
		"minimum": -1,
		"maxItems": 10,
		"minItems": 2,
		"type": "array",
		"items": {
			"type": "integer",
			"format": "int32"
		}
	}
}

And I think it should write:

{
	"name": "Array",
	"in": "query",
	"schema": {
		"maxItems": 10,
		"minItems": 2,
		"type": "array",
		"items": {
			"type": "integer",
			"format": "int32",
			"maximum": 2,
			"minimum": -1,
		}
	}
}

Expected Behavior

The validation of the Annotation to do not occur and also that the OpenApi spec would be the suggested one

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

9.0.100

Anything else?

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Nov 15, 2024
@jgarciadelanoceda jgarciadelanoceda changed the title Range Attribute to specify a value inside an array max/min lenghts Range Attribute to specify a value inside an array max/min lengths Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Projects
None yet
Development

No branches or pull requests

1 participant