{"action":"created","issue":{"url":"https://api.github.com/repos/Azure/autorest/issues/2875","repository_url":"https://api.github.com/repos/Azure/autorest","labels_url":"https://api.github.com/repos/Azure/autorest/issues/2875/labels{/name}","comments_url":"https://api.github.com/repos/Azure/autorest/issues/2875/comments","events_url":"https://api.github.com/repos/Azure/autorest/issues/2875/events","html_url":"https://github.com/Azure/autorest/issues/2875","id":308704772,"number":2875,"title":"C# code generation error when using global parameters with top level operations","user":{"login":"natinimni","id":26612043,"avatar_url":"https://avatars3.githubusercontent.com/u/26612043?v=4","gravatar_id":"","url":"https://api.github.com/users/natinimni","html_url":"https://github.com/natinimni","followers_url":"https://api.github.com/users/natinimni/followers","following_url":"https://api.github.com/users/natinimni/following{/other_user}","gists_url":"https://api.github.com/users/natinimni/gists{/gist_id}","starred_url":"https://api.github.com/users/natinimni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/natinimni/subscriptions","organizations_url":"https://api.github.com/users/natinimni/orgs","repos_url":"https://api.github.com/users/natinimni/repos","events_url":"https://api.github.com/users/natinimni/events{/privacy}","received_events_url":"https://api.github.com/users/natinimni/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-03-26T19:29:58Z","updated_at":"2018-03-26T19:48:16Z","closed_at":null,"author_association":"NONE","body":"AutoRest creates a non-compiling C# code when defining a swagger with global parameter and top\\client level operation. \r\n\r\nConsider the following swagger:\r\n~~~{\r\n  \"swagger\": \"2.0\",\r\n  \"info\": {\r\n    \"title\": \"FooBarClient\",\r\n    \"version\": \"2016-09-01-Preview\"\r\n  },\r\n  \"x-ms-parameterized-host\": {\r\n    \"parameters\": [\r\n      {\r\n        \"$ref\": \"#/parameters/SomeParameter\"\r\n      }\r\n    ]\r\n  },\r\n  \"consumes\": [\"application/json\"],\r\n  \"produces\": [\"application/json\"],\r\n  \"paths\": {\r\n    \"/bar\": {\r\n      \"get\": {\r\n        \"operationId\": \"Bar\",\r\n        \"responses\": {\"200\": {\"description\": \"\"}}\r\n      }\r\n    },\r\n    \"/foo\": {\r\n      \"get\": {\r\n        \"operationId\": \"Foo_Get\",\r\n        \"responses\": {\"200\": {\"description\": \"\"}}\r\n      }\r\n    }\r\n    \r\n  },\r\n  \"parameters\": {\r\n    \"SomeParameter\": {\r\n      \"name\": \"someParameter\",\r\n      \"in\": \"path\",\r\n      \"required\": true,\r\n      \"type\": \"string\",\r\n      \"x-ms-parameter-location\": \"client\"\r\n    }\r\n  }\r\n}\r\n~~~\r\nWhile the generated C# code for \"FooOperations\" access 'SomeParameter' correctly using 'Client': \r\n~~~\r\n    internal partial class FooOperations : IServiceOperations<FooBarClient>, IFooOperations\r\n    {\r\n        public FooBarClient Client { get; private set; }\r\npublic async Task<AzureOperationResponse> GetWithHttpMessagesAsync(Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))\r\n        {\r\n            if (Client.SomeParameter == null)\r\n            {\r\n                throw new ValidationException(ValidationRules.CannotBeNull, \"this.Client.SomeParameter\");\r\n            }\r\n            . . .\r\n        }\r\n    }\r\n~~~\r\nBut the generated \"FooBarClient\" code wrongly tries to access 'SomeParameter' in the same way, using 'Client', instead of accessing it using 'this':\r\n~~~\r\n    public partial class FooBarClient : ServiceClient<FooBarClient>, IFooBarClient, IAzureClient\r\n    {\r\n        public string SomeParameter { get; set; }\r\n\r\n        public virtual IFooOperations Foo { get; private set; }\r\n\r\n        public async Task<AzureOperationResponse> BarWithHttpMessagesAsync(Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))\r\n        {\r\n            if (this.Client.SomeParameter == null)\r\n            {\r\n                throw new ValidationException(ValidationRules.CannotBeNull, \"this.Client.SomeParameter\");\r\n            }\r\n            . . .\r\n         }\r\n    }\r\n~~~\r\n\r\nThis is of course a compilation error. \r\nFurthermore, the generated code seems to be affected by the order of the operations in the swagger file - changing the order of 'foo' and  'bar' in the swagger, results in both FooBarClient and FooOperations accessing SomeParameter using 'this' (and not 'Client') - changing the compilation error to the FooOperations class.\r\n\r\nNote that when defining **only** top-level operations, this works well.\r\nAm I doing something wrong here? "},"comment":{"url":"https://api.github.com/repos/Azure/autorest/issues/comments/376289159","html_url":"https://github.com/Azure/autorest/issues/2875#issuecomment-376289159","issue_url":"https://api.github.com/repos/Azure/autorest/issues/2875","id":376289159,"user":{"login":"fearthecowboy","id":133736,"avatar_url":"https://avatars3.githubusercontent.com/u/133736?v=4","gravatar_id":"","url":"https://api.github.com/users/fearthecowboy","html_url":"https://github.com/fearthecowboy","followers_url":"https://api.github.com/users/fearthecowboy/followers","following_url":"https://api.github.com/users/fearthecowboy/following{/other_user}","gists_url":"https://api.github.com/users/fearthecowboy/gists{/gist_id}","starred_url":"https://api.github.com/users/fearthecowboy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fearthecowboy/subscriptions","organizations_url":"https://api.github.com/users/fearthecowboy/orgs","repos_url":"https://api.github.com/users/fearthecowboy/repos","events_url":"https://api.github.com/users/fearthecowboy/events{/privacy}","received_events_url":"https://api.github.com/users/fearthecowboy/received_events","type":"User","site_admin":false},"created_at":"2018-03-26T19:48:16Z","updated_at":"2018-03-26T19:48:16Z","author_association":"MEMBER","body":"O_o \r\n\r\nIt definitely looks like you've found a glitch here.  I'm thinking it's related to `x-ms-parameterized-host`. \r\n\r\nWorse, I know there are some weird bits in there that how something is used first, affected how it emitted code on subsequent use.  Pretty much every time it has to say `this.Client` it's a ratsnest in those templates. \r\n\r\n\r\n"}}
{"actor":{"display_login":"fearthecowboy"}}