diff --git a/ApiDocumentation/Implementations/ModelsGenerator.cs b/ApiDocumentation/Implementations/ModelsGenerator.cs index 57355b3..e15b5ba 100644 --- a/ApiDocumentation/Implementations/ModelsGenerator.cs +++ b/ApiDocumentation/Implementations/ModelsGenerator.cs @@ -40,7 +40,10 @@ public virtual Dictionary 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 ); @@ -52,7 +55,12 @@ private static bool IsTask(Type type) => type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Task<>); - private void ProcessType( Type type, Dictionary apiDocModels ) + private static bool IsNullableType(Type typeToConvert) + { + return Nullable.GetUnderlyingType(typeToConvert) != null; + } + + private void ProcessType( Type type, Dictionary apiDocModels ) { foreach ( var property in type.GetProperties() ) { @@ -81,8 +89,12 @@ private void ProcessType( Type type, Dictionary 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 ); diff --git a/ApiDocumentation/Implementations/SwaggerDocumentationTools.cs b/ApiDocumentation/Implementations/SwaggerDocumentationTools.cs index 7c3e442..f6b5bae 100644 --- a/ApiDocumentation/Implementations/SwaggerDocumentationTools.cs +++ b/ApiDocumentation/Implementations/SwaggerDocumentationTools.cs @@ -88,9 +88,13 @@ public Dictionary 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 GetControllerMethods( Type controllerType )