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

Added author , owner and description to NuGet generation #160

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/generating/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ yardarm generate -i my-spec.yaml -n MySpec -v 1.0.0 -f net6.0 -o output/director
# Generate a NuGet package and symbols package, with System.Text.Json and DI support targeting net6.0 and netstandard2.0
yardarm generate -i my-spec.json -n MySpec -v 1.0.0 -f net6.0 netstandard2.0 --nupkg output/directory/ -x Yardarm.SystemTextJson Yardarm.MicrosoftExtensionsHttp

# Generate a NuGet package and symbols package, with Newtonsoft.Json and DI support targeting net6.0 with author name, owner and description
yardarm generate -i my-spec.json -n MySpec -v 1.0.0 -f net6.0 --author "Some Name Here" --owner "Some Owner Here" --description "Some description here" --nupkg output/directory/ -x Yardarm.NewtonsoftJson Yardarm.MicrosoftExtensionsHttp

# Note the trailing slash on the output directory. If there is no trailing slash, it is assumed to be a DLL or nupkg file name.
# Related files will be output beside that file.
```
Expand Down
4 changes: 4 additions & 0 deletions src/main/Yardarm.CommandLine/GenerateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ protected override void ApplyNuGetSettings(YardarmGenerationSettings settings)
new RepositoryMetadata(_options.RepositoryType, _options.RepositoryUrl, _options.RepositoryBranch,
_options.RepositoryCommit);
}

settings.Author = _options.Author;
settings.Description= _options.Description;
settings.Owner = _options.Owner;
}

// Holds a temporary file which will eventually be persisted to a final file.
Expand Down
9 changes: 9 additions & 0 deletions src/main/Yardarm.CommandLine/GenerateOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ public class GenerateOptions : CommonOptions

#region NuGet

[Option("author", HelpText = "Author to show for the .nupkg/.snupkg package file", SetName = "nuget")]
public string Author { get; set; }

[Option("owner", HelpText = "Owner to show for the .nupkg/.snupkg package file", SetName = "nuget")]
public string Owner { get; set; }

[Option("description", HelpText = "Description to show for the .nupkg/.snupkg package file", SetName = "nuget")]
public string Description { get; set; }

[Option("nupkg", HelpText = "Output directory or .nupkg package file. Indicate a directory with a trailing slash.", SetName = "nuget")]
public string OutputPackageFile { get; set; }

Expand Down
10 changes: 9 additions & 1 deletion src/main/Yardarm/Generation/Tag/TagTypeGeneratorBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.OpenApi.Models;
Expand Down Expand Up @@ -29,6 +30,13 @@ protected virtual IEnumerable<MethodDeclarationSyntax> GenerateOperationMethodHe
string methodName = Context.NameFormatterSelector.GetFormatter(NameKind.AsyncMethod)
.Format(operation.Element.OperationId);

// This is here to show a useful error that there is an error with the Spec provided. If the operation
// is missing the name attribute in the OpenAPI spec, the MethodDeclaration step will fail
if (string.IsNullOrEmpty(methodName))
{
throw new NullReferenceException($"{nameof(GenerateOperationMethodHeader)} ran into an error. Please ensure the method at the path {operation.Key} {operation} is decorated correctly with the OperationId present.");
}

Comment on lines +33 to +39
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's actually a separate issue already open to address this problem, I'd prefer to leave it off this PR for the sake of the separation of issues.

Suggested change
// This is here to show a useful error that there is an error with the Spec provided. If the operation
// is missing the name attribute in the OpenAPI spec, the MethodDeclaration step will fail
if (string.IsNullOrEmpty(methodName))
{
throw new NullReferenceException($"{nameof(GenerateOperationMethodHeader)} ran into an error. Please ensure the method at the path {operation.Key} {operation} is decorated correctly with the OperationId present.");
}

var methodDeclaration = MethodDeclaration(responseType, methodName)
.AddElementAnnotation(operation, Context.ElementRegistry)
.AddParameterListParameters(
Expand Down
8 changes: 5 additions & 3 deletions src/main/Yardarm/Packaging/NuGetPacker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ public void Pack(IList<YardarmCompilationResult> compilationResults, Stream nuge
Version = new NuGetVersion(_settings.Version,
_settings.VersionSuffix?.TrimStart('-').Split(new[] {'.'}, StringSplitOptions.RemoveEmptyEntries),
null, null),
Description = _settings.AssemblyName,
Description = _settings.Description ?? _settings.AssemblyName,
Summary = _document.Info.Description,
Authors = {_settings.Author},
Owners = {_settings.Owner},
Repository = _settings.Repository
};

Expand Down Expand Up @@ -88,9 +89,10 @@ public void PackSymbols(IList<YardarmCompilationResult> compilationResults, Stre
{
PackageType.SymbolsPackage
},
Description = _settings.AssemblyName,
Description = _settings.Description ?? _settings.AssemblyName,
Summary = _document.Info.Description,
Authors = { _settings.Author }
Authors = {_settings.Author},
Owners = {_settings.Owner},
};

builder.Files.AddRange(compilationResults
Expand Down
2 changes: 2 additions & 0 deletions src/main/Yardarm/YardarmGenerationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class YardarmGenerationSettings
public Version Version { get; set; } = new Version(1, 0, 0);
public string? VersionSuffix { get; set; }
public string Author { get; set; } = "anonymous";
public string Owner { get; set; } = "anonymous";
public string Description { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one needs a nullable annotation.

Suggested change
public string Description { get; set; }
public string? Description { get; set; }

public RepositoryMetadata? Repository { get; set; }

/// <summary>
Expand Down