{"record":{"id":"09f4774da57765c5","repo":"RicoSuter/NSwag","slug":"the-parameter-name-is-required","errorCode":null,"errorMessage":"The parameter '\" + Name + \"' is required.","messagePattern":"The parameter '\" \\+ Name \\+ \"' is required\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/NSwag.Commands/NConsole/ArgumentAttribute.cs","lineNumber":71,"sourceCode":"            {\n                return ArgumentAttributeBase.ConvertToType(value, property.PropertyType);\n            }\n                \n            if (AcceptsCommandInput && input != null)\n                return input;\n\n            if (!ArgumentAttribute.IsInteractiveMode(args) && !IsRequired)\n                return property.CanRead ? property.GetValue(command) : null;\n\n            if (ShowPrompt)\n            {\n                value = consoleHost.ReadValue(GetFullParameterDescription(property, command));\n                if (value == \"[default]\")\n                {\n                    if (!IsRequired)\n                        return property.CanRead ? property.GetValue(command) : null;\n\n                    throw new InvalidOperationException(\"The parameter '\" + Name + \"' is required.\");\n                }\n\n                return ArgumentAttributeBase.ConvertToType(value, property.PropertyType);\n            }\n            else\n                return property.CanRead ? property.GetValue(command) : null;\n        }\n\n        private static bool IsInteractiveMode(string[] args)\n        {\n            return args.Length == 0;\n        }\n\n        private bool TryGetPositionalArgumentValue(string[] args, ref string used, out string value)\n        {\n            if (Position > 0 && Position < args.Length)\n            {\n                value = args[Position];","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/RicoSuter/NSwag/blob/63daf8fcc3a25151b62eb4b326a1e8ea048a0d41/src/NSwag.Commands/NConsole/ArgumentAttribute.cs#L53-L89","documentation":"When a required argument's value is missing on the command line, NConsole prompts interactively via consoleHost.ReadValue. If the user (or a non-interactive host) answers '[default]', the attribute falls back to the property's current value — but when IsRequired is true there is no acceptable default, so it throws InvalidOperationException naming the required parameter.","triggerScenarios":"Running a command without a required argument while IsRequired = true on its [Argument] attribute, and the interactive prompt returns '[default]' (e.g. piped/redirected stdin, CI with no TTY supplying the default sentinel) so no real value is captured.","commonSituations":"Forgetting /input or /output style required options in scripts; running NSwag in CI where interactive prompts read an empty/auto-answered stdin; marked IsRequired but never supplying the value in an .nswag variables section.","solutions":["Provide the required argument explicitly on the command line (/name:value) so no prompt occurs.","If the argument should have a fallback, set IsRequired = false and supply a default property value in the command class.","In non-interactive environments, feed the value via stdin/variables instead of relying on the prompt.","Check the .nswag/CI config that the variable mapped to this argument isn't empty."],"exampleFix":"// before\nnswag openapi2csclient /output:Client.cs   // input prompted, [default] answered\n\n// after\nnswag openapi2csclient /input:swagger.json /output:Client.cs","handlingStrategy":"validation","validationCode":"var missing = requiredArgs.Where(a => !CommandLineArgs.ContainsKey(a)).ToList();\nif (missing.Any())\n    throw new ArgumentException($\"Missing required arguments: {string.Join(\", \", missing)}. Supply them on the command line; do not rely on interactive prompts.\");","typeGuard":null,"tryCatchPattern":"try { result = processor.Process(args); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"is required\")) { Console.Error.WriteLine($\"Supply the missing option: {ex.Message}\"); Environment.Exit(2); }","preventionTips":["Always pass required options explicitly in scripts/CI — never rely on the interactive prompt","Run non-interactive CI with all arguments supplied via stdin or flags","Mark IsRequired = false only when a real default exists on the property","Validate required inputs in your wrapper script before invoking NSwag"],"tags":["cli-parsing","required-argument","interactive-prompt"],"backgroundTag":"missing-required-argument","analyzedSha":"63daf8fcc3a25151b62eb4b326a1e8ea048a0d41","analyzedAt":"2026-09-14T11:38:15.205Z","contentChangedAt":"2026-09-14T11:38:15.205Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}