autorest icon indicating copy to clipboard operation
autorest copied to clipboard

Support parameterized host names using an extension

Open markcowl opened this issue 10 years ago • 2 comments

Add an extension:

x-ms-parameterized-host to the base swagger element in the swagger doc

XMSParameterizedHostSchema: {
  "type": "object",
  "required": ["hostTemplate", "parameters"],
  "properties": {
        "hostTemplate": "string",
        "parameters": {
            "type": "array",
            "items": {
               "type":"object",
                "required": ["name", "description"],
                "properties": {
                     "name": "string",
                     "description": "string"
                 }
            }
      }
  }
}

for example:

x-ms-parameterized-host: {
  "hostTemplate": "{accountName}.contoso.com",
   "parameters": [{"name":"accountName", "description":"The account id for your contoso account."}]

This extension would add a parameterized baseUri to each method, with the specified parameters added as string parameters, with the specified description documentation. The parameters would be substituted in the parameterized host template by name, and the resulting string would be used as the host portion of the URI for the request

markcowl avatar Feb 02 '16 02:02 markcowl

:+1: This is a must-have for multi-tenant services.

One thing that would make this more useful is the ability to take host name as a constructor parameter of the client instead of making it a parameter of every operation. In the case of Azure Search for example, one tenant == one customer == one hostname, so that customer's application will always have the same value for hostname. It would be pointless to pass it around everywhere when it can just be part of the client.

For examples of how Azure Search handles this scenario, see our custom code for SearchIndexClient and SearchServiceClient.

bitsforthought avatar Feb 02 '16 18:02 bitsforthought

  • [ ] Update swagger modeler to handle the new extension
  • [ ] Update client model if necessary
  • [ ] Implement changes in C# and add tests
  • [ ] Implement changes in NodeJS and add tests
  • [ ] Implement changes in Java and add tests
  • [ ] Implement changes in Python and add tests
  • [ ] Implement changes in Ruby and add tests
  • [ ] Update schema
  • [ ] Update documentation

stankovski avatar Feb 02 '16 18:02 stankovski