Skip to content
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

--document-name flag not being respected when generating open api documents at build time. #59097

Open
WretchedDade opened this issue Nov 21, 2024 · 0 comments
Labels
area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI feature-openapi

Comments

@WretchedDade
Copy link

I was trying to follow the example in this guide on learn for generating documents at build time. It indicates there that you can use the --document-name flag to only generate the document matching the given name. However, I noticed that no matter what value I passed, all of my documents were being generated.

I dug into the code and found the lines where this flag was being consumed. I even saw a comment indicating "If an explicit document name is provided, then generate only that document.". Notably though, I didn't see any code that actually did this restriction prior to the logic iterating over all documents and generating them.

// If an explicit document name is provided, then generate only that document.
var documentNames = (IEnumerable<string>)InvokeMethod(getDocumentsMethod, service, _getDocumentsArguments);
if (documentNames == null)
{
return false;
}
if (!string.IsNullOrEmpty(_context.DocumentName) && !documentNames.Contains(_context.DocumentName))
{
_reporter.WriteError(Resources.FormatDocumentNotFound(_context.DocumentName));
return false;
}
if (!string.IsNullOrWhiteSpace(_context.FileName) && !Regex.IsMatch(_context.FileName, "^([A-Za-z0-9-_]+)$"))
{
_reporter.WriteError(Resources.FileNameFormatInvalid);
return false;
}
// Write out the documents.
var found = false;
Directory.CreateDirectory(_context.OutputDirectory);
var filePathList = new List<string>();
foreach (var documentName in documentNames)
{
var filePath = GetDocument(
documentName,
_context.ProjectName,
_context.OutputDirectory,
generateMethod,
service,
generateWithVersionMethod,
_context.FileName);
if (filePath == null)
{
return false;
}
filePathList.Add(filePath);
found = true;
}

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Nov 21, 2024
@martincostello martincostello added area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI feature-openapi and removed area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates labels Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI feature-openapi
Projects
None yet
Development

No branches or pull requests

2 participants