autorest icon indicating copy to clipboard operation
autorest copied to clipboard

AutoRest should provide a way to disable client-side validation

Open bitsforthought opened this issue 9 years ago • 14 comments

A frequent piece of feedback I get when changing a Swagger spec is that I'm not documenting min/max length and regex rules for certain string properties such as resource names. I should do this for documentation purposes, but I don't.

The reason I don't include regex constraints and the like is because AutoRest uses them to generate client-side validation code, which I don't want. It introduces too much coupling between the client and the service and makes versioning more painful for practically zero benefit. I expand more on this line of reasoning in the discussion in this PR.

Client-side validation can make sense in the context of a UI where round-trip time is important and you need to preserve the user's work, but in the context of a library that directly calls a REST API it makes little sense.

bitsforthought avatar Mar 31 '17 23:03 bitsforthought

We use auto generated sdk's for integration testing, the client side validation prevents us from writing a lot negative test cases.

tailo avatar Apr 04 '17 22:04 tailo

@brjohnstmsft @tailo A configuration point to disable client side validation in C# should be in the latest nightly, see https://github.com/olydis/autorest/blob/master/Samples/1d-common-settings/readme.md (specifically client-side-validation: false) for an example. As we will move away from the legacy CLI, I haven't tested the switch there, but if I'm not mistaken it should be usable as -ClientSideValidation false.

Let me know if you have any questions, whether I have missed tying some validation to that flag or if something doesn't work! 🙂

olydis avatar May 03 '17 16:05 olydis

reopening to tag the languages I haven't touched (not even sure if they have client side validation in the first place)

olydis avatar May 03 '17 16:05 olydis

To the language owners I've tagged: Please check whether your language supports client side validation. If so, please imitate C#'s behavior of respecting the flag mentioned above (Settings.Instance.Host.GetValue<bool?>("client-side-validation") should get you the setting wherever you need it). If not, I assume that your customers never requested client side validation in the first place and you're off the hook.

Note that allowing to disable validation was done in C# due to strong customer feedback and the fact that it actually contradicts the Swagger spec (that says that constraints are enforced by the server side). By default, AutoRest core sets this setting to true to maintain backwards compatibility.

olydis avatar Jul 18 '17 17:07 olydis

Now supported on Go

mcardosos avatar Sep 01 '17 20:09 mcardosos

@olydis @fearthecowboy duplicate of https://github.com/Azure/autorest/issues/1583?

lmazuel avatar Sep 28 '17 18:09 lmazuel

lol, indeed, closed the other one since there seems to be more traction on this issue here :D

olydis avatar Sep 28 '17 18:09 olydis

Will be released in autorest.python 2.0.15. Needs msrest >= 0.4.15 to work (will be just ignored if < 0.4.15, will not crash).

lmazuel avatar Oct 03 '17 17:10 lmazuel

With PRs https://github.com/Azure/azure-sdk-for-ruby/pull/1119 and https://github.com/Azure/autorest.ruby/pull/16 Ruby has added conditions that validations will not happen if the client side validation is set to false. Let me know if there is anything else to do on our side

sarangan12 avatar Nov 10 '17 07:11 sarangan12

Also changing the node assignment from @balajikris to @amarzavery

sarangan12 avatar Nov 10 '17 07:11 sarangan12

Any update when this will be done for the typescript version?

shaunnez avatar Aug 12 '18 22:08 shaunnez

@RikkiGibson for TS

lmazuel avatar Aug 13 '18 17:08 lmazuel

tracking in Azure/autorest.typescript#243

RikkiGibson avatar Aug 13 '18 18:08 RikkiGibson

@RikkiGibson any eta for TS?

shabfactor avatar Aug 15 '18 01:08 shabfactor