-
-
Notifications
You must be signed in to change notification settings - Fork 160
openapi: support validation attributes #1477
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
openapi: support validation attributes #1477
Conversation
|
@bkoelman could you give a preliminary review on just that? |
|
@verdie-g Do you still intend to complete this? |
|
Unfortunately I don't think I'll find the time. |
|
I pushed some old changes that were still on my machine in case someone wants to continue the PR. |
3f781fb to
9dee70f
Compare
f46fc65 to
07c9d7d
Compare
test/OpenApiNSwagEndToEndTests/ModelValidation/ModelValidationTests.cs
Outdated
Show resolved
Hide resolved
test/OpenApiNSwagEndToEndTests/ModelValidation/ModelValidationTests.cs
Outdated
Show resolved
Hide resolved
|
Hi @bkoelman, I'll try finishing that PR. Could you have a pass on its current state, I'll add tests for Kiota once the one for NSwag start looking okay. Also, is there anything worth adding to the doc regarding this change? |
Cool! Sure, I'll take a look. I don't expect the docs need to be updated, unless there are pitfalls users should know about. For kiota, it's worth removing the |
bkoelman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added some comments on things that jumped out to me. Before focussing on kiota, we should get the proposed scope table in better shape.
test/OpenApiNSwagEndToEndTests/OpenApiNSwagEndToEndTests.csproj
Outdated
Show resolved
Hide resolved
test/OpenApiNSwagEndToEndTests/ModelValidation/ModelValidationTests.cs
Outdated
Show resolved
Hide resolved
test/OpenApiNSwagEndToEndTests/ModelValidation/ModelValidationTests.cs
Outdated
Show resolved
Hide resolved
test/OpenApiNSwagEndToEndTests/ModelValidation/ModelValidationTests.cs
Outdated
Show resolved
Hide resolved
bkoelman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments. The test coverage needs adjustment, based on the table (that isn't finished yet). I would expect to see some net80-only tests too.
test/OpenApiNSwagEndToEndTests/ModelStateValidation/ModelStateValidationTests.cs
Outdated
Show resolved
Hide resolved
test/OpenApiNSwagEndToEndTests/ModelStateValidation/ModelStateValidationTests.cs
Outdated
Show resolved
Hide resolved
test/OpenApiNSwagEndToEndTests/ModelStateValidation/ModelStateValidationTests.cs
Outdated
Show resolved
Hide resolved
test/OpenApiNSwagEndToEndTests/ModelStateValidation/ModelStateValidationTests.cs
Outdated
Show resolved
Hide resolved
test/OpenApiNSwagEndToEndTests/ModelStateValidation/ModelStateValidationTests.cs
Outdated
Show resolved
Hide resolved
test/OpenApiTests/ModelStateValidation/ModelStateValidationTests.cs
Outdated
Show resolved
Hide resolved
test/OpenApiTests/ModelStateValidation/ModelStateValidationTests.cs
Outdated
Show resolved
Hide resolved
test/OpenApiTests/ModelStateValidation/ModelStateValidationTests.cs
Outdated
Show resolved
Hide resolved
test/OpenApiTests/ModelStateValidation/ModelStateValidationTests.cs
Outdated
Show resolved
Hide resolved
|
I'll resume the work in a few days |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not seeing any end-to-end tests for the .NET 8 attributes.
Oh well, I expected to find #if lines, but end-to-end tests can't multi-target so it's .NET 8 only.
test/OpenApiTests/ModelStateValidation/ModelStateValidationFakers.cs
Outdated
Show resolved
Hide resolved
test/OpenApiTests/ModelStateValidation/ModelStateValidationFakers.cs
Outdated
Show resolved
Hide resolved
test/OpenApiTests/ModelStateValidation/ModelStateValidationFakers.cs
Outdated
Show resolved
Hide resolved
test/OpenApiTests/ModelStateValidation/ModelStateValidationFakers.cs
Outdated
Show resolved
Hide resolved
test/OpenApiNSwagEndToEndTests/ModelStateValidation/ModelStateValidationTests.cs
Outdated
Show resolved
Hide resolved
I've mentioned earlier that the goal of writing end-to-end tests is to assess the overall experience our users will face. This doesn't mean we need to write tests for EF Core features in this PR, but we do need to check for oddities and possibly create separate issues to address them, or document things to watch out for. So I disagree that it's out of scope. Otherwise, I wouldn't have added the EF Core column in the first place. |
|
Here is the single SQL statement to create the table CREATE TABLE "SocialMediaAccounts" (
"Id" uuid NOT NULL,
"AlternativeId" uuid,
"FirstName" text,
"LastName" text NOT NULL,
"UserName" character varying(18),
"CreditCard" text,
"Email" text,
"Password" text,
"Phone" text,
"Age" double precision,
"ProfilePicture" text,
"BackgroundPicture" text,
"Tags" text[],
"CountryCode" text,
"Planet" text,
"NextRevalidation" interval,
"ValidatedAt" timestamp with time zone,
"ValidatedAtDate" date,
"ValidatedAtTime" time without time zone,
CONSTRAINT "PK_SocialMediaAccounts" PRIMARY KEY ("Id")
);I've updated the table accordingly. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## openapi #1477 +/- ##
========================================
Coverage 91.30% 91.30%
========================================
Files 396 396
Lines 12834 12834
Branches 2028 2028
========================================
Hits 11718 11718
Misses 725 725
Partials 391 391 ☔ View full report in Codecov by Sentry. |
test/OpenApiTests/ModelStateValidation/ModelStateValidationTests.cs
Outdated
Show resolved
Hide resolved
test/OpenApiTests/ModelStateValidation/ModelStateValidationTests.cs
Outdated
Show resolved
Hide resolved
test/OpenApiKiotaEndToEndTests/ModelStateValidation/UtcDateTimeJsonConverter.cs
Outdated
Show resolved
Hide resolved
test/OpenApiKiotaEndToEndTests/ModelStateValidation/ModelStateValidationTests.cs
Outdated
Show resolved
Hide resolved
test/OpenApiNSwagEndToEndTests/ModelStateValidation/ModelStateValidationTests.cs
Outdated
Show resolved
Hide resolved
test/OpenApiTests/ModelStateValidation/ModelStateValidationTests.cs
Outdated
Show resolved
Hide resolved
test/OpenApiTests/ModelStateValidation/ModelStateValidationTests.cs
Outdated
Show resolved
Hide resolved
test/OpenApiNSwagEndToEndTests/ModelStateValidation/ModelStateValidationTests.cs
Outdated
Show resolved
Hide resolved
bkoelman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work on filling out the feature table.
Please update the following entries, replacing the '?':
- | [ValidateNever] | - | N | N | N |
- | [Remote] | - | N | N | N |
Also, readOnly and writeOnly need to move one column to the right. I've tried adding properties for them, but set-only causes a crash inside Microsoft.AspNetCore.Mvc.ModelBinding.GetMetadataForProperty, so let's forget about them.
I'm working on a PR to support atomic:operations in OpenAPI, which has heavy changes throughout all tests that I don't want to disturb you with. So if feasible, I'd like to get this PR merged first. With some luck, mine will be completed somewhere next week. No pressure, but it would be nice if we can get this one finalized in the next few days.
test/OpenApiKiotaEndToEndTests/ModelStateValidation/ModelStateValidationTests.cs
Outdated
Show resolved
Hide resolved
test/OpenApiKiotaEndToEndTests/ModelStateValidation/ModelStateValidationTests.cs
Outdated
Show resolved
Hide resolved
test/OpenApiKiotaEndToEndTests/ModelStateValidation/ModelStateValidationTests.cs
Outdated
Show resolved
Hide resolved
test/OpenApiKiotaEndToEndTests/ModelStateValidation/ModelStateValidationTests.cs
Outdated
Show resolved
Hide resolved
test/OpenApiKiotaEndToEndTests/ModelStateValidation/ModelStateValidationTests.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Bart Koelman <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've created domaindrivendev/Swashbuckle.AspNetCore#2957 for the missing .NET 8 entries.
test/OpenApiTests/ModelStateValidation/ModelStateValidationTests.cs
Outdated
Show resolved
Hide resolved
test/OpenApiTests/ModelStateValidation/ModelStateValidationTests.cs
Outdated
Show resolved
Hide resolved
test/OpenApiKiotaEndToEndTests/ModelStateValidation/ModelStateValidationTests.cs
Outdated
Show resolved
Hide resolved
test/OpenApiNSwagEndToEndTests/ModelStateValidation/ModelStateValidationTests.cs
Outdated
Show resolved
Hide resolved
…ts.cs Co-authored-by: Bart Koelman <[email protected]>
I used |
bkoelman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments. Not all changes have been applied yet, and unexpected parts got deleted.
I'm not able to access the comment to answer but I could you clarify what you are expecting here. |
Using the dollar sign and putting literal values in there, so it becomes culture-insensitive. |
bkoelman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this is in great shape now!

Closes #1055
[Length]string,ICollectionminLength/maxLength/minItems/maxItems[MinLength]string,ICollectionminLength/minItems[MaxLength]string,ICollectionmaxLength/maxItems[Compare]Equals[Required(AllowEmptyStrings = true)]stringrequired: [][RegularExpression]stringpattern: XXConvert.ToStringis used on the value so could theoretically be used on other types thanstring[StringLength]stringminLength/maxLengthMinimumLengthimplies0.character varyingwith PostgreSQL[CreditCard]or[DataType(DataType.CreditCard)]stringformat: credit-card[EmailAddress]or[DataType(DataType.EmailAddress)]stringformat: email[Base64String]string[Phone]or[DataType(DataType.PhoneNumber)]stringformat: tel[Range]int,double,IComparableminimum,maximum(both inclusive)MinimumIsExclusive,MaximumIsExclusivebut it's not supported by Swashbuckle[Url]stringformat: uri[AllowedValues][DeniedValues][Required]required: [],minLength: 1NOT NULL, has priority over[NotNull][Remote][ValidateNever][DataType(DataType.Currency)]format: currency[DataType(DataType.Date)]format: date[DataType(DataType.DateTime)]format: date-time[DataType(DataType.Duration)]format: duration[DataType(DataType.Html)]format: html[DataType(DataType.ImageUrl)]format: uri[DataType(DataType.MultilineText)]format: multiline[DataType(DataType.Password)]format: password[DataType(DataType.PostalCode)]format: postal-code[DataType(DataType.Time)]format: time[DataType(DataType.Upload)]format: binary[DataType(DataType.Url)]format: uriGuidformat: uuidHashSetuniqueItemsUriformat: uriDateOnlyformat: dateTimeOnlyformat: timemultipleOfhostnameminItems,maxItemsipv4,ipv6get;readOnlyset;writeOnlyLegend:
QUALITY CHECKLIST