public static ApiObject GetHeadersObject(ClientGeneratorMethod generatedMethod, Response response, string objectName)
 {
    return new ApiObject
     {
         Name = generatedMethod.Name + objectName + ParserHelpers.GetStatusCode(response.Code) + "ResponseHeader",
         Properties = ParseHeaders(response)
     };
 }
        public RamlResponseWrapper(Response ramlDocResponse)
        {
            HttpReturnCode = ramlDocResponse.Code;
            Description = ramlDocResponse.Description;

            if (ramlDocResponse.Body != null)
            {
                var responseBody = ramlDocResponse.Body.FirstOrDefault(kvp => kvp.Key.Contains("json"));

                MediaType = responseBody.Key;
                JsonSchema = (MediaType != null) ? responseBody.Value.Schema : null;
                IsMTJson = (JsonSchema != null);
            }
        }
        public void Should_Build_Multiple_Headers_When_Many_Response_With_Headers()
        {
            var doc = new RamlDocument {Title = "test"};

            var okHeaders = new List<Parameter>
                            {
                                new Parameter
                                {
                                    DisplayName = "code",
                                    Type = "integer"
                                },
                                new Parameter
                                {
                                    DisplayName = "token",
                                    Type = "string"
                                }
                            };

            var errorHeaders = new List<Parameter>
                            {
                                new Parameter
                                {
                                    DisplayName = "code",
                                    Type = "integer"
                                },
                                new Parameter
                                {
                                    DisplayName = "error",
                                    Type = "string"
                                }
                            };

            var badRequestHeaders = new List<Parameter>
                            {
                                new Parameter
                                {
                                    DisplayName = "code",
                                    Type = "integer"
                                },
                                new Parameter
                                {
                                    DisplayName = "description",
                                    Type = "string"
                                }
                            };

            var okResponse = new Response
                             {
                                 Code = "200",
                                 Headers = okHeaders
                             };

            var errorResponse = new Response
                                {
                                    Code = "400",
                                    Headers = errorHeaders
                                };

            var notFoundResponse = new Response
                                   {
                                       Code = "404",
                                       Headers = badRequestHeaders
                                   };

            var methods = new List<Method>
                          {
                              new Method
                              {
                                  Verb = "get",
                                  Responses = new[] { okResponse, errorResponse, notFoundResponse }
                              }
                          };

            var resources = new Collection<Resource>
                            {
                                new Resource
                                {
                                    RelativeUri = "movies",
                                    Methods = methods
                                }
                            };

            doc.Resources = resources;

            var service = new ClientGeneratorService(doc, "test", "TargetNamespace");
            var model = service.BuildModel();
            Assert.AreEqual(4, model.ResponseHeaderObjects.Count);

            var multipleModel = model.ResponseHeaderObjects.First(o => o.Key.Contains("Multiple")).Value;

            Assert.AreEqual(3, multipleModel.Properties.Count);

            Assert.AreEqual("Models." + model.ResponseHeaderObjects.First(o => o.Key.Contains("Multiple")).Value.Name,
                model.Classes.First().Methods.First().ResponseHeaderType);
        }
		private IEnumerable<Response> GetResponses(ResponseDescription responseDescription)
		{
			if (responseDescription.ResponseType == null && responseDescription.DeclaredType == null)
				return new Collection<Response>();

			var responseType = responseDescription.ResponseType ?? responseDescription.DeclaredType;

            if(responseType == typeof(IHttpActionResult))
                return new Collection<Response>();

		    var schemaName = AddSchema(responseType);

		    var mimeTypes = new Dictionary<string, MimeType>
			                {
				                {
					                "application/json",
					                new MimeType
					                {
						                Schema = schemaName
					                }
				                }
			                };

			var response = new Response
			               {
				               Body = mimeTypes,
							   Code = "200" // TODO: is it OK to asume this ?
			               };
			return new[] {response};
		}
		private void SerializeResponse(StringBuilder sb, Response response, int indentation)
		{
			sb.AppendLine(response.Code.Indent(indentation) + ":");
            SerializeDescriptionProperty(sb, response.Description, indentation + 2);
			SerializeBody(sb, response.Body, indentation + 2);
		}
        public void Should_Get_Multiple_Type_When_Many_Response_Schemas_On_Resource()
        {
            var doc = new RamlDocument { Title = "test" };

            var okResponse = new Response
            {
                Code = "200",
                Body = new Dictionary<string, MimeType>
                                        {
                                            {
                                                "application/json", new MimeType
                                                                    {
                                                                        Schema = movieSchema
                                                                    }
                                            }
                                        }
            };

            var errorResponse = new Response
            {
                Code = "400",
                Body = new Dictionary<string, MimeType>
                                           {
                                               {
                                                   "application/json", new MimeType
                                                                       {
                                                                           Schema = errorSchema
                                                                       }
                                               }
                                           }
            };

            var notFoundResponse = new Response
            {
                Code = "404",
                Body = new Dictionary<string, MimeType>
                                              {
                                                  {
                                                      "application/json", new MimeType
                                                                          {
                                                                              Schema = notFoundSchema
                                                                          }
                                                  }
                                              }
            };

            var methods = new List<Method>
                          {
                              new Method
                              {
                                  Verb = "get",
                                  Responses = new[] { okResponse, errorResponse, notFoundResponse }
                              }
                          };

            var resources = new Collection<Resource>
                            {
                                new Resource
                                {
                                    RelativeUri = "/movies",
                                    Methods = methods
                                }
                            };

            doc.Resources = resources;

            var service = new ClientGeneratorService(doc, "test", "TestNs");
            var model = service.BuildModel();
            Assert.AreEqual(4, model.ResponseObjects.Count);

            var multipleModel = model.ResponseObjects.First(o => o.Key.Contains("Multiple")).Value;

            Assert.AreEqual(3, multipleModel.Properties.Count);
        }
        public void Should_Get_Multiple_Type_When_Many_Response_Schemas_On_Root()
        {
            var doc = new RamlDocument {Title = "test"};
            var schemas = new List<Dictionary<string, string>>();
            var schemaMovie = new Dictionary<string, string>();
            schemaMovie.Add("movie", movieSchema);
            var schemaError = new Dictionary<string, string>();
            schemaMovie.Add("error", errorSchema);
            var schemaNotFound = new Dictionary<string, string>();
            schemaMovie.Add("notfound", notFoundSchema);
            schemas.Add(schemaMovie);
            schemas.Add(schemaError);
            schemas.Add(schemaNotFound);
            doc.Schemas = schemas;

            var okResponse = new Response
                             {
                                 Code = "200",
                                 Body = new Dictionary<string, MimeType>
                                        {
                                            {
                                                "application/json", new MimeType
                                                                    {
                                                                        Schema = "movie"
                                                                    }
                                            }
                                        }
                             };

            var errorResponse = new Response
                                {
                                    Code = "400",
                                    Body = new Dictionary<string, MimeType>
                                           {
                                               {
                                                   "application/json", new MimeType
                                                                       {
                                                                           Schema = "error"
                                                                       }
                                               }
                                           }
                                };

            var notFoundResponse = new Response
                                   {
                                       Code = "404",
                                       Body = new Dictionary<string, MimeType>
                                              {
                                                  {
                                                      "application/json", new MimeType
                                                                          {
                                                                              Schema = "notfound"
                                                                          }
                                                  }
                                              }
                                   };

            var methods = new List<Method>
                          {
                              new Method
                              {
                                  Verb = "get",
                                  Responses = new[] { okResponse, errorResponse, notFoundResponse }
                              }
                          };

            var resources = new Collection<Resource>
                            {
                                new Resource
                                {
                                    RelativeUri = "/movies",
                                    Methods = methods
                                }
                            };

            doc.Resources = resources;

            var service = new ClientGeneratorService(doc, "test", "TestNs");
            var model = service.BuildModel();
            Assert.AreEqual(1, model.ResponseObjects.Count);
            Assert.AreEqual(3, model.SchemaObjects.Count);

            var multipleModel = model.ResponseObjects.First(o => o.Key.Contains("Multiple")).Value;

            Assert.AreEqual(3, multipleModel.Properties.Count);

            Assert.AreEqual(1, multipleModel.Properties.Count(p => p.Type == "Movie"));
            Assert.AreEqual(1, multipleModel.Properties.Count(p => p.Type == "Error"));
            Assert.AreEqual(1, multipleModel.Properties.Count(p => p.Type == "Notfound"));
        }
 public static IList<Property> ParseHeaders(Response response)
 {
     return ConvertHeadersToProperties(response.Headers);
 }