Skip to content
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
18 changes: 15 additions & 3 deletions ApiDocumentation/Implementations/ModelsGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ public virtual Dictionary<String, ApiDocModel> GetModels( Type type )
if ( IsArray( type ) )
type = type.GetElementType();

var name = _typeToStringConverter.GetApiOperationType( type );
if (IsNullableType(type))
type = Nullable.GetUnderlyingType(type);

var name = _typeToStringConverter.GetApiOperationType( type );
var apiDocModels = InitializeApiDocModels( name );

ProcessType( type, apiDocModels );
Expand All @@ -52,7 +55,12 @@ private static bool IsTask(Type type)
=> type.IsGenericType
&& type.GetGenericTypeDefinition() == typeof(Task<>);

private void ProcessType( Type type, Dictionary<string, ApiDocModel> apiDocModels )
private static bool IsNullableType(Type typeToConvert)
{
return Nullable.GetUnderlyingType(typeToConvert) != null;
}

private void ProcessType( Type type, Dictionary<string, ApiDocModel> apiDocModels )
{
foreach ( var property in type.GetProperties() )
{
Expand Down Expand Up @@ -81,8 +89,12 @@ private void ProcessType( Type type, Dictionary<string, ApiDocModel> apiDocModel

modelProperty = GetArrayModelProperty( typeof( KeyValuePair<,> ) );
}
else if (IsNullableType(propertyType))
{
propertyType = Nullable.GetUnderlyingType(propertyType);
}

GetNonPrimitiveModels( propertyType, apiDocModels );
GetNonPrimitiveModels( propertyType, apiDocModels );
apiDocModels.First().Value.properties.Add( property.Name, modelProperty );
if ( property.GetCustomAttributes( typeof( OptionalAttribute ), true ).Length == 0 )
apiDocModels.First().Value.required.Add( property.Name );
Expand Down
8 changes: 6 additions & 2 deletions ApiDocumentation/Implementations/SwaggerDocumentationTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,13 @@ public Dictionary<string, ApiDocModel> GetControllerModels( Type controllerType
foreach ( var apiDocumentationAttributesAndReturnType in GetApiDocumentationAttributesAndReturnTypes( controllerType ) )
{
result.Merge( _modelsGenerator.GetModels( apiDocumentationAttributesAndReturnType.Key.ReturnType ?? apiDocumentationAttributesAndReturnType.Value ) );
}

return result;
//Get models for parameters
if ( apiDocumentationAttributesAndReturnType.Key.FormBody != null )
result.Merge( _modelsGenerator.GetModels(apiDocumentationAttributesAndReturnType.Key.FormBody) );
}

return result;
}

private IEnumerable<MethodInfo> GetControllerMethods( Type controllerType )
Expand Down