Open AndreyYurashevich opened 3 years ago
Why don't you let the generated client do it stuff, and provide a BaseUrl
at client init ? The host name often needs to be set anyway.
@jeremyVignelles, I have loads of client classes with lots of places they are constructed, so it's nice to have a single place where baseUrl can be set. That may seem weird but I really don't need to set host (current origin is used in every environment) during the client generation but I need path prefix to be consistent. There aren't options to do precisely that in the configuration, but serviceHost
option does what I need.
The only caveat is that if a path prefix appears in the serviceHost
value of one of the code generators then it gets used in consequent code generators too even if they don't provide any serviceHost
value or provide "*" value to reset the host.
I admit it isn't an NSwag really an NSwag issue as I rely on undocumented behavior, but I'm mostly curious if it's possible to have an option for path prefix in code generators that can be set on a code-generator basis?
You could overwrite the template (however not really recommended as you lose/have to maintain changes yourself)?
Actually, since my issue is caused by sharing the same OpenAPI document between multiple code generators the simplest workaround is to split config into two separate configs and invoke nswag executable multiple times. Feel free to close the issue unless you think you could add the path prefix option.
I have a non-trivial configuration with two code generators: for C# and TS. C# clients don't require any pre-set baseUrl but TS requires some URL prefix like
/test-prefix
. I admit that this is not quite expected usage of serviceHost value but here is the config I use:It produces the expected result for TS, but example C# client looks like this:
My guess is that once OpenApiDocument.BaseValue property gets some value it can not be cleared later by manipulating Host and ServiceShemes. Given that OpenApiDocument gets shared between code generators this leads to unexpected BaseUrl value during second code generator invocation.