autorest icon indicating copy to clipboard operation
autorest copied to clipboard

Feature request: ability to mark property as required but only when creating resource

Open jaredmoo opened this issue 9 years ago • 4 comments

The resource type “Microsoft.Sql/servers” has 2 properties, “administratorLogin” and “administratorLoginPassword” which are required properties for PUT when creating the server, but optional for PUT when updating the server. (I understand that this may be considered questionable from pure REST point of view, but we have no plans to change this in the future.)

Since there’s no way to represent this in Swagger, we have to do manual tweaks to both Azure CLI create commands and RP schemas. It would be lovely if there was some way to do this in Swagger so that we can eliminate these manual edits.

jaredmoo avatar Jun 21 '17 17:06 jaredmoo

Just for clarification: The server type is used in this PUT operation "CreateOrUpdate". So regardless of how we would realize different treatment of the type: In order to enable any different treatment between "creating the server" and "updating the server", one would have to split this method up. All artifacts generated from the Swagger will generate a single method and see no distinction between creating and updating and hence no way to determine which treatment to apply. Are you implying that you would like to:

a) split the method into two in the Swagger definition? b) expect generators to split one Swagger operation into two using some x-ms magic? c) keep generating a single method but add a parameter to distinguish between create and update (ewww)?

All those changes are breaking (and slightly deviate from ARM guidelines as far as I can tell), so we should be on the same page of what the long term plan is before starting to think about how to express and implement all this. 🙂 Assuming there was a way to express this in Swagger, what exactly should we generate for which language?

olydis avatar Jun 21 '17 18:06 olydis

The main reason this comes up is that I want to avoid manual changes to RP schemas. These properties are required for create, so I want them to be marked as required in the RP schema.

I'm making the assumption that ARM templates are mainly used for creating resources, although I just remembered it may be possible to also use ARM templates to update resources. @TianoMS , @rjmax , can you correct me here? If the ARM template must be usable for update, then we should NOT mark the properties required and this issue can be closed.

My original thinking was something like (b) where both a Create and CreateOrUpdate method may be generated.

jaredmoo avatar Jun 21 '17 18:06 jaredmoo

@jaredmoo All resources in ARM template are considered as a PUT on the resource.

TianoMS avatar Jun 21 '17 18:06 TianoMS

Ok, if updating with template is an important scenario then we should not do this. It's easy enough to manually make params required in CLI, so I have no scenario where this would be useful. Issue can be closed if nobody objects.

jaredmoo avatar Jun 23 '17 03:06 jaredmoo