RicoSuter/NSwag · error · ArgumentException
The argument 'Input' was empty.
Error message
The argument 'Input' was empty.
What it means
GetInputSwaggerDocument resolves the Swagger/OpenAPI document to process. When no document was loaded in memory, it falls back to the Input property; if that string is null or empty, it throws ArgumentException. It simply means no input document (URL, file path, or inline JSON) was supplied.
Solutions
- Pass an explicit input: a swagger file path, an http(s) URL, or inline JSON via the Input property (/input:...).
- If input comes from a variable/config, validate it is non-empty before invoking NSwag.
- Check shell quoting — an argument swallowed by quotes/whitespace can collapse to an empty value.
- If the document should come from runtime generation (aspnetcore/webapi), use the matching command rather than a document-input command.
Example fix
// before nswag openapi2csclient /output:ApiClient.cs // after nswag openapi2csclient /input:swagger.json /output:ApiClient.cs
Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrWhiteSpace(input) && document == null)
throw new ArgumentException("Provide /input as a swagger file path, URL, or inline JSON before running the command."); Try / catch
try { await command.GetInputSwaggerDocumentAsync(); }
catch (ArgumentException ex) when (ex.Message.Contains("argument 'Input' was empty")) { Console.Error.WriteLine("Missing --input: pass a file path, URL, or inline JSON."); } Prevention
- Always include /input:... when calling document-based commands
- In scripts, expand and check variables before invoking NSwag
- Use quoted absolute paths to avoid shell splitting issues
- Prefer .nswag config files checked into the repo so inputs are explicit
When it happens
Trigger: Calling a command (e.g. openapi2csclient, webapi2openapi with /output) without setting the Input argument — e.g. `nswag openapi2csclient /output:Client.cs` with no /input, or programmatically creating a command and never assigning Input.
Common situations: Omitting /input on the command line; referencing a settings file that doesn't set the input variable; empty environment-variable expansion like /input:%SWAGGER_URL% resolving to nothing; calling the NSwag.Commands API in code with defaults.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- Could not retrieve command from arguments
- The specified runtime in the document
- Project outputs could not be located in
- The ouput of is a 32-bit application and requires…
- The ouput of is a 64-bit application and requires…
AI-assisted analysis of RicoSuter/NSwag@63daf8fcc3 (2026-09-14).
Data as JSON: /api/errors/e871c7d04c1c4cf3.
Report an issue: GitHub.
Appendix: source
Thrown at src/NSwag.Commands/Commands/InputOutputCommandBase.cs:39
public object Input { get; set; }
[Argument(Name = "ServiceHost", IsRequired = false, Description = "Overrides the service host of the web document (optional, use '.' to remove the hostname).")]
public string ServiceHost { get; set; }
[Argument(Name = "ServiceSchemes", IsRequired = false, Description = "Overrides the allowed schemes of the web service (optional, comma separated, 'http', 'https', 'ws', 'wss').")]
public string[] ServiceSchemes { get; set; }
/// <exception cref="ArgumentException">The argument 'Input' was empty.</exception>
protected async Task<OpenApiDocument> GetInputSwaggerDocument()
{
var document = Input as OpenApiDocument;
if (document == null)
{
var input = Input.ToString();
if (string.IsNullOrEmpty(input))
{
throw new ArgumentException("The argument 'Input' was empty.");
}
document = await ReadSwaggerDocumentAsync(input);
}
if (ServiceHost == ".")
{
document.Host = string.Empty;
document.Schemes.Clear();
}
else
{
if (!string.IsNullOrEmpty(ServiceHost))
{
document.Host = ServiceHost;
}
if (ServiceSchemes != null && ServiceSchemes.Length > 0)View on GitHub (pinned to 63daf8fcc3)