Skip to content

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

@WretchedDade

Description

@WretchedDade

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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-commandlinetoolsIncludes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPIfeature-openapihelp wantedUp for grabs. We would accept a PR to help resolve this issue

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions