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

Fix issues with swagger publishing #153

Open
wants to merge 1 commit into
base: master
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 ApiDocs.Publishing/Swagger/SwaggerClasses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ internal class SwaggerMethod
[JsonProperty("responses", NullValueHandling=NullValueHandling.Ignore)]
public Dictionary<string, SwaggerResponse> Responses { get; set; }

[JsonProperty("operationId")]
public string OperationId { get; internal set; }

public SwaggerMethod()
{
this.Parameters = new List<SwaggerParameter>();
Expand Down
5 changes: 3 additions & 2 deletions ApiDocs.Publishing/Swagger/SwaggerExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ internal static string ToSwaggerTypeString(this SimpleDataType type, string cust
case SimpleDataType.Object:
return "object";
case SimpleDataType.Collection:
return "collection";
throw new ArgumentException();
default:
return type.ToString().ToLower();
Expand Down Expand Up @@ -137,7 +138,7 @@ internal static SwaggerParameter ToSwaggerParameter(this ParameterDefinition par
SwaggerParameter p = new SwaggerParameter()
{
Name = parameter.Name,
Required = parameter.Required.Value,
Required = parameter.Required.HasValue ? parameter.Required.Value : false,
Type = parameter.Type.ToSwaggerTypeString(),
Description = parameter.Description
};
Expand Down Expand Up @@ -171,7 +172,7 @@ internal static SwaggerParameter ToSwaggerParameter(this ParameterDefinition par
/// <param name="method">Method.</param>
internal static SwaggerMethod ToSwaggerMethod(this MethodDefinition method)
{
var output = new SwaggerMethod { Summary = method.Title };
var output = new SwaggerMethod { Summary = method.Title, OperationId = Guid.NewGuid().ToString() };

if (!string.IsNullOrEmpty(method.Description))
output.Description = method.Description;
Expand Down
9 changes: 8 additions & 1 deletion ApiDocs.Publishing/Swagger/SwaggerWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,17 @@ private object BuildSecurityDefinition()
{
var foundScopes = this.Documents.AuthScopes;

Dictionary<string, string> authScopes = new Dictionary<string, string>();
foreach(var scope in foundScopes)
{
authScopes[scope.Scope] = scope.Description;
}

return new Dictionary<string, object> {
{
this.AuthenticationParameters.ProviderName, new {
type = this.AuthenticationParameters.AuthType,
scopes = foundScopes.ToDictionary(x => x.Scope, x => x.Description),
scopes = authScopes,
flow = this.AuthenticationParameters.OAuthFlow,
authorizationUrl = this.AuthenticationParameters.AuthorizationEndPoint
}}};
Expand Down Expand Up @@ -279,6 +285,7 @@ private IDictionary<string, IDictionary<string, SwaggerMethod>> GeneratePathsFro

// Make sure any query string parameters on this method are included in the existing definition
var missingQueryParameters = method.MissingRequestParameters(true);
if (existing.Parameters == null) { existing.Parameters = new List<Swagger.SwaggerParameter>(); };
existing.Parameters.AddRange(from qp in missingQueryParameters select qp.ToSwaggerParameter());
}
}
Expand Down