/// <summary>
 /// Sets the help page sample generator.
 /// </summary>
 /// <param name="config">The <see cref="HttpConfiguration"/>.</param>
 /// <param name="sampleGenerator">The help page sample generator.</param>
 public static void SetApiSpecSampleGenerator(this HttpConfiguration config, ApiSpecSampleGenerator sampleGenerator)
 {
     config.Properties.AddOrUpdate(
         typeof(ApiSpecSampleGenerator),
         k => sampleGenerator,
         (k, o) => sampleGenerator);
 }
        private static bool TryGetResourceParameter(ApiDescription apiDescription, HttpConfiguration config, out ApiParameterDescription parameterDescription, out Type resourceType)
        {
            parameterDescription = apiDescription.ParameterDescriptions.FirstOrDefault(
                p => p.Source == ApiParameterSource.FromBody ||
                (p.ParameterDescriptor != null && p.ParameterDescriptor.ParameterType == typeof(HttpRequestMessage)));

            if (parameterDescription == null)
            {
                resourceType = null;
                return(false);
            }

            resourceType = parameterDescription.ParameterDescriptor.ParameterType;

            if (resourceType == typeof(HttpRequestMessage))
            {
                ApiSpecSampleGenerator sampleGenerator = config.GetApiSpecSampleGenerator();
                resourceType = sampleGenerator.ResolveHttpRequestMessageType(apiDescription);
            }

            if (resourceType == null)
            {
                parameterDescription = null;
                return(false);
            }

            return(true);
        }
        // Default factory for sample objects
        private static object DefaultSampleObjectFactory(ApiSpecSampleGenerator sampleGenerator, Type type)
        {
            // Try to create a default sample object
            ObjectGenerator objectGenerator = new ObjectGenerator();

            return(objectGenerator.GenerateObject(type));
        }