Skip to content

Generating code for an OpenAPI Service Reference fails if the path to the swagger file has spaces in it. #45926

@vsfeedback

Description

@vsfeedback

This issue has been moved from a ticket on Developer Community.


[severity:It's more difficult to complete my work]
If you attempt to generate an OpenAPI Service Reference when the path to the swagger.json has spaces in it, it will fail to generate the C# code. This is because the path to the swagger.json file is not escaped, so if you have a swagger.json file at "C:\path with spaces\swagger.json", this will run the command "path\to\nswag.exe" /input:C:\path with spaces\swagger.json /output:obj/swagger.cs, which will be interpreted by NSwag as /input:C:\path. Manually copying the command and running it with quotation marks around the input command allows the build to succeed.


Original Comments

Feedback Bot on 1/4/2023, 07:54 PM:

(private comment, text removed)


Original Solutions

Levi Willrich solved on 1/4/2023, 09:27 AM, 0 votes:

It is possible to manually generate the code file by copying the command from the error list into a text editor, which gives you something like this

Severity	Code	Description	Project	File	Line	Suppression State
Error	MSB3073	The command ""C:\Users\lwillrich\.nuget\packages\nswag.msbuild\13.0.5\build\../tools/Win/NSwag.exe" openapi2csclient /className:WebApi /namespace:<Namespace> /input:E:\Repos\Windows Applications\<solution>\<project>\OpenAPIs\swagger.json /output:obj\swaggerClient.cs " exited with code -1.	<Solution>	C:\Users\lwillrich\.nuget\packages\nswag.apidescription.client\13.0.5\build\NSwag.ApiDescription.Client.targets	28	

From there you can add quotes around the path after /input, copy out the actual command into the command line, and run it.

Metadata

Metadata

Assignees

Labels

Author: Migration Bot 🤖The issue was created by a issue mover bot. The author may not be the actual author.ExternalThis is an issue in a component not contained in this repository. It is open for tracking purposes.feature-openapiold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions