-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add credentials and mode attributes to fetch template generation #5235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add credentials and mode attributes to fetch template generation #5235
Conversation
|
You can mark a PR as a draft so it won't be accidentally merged. |
|
Please add at least one test case that enables this option and does both |
| credentials: 'include', | ||
| {%- endif -%} | ||
| {%- if UseCorsMode -%} | ||
| mode: 'cors', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because there are four possible values: https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#mode should this be an enum on settings side? I don't know about other clients if they support same options, but then it would be public enum CorsMode or FetchCorsMode with default of None, client template model could have Mode property which would map enum to string version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the same applies to Credientials too, it has other options which would then be hard to set if it's hard-coded to include if credentials is set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I can change to be an enum that I assume would be nullable so people don't have to have it set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well if it defaults to default of first value None I think there would be no need to set it? I have no strong opinions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lahma is there a way to use an enum equivalence check in the liquid files? I don't see any existing examples. I'm not sure what code options I have versus if I use a boolean I see prior art for me to do an if check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Short of me just creating a unique boolean for each different enum option in NSwag.CodeGeneration.TypeScript\Models\TypeScriptClientTemplateModel.cs. Which feels hacky but would be relatively easy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just add a string property that returns correct value, null should evaluate to false in if check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good call. Thanks
|
Checked the PR and spec, some notes:
Now it remains a question whether it needs to be rendered in the JS file if it is the default - your current logic incorrectly returns empty string, like I said, null needs to be returned. |
|
I was thinking about having no NotSet but then it'd change a bunch of people's client files unnecessarily. I would generally say I'd want it to not appear in people's file and therefore I'd need to do one of two things
|
I think the NotSet will be the value if you save the nswag.json using NSwagStudio for example, so the property will pesisted there, if you don't want it to appear then it probably needs JsonProperty attribute to ignore the default value. |
|
@etriebe do you have time/plans to fix the current test problems? 🙏🏻 |
|
Let me take a look. My development desktop died the other week so it's been a minute to get setup and configured again. |
|
@lahma I am running locally and even just running for one of my tests I see the following and it spins for a very long time. Is there some sort of setup I need to do to make this work? ========== Starting test run ========== |
Haven't seen this before, might be related to your reset setup? |
|
I think tsc is failing to install for me and/or it isn't on my path variable. How do you install tsc? |
|
Try running build.cmd in repository root. |
|
When I run build.cmd it fails and says it can't find msbuild. And I have VS 2022 installed. |
|
I had previously just installed .NET 9 SDK but installing .NET 8 SDK allowed this to run, too. |
|
OK tests are passing locally now. @lahma Can you approve to run them here? |
lahma
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great addition, thanks for iterating! As a later improvement, we probably want these also in NSwagStudio and nswag.json.
Haven't tested yet but just attempting to get this started.