Skip to content

Commit

Permalink
Merge pull request #66 from Kupferhirn/prop-example
Browse files Browse the repository at this point in the history
Add example to property
  • Loading branch information
abelsilva authored Feb 21, 2017
2 parents 1acda73 + c0bb417 commit 5f5b18a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/SwaggerWcf/Attributes/SwaggerWcfPropertyAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public SwaggerWcfPropertyAttribute()
/// </summary>
public string Default { get; set; }

/// <summary>
/// Illustrate what the value is supposed to be like.
/// </summary>
public object Example { get; set; }

/// <summary>
/// Maximum allowed value, as modified by ExclusiveMaximum.
/// Must be a valid JSON number, and storable as a decimal.
Expand Down
17 changes: 17 additions & 0 deletions src/SwaggerWcf/Models/DefinitionProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public DefinitionProperty()

public string Default { get; set; }

public object Example { get; set; }

public decimal Maximum { get; set; }

public bool ExclusiveMaximum { get; set; }
Expand Down Expand Up @@ -92,6 +94,21 @@ public void Serialize(JsonWriter writer)
writer.WritePropertyName("default");
writer.WriteValue(Default);
}
if (Example!=null)
{
writer.WritePropertyName("example");
if (Example.GetType().IsArray)
{
writer.WriteStartArray();
foreach (var value in (object[])Example)
{
writer.WriteValue(value);
}
writer.WriteEndArray();
}
else
writer.WriteValue(Example);
}
if (Maximum != decimal.MaxValue)
{
writer.WritePropertyName("maximum");
Expand Down
1 change: 1 addition & 0 deletions src/SwaggerWcf/Support/DefinitionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ private static void ApplyAttributeOptions(PropertyInfo propertyInfo, DefinitionP
//ApplyIfValid(LastValidValue(attrs, a => a._AllowEmptyValue), x => prop.AllowEmptyValue = x.Value);
//ApplyIfValid(LastValidValue(attrs, a => a._CollectionFormat), x => prop.CollectionFormat = x.Value);
ApplyIfValid(LastValidValue(attrs, a => a.Default), x => prop.Default = x);
ApplyIfValid(LastValidValue(attrs, a => a.Example), x => prop.Example = x);
ApplyIfValid(LastValidValue(attrs, a => a._Maximum), x => prop.Maximum = x.Value);
ApplyIfValid(LastValidValue(attrs, a => a._ExclusiveMaximum), x => prop.ExclusiveMaximum = x.Value);
ApplyIfValid(LastValidValue(attrs, a => a._Minimum), x => prop.Minimum = x.Value);
Expand Down

0 comments on commit 5f5b18a

Please sign in to comment.