private static void GenerateSamples(HelpPageApiModel apiModel, HelpPageSampleGenerator sampleGenerator)
        {
            try
            {
                foreach (var item in sampleGenerator.GetSampleRequests(apiModel.ApiDescription))
                {
                    apiModel.SampleRequests.Add(item.Key, item.Value);
                    LogInvalidSampleAsError(apiModel, item.Value);
                }

                foreach (var item in sampleGenerator.GetSampleResponses(apiModel.ApiDescription))
                {
                    apiModel.SampleResponses.Add(item.Key, item.Value);
                    LogInvalidSampleAsError(apiModel, item.Value);
                }
            }
            catch (Exception e)
            {
                apiModel.ErrorMessages.Add(String.Format(CultureInfo.CurrentCulture,
                    "An exception has occurred while generating the sample. Exception message: {0}",
                    HelpPageSampleGenerator.UnwrapException(e).Message));
            }
        }
 private static void LogInvalidSampleAsError(HelpPageApiModel apiModel, object sample)
 {
     var invalidSample = sample as InvalidSample;
     if (invalidSample != null)
     {
         apiModel.ErrorMessages.Add(invalidSample.ErrorMessage);
     }
 }
        private static HelpPageApiModel GenerateApiModel(ApiDescription apiDescription, HttpConfiguration config)
        {
            var apiModel = new HelpPageApiModel()
            {
                ApiDescription = apiDescription,
            };

            var modelGenerator = config.GetModelDescriptionGenerator();
            var sampleGenerator = config.GetHelpPageSampleGenerator();
            apiModel.UriParameters = apiModel.ApiDescription.GenerateUriParameters(modelGenerator);
            apiModel.RequestModelDescription = apiModel.ApiDescription.GenerateRequestModelDescription(modelGenerator, sampleGenerator);
            apiModel.ResourceDescription = apiModel.ApiDescription.GenerateResponseDescription(modelGenerator);
            GenerateSamples(apiModel, sampleGenerator);

            return apiModel;
        }