Azure / autorest.csharp

Extension for AutoRest (https://github.com/Azure/autorest) that generates C# code
MIT License
142 stars 166 forks source link

Initialize method generated does not understand Relative URL and throws exception (Csharp) #162

Open JasonSmyr opened 6 years ago

JasonSmyr commented 6 years ago

When generating from a swagger document that uses a relative URL for host, the initialize sets the base URL without saying that it should be UriKind.Relative or possibly UriKind.RelativeOrAbsolute

This causes an exception ""Invalid URI: The format of the URI could not be determined."

private void Initialize() { BaseUri = new System.Uri("/monarch/mapping"); .. }

should be:

private void Initialize() { BaseUri = new System.Uri("/monarch/mapping",UriKind.RelativeOrAbsolute); .. }

fix https://github.com/Azure/autorest/issues/2746 seems to be linked to this as does https://github.com/Azure/autorest.modeler/pull/40 by @olydis

deka commented 6 years ago

Is there a workaround with autorest directives ?

JasonSmyr commented 6 years ago

Is there a workaround with autorest directives ?

I have not figured out one if there is , currently we manually change the code and have a unit test to check incase we forget

kgreed commented 5 years ago

This issue is causing us some pain too.

deka commented 5 years ago

https://github.com/Azure/autorest/blob/master/docs/user/literate-file-formats/configuration.md A workaround with "directives" :

Remove BaseUri in Initialize method

JasonSmyr commented 5 years ago

I guess that is a fix.. seems that code gen just needs to use UriKind.RelativeOrAbsolute and all would be covered

kgreed commented 5 years ago

@deka that link does not seem to work.

deka commented 5 years ago

@deka that link does not seem to work. https://github.com/Azure/autorest/wiki/How-Do-I... https://github.com/Azure/autorest/blob/master/docs/proposals/generator-specific-settings/literate-configuration.md

jornhd commented 5 years ago

Over a year and still no fix? I have to manually edit this every time I update API clients.

dan-olsen commented 3 years ago

Is there any update on this. We are experiencing the same issue and the given directive workaround is not working.