Skip to content

Commit

Permalink
fixing multiple issues - #44 #42 #41 #37 #26
Browse files Browse the repository at this point in the history
  • Loading branch information
abelsilva committed Oct 29, 2016
1 parent 14ad3ee commit dc4b30c
Show file tree
Hide file tree
Showing 12 changed files with 335 additions and 49 deletions.
4 changes: 4 additions & 0 deletions src/SwaggerWcf.Test.Service/Data/Book.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,9 @@ public class Book
[DataMember]
[Description("Book Language")]
public Language Language { get; set; }

[DataMember]
[Description("Book Tags")]
public string[] Tags { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/SwaggerWcf.Test.Service/IStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface IStore

[SwaggerWcfPath("Create book", "Create a book on the store")]
// default Method for WebInvoke is POST
[WebInvoke(UriTemplate = "/books", BodyStyle = WebMessageBodyStyle.Bare, //Method = "POST",
[WebInvoke(UriTemplate = "/books", BodyStyle = WebMessageBodyStyle.Wrapped, //Method = "POST",
RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
[OperationContract]
Book CreateBook([SwaggerWcfParameter(Description = "Book to be created, the id will be replaced")] Book value);
Expand Down
1 change: 1 addition & 0 deletions src/SwaggerWcf.Test.Service/Store.svc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class BookStore : IStore
{
#region /books
[SwaggerWcfTag("Books")]
[SwaggerWcfHeader("clientId", false, "Client ID", "000")]
[SwaggerWcfResponse(HttpStatusCode.Created, "Book created, value in the response body with id updated")]
[SwaggerWcfResponse(HttpStatusCode.BadRequest, "Bad request", true)]
[SwaggerWcfResponse(HttpStatusCode.InternalServerError,
Expand Down
46 changes: 46 additions & 0 deletions src/SwaggerWcf/Attributes/SwaggerWcfHeaderAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;

namespace SwaggerWcf.Attributes
{
/// <summary>
/// Describe a parameter
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public class SwaggerWcfHeaderAttribute : Attribute
{
/// <summary>
/// Describes a parameter
/// </summary>
/// <param name="name">Parameter name</param>
/// <param name="required">Set parameter as required. Defaults is false.</param>
/// <param name="description">Parameter description.</param>
/// <param name="defaultValue">Parameter default value.</param>
public SwaggerWcfHeaderAttribute(string name, bool required = false, string description = null, string defaultValue = null)
{
Name = name;
Required = required;
Description = description;
DefaultValue = defaultValue;
}

/// <summary>
/// Name of this parameter
/// </summary>
public string Name { get; set; }

/// <summary>
/// Defines if this parameter is required in operations
/// </summary>
public bool Required { get; set; }

/// <summary>
/// Description of this parameter
/// </summary>
public string Description { get; set; }

/// <summary>
/// Default value of this parameter
/// </summary>
public string DefaultValue { get; set; }
}
}
3 changes: 2 additions & 1 deletion src/SwaggerWcf/Models/InType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ internal enum InType
Body = 1,
Path = 2,
Query = 3,
FormData = 4
FormData = 4,
Header = 5
}
}
27 changes: 17 additions & 10 deletions src/SwaggerWcf/Support/DefinitionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace SwaggerWcf.Support
{
internal sealed class DefinitionsBuilder
{
public static List<Definition> Process(IList<string> hiddenTags, List<Type> definitionsTypes)
public static List<Definition> Process(IList<string> hiddenTags, IList<string> visibleTags, List<Type> definitionsTypes)
{
if (definitionsTypes == null || !definitionsTypes.Any())
return new List<Definition>(0);
Expand All @@ -24,7 +24,7 @@ public static List<Definition> Process(IList<string> hiddenTags, List<Type> defi
while (typesStack.Any())
{
Type t = typesStack.Pop();
if (IsHidden(t, hiddenTags) || processedTypes.Contains(t))
if (IsHidden(t, hiddenTags, visibleTags) || processedTypes.Contains(t))
continue;

processedTypes.Add(t);
Expand All @@ -34,18 +34,17 @@ public static List<Definition> Process(IList<string> hiddenTags, List<Type> defi
return definitions;
}

private static bool IsHidden(Type type, IList<string> hiddenTags)
private static bool IsHidden(Type type, ICollection<string> hiddenTags, ICollection<string> visibleTags)
{
if (hiddenTags.Contains(type.FullName))
return true;

if (type.GetCustomAttribute<SwaggerWcfHiddenAttribute>() != null)
return true;

if (type.GetCustomAttributes<SwaggerWcfTagAttribute>().Select(t => t.TagName).Any(hiddenTags.Contains))
return true;
{
return !type.GetCustomAttributes<SwaggerWcfTagAttribute>().Select(t => t.TagName).Any(visibleTags.Contains);
}

return false;
return type.GetCustomAttributes<SwaggerWcfTagAttribute>().Select(t => t.TagName).Any(hiddenTags.Contains);
}

private static Definition ConvertTypeToDefinition(Type definitionType, IList<string> hiddenTags,
Expand Down Expand Up @@ -136,8 +135,16 @@ private static void ProcessProperties(Type definitionType, DefinitionSchema sche
//prop.TypeFormat = new TypeFormat(prop.TypeFormat.Type, HttpUtility.HtmlEncode(t.FullName));
prop.TypeFormat = new TypeFormat(prop.TypeFormat.Type, null);

prop.Items.TypeFormat = new TypeFormat(ParameterType.Unknown, null);
prop.Items.Ref = t.FullName;
TypeFormat st = Helpers.MapSwaggerType(t);
if (st.Type == ParameterType.Array || st.Type == ParameterType.Object)
{
prop.Items.TypeFormat = new TypeFormat(ParameterType.Unknown, null);
prop.Items.Ref = t.FullName;
}
else
{
prop.Items.TypeFormat = st;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/SwaggerWcf/Support/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace SwaggerWcf.Support
{
internal static class Helpers
{
public static TypeFormat MapSwaggerType(Type type, IList<Type> definitions)
public static TypeFormat MapSwaggerType(Type type, IList<Type> definitions = null)
{
//built-in types
if (type == typeof(bool))
Expand Down
Loading

0 comments on commit dc4b30c

Please sign in to comment.