Ejemplo n.º 1
0
        public static IList <Property> ConvertHeadersToProperties(IEnumerable <Parameter> headers)
        {
            var properties = new List <Property>();

            if (headers == null)
            {
                return(properties);
            }

            foreach (var header in headers)
            {
                var description = ParserHelpers.RemoveNewLines(header.Description);

                var shape      = (AnyShape)header.Schema;
                var type       = NewNetTypeMapper.GetNetType(shape);
                var typeSuffix = (type == "string" || type == "object" || header.Required ? "" : "?");

                properties.Add(new Property
                {
                    Type         = type + typeSuffix,
                    Name         = NetNamingMapper.GetPropertyName(header.Name),
                    OriginalName = header.Name,
                    Description  = description,
                    Example      = ObjectParser.MapExample(shape),
                    Required     = header.Required
                });
            }
            return(properties);
        }
Ejemplo n.º 2
0
        private void AddProperty(RAML.Parser.Model.EndPoint resource, Operation method, string key, Response response, ICollection <Property> properties, string fullUrl)
        {
            var mimeType = GeneratorServiceHelper.GetMimeType(response);

            if (mimeType == null)
            {
                return;
            }

            var type = responseTypesService.GetResponseType(method, resource, mimeType, key, response.StatusCode, fullUrl);

            if (string.IsNullOrWhiteSpace(type))
            {
                return;
            }

            var name = NetNamingMapper.GetPropertyName(CollectionTypeHelper.GetBaseType(type));

            if (properties.Any(p => p.Name == name))
            {
                name = name + response.StatusCode;
            }

            var property = new Property
            {
                Name        = name,
                Description = response.Description + " " + mimeType.Schema.Description,
                Example     = ObjectParser.MapExample(mimeType.Schema),
                Type        = type,
                StatusCode  = GetStatusCode(response),
                JSONSchema  = mimeType.Schema as SchemaShape == null ? null : ((SchemaShape)mimeType.Schema).Raw.Replace(Environment.NewLine, "").Replace("\r\n", "").Replace("\n", "").Replace("\"", "\\\"")
            };

            properties.Add(property);
        }
Ejemplo n.º 3
0
        public IList <Property> ConvertParametersToProperties(IEnumerable <Parameter> parameters)
        {
            var properties = new List <Property>();

            foreach (var parameter in parameters.Where(parameter => parameter != null && parameter.Schema != null))
            {
                var description = ParserHelpers.RemoveNewLines(parameter.Description);

                properties.Add(new Property
                {
                    Type         = NewNetTypeMapper.GetNetType(parameter.Schema),
                    Name         = NetNamingMapper.GetPropertyName(parameter.Name),
                    OriginalName = parameter.Name,
                    Description  = description,
                    Example      = ObjectParser.MapExample(parameter.Schema),
                    Required     = parameter.Required
                });
            }
            return(properties);
        }