Beispiel #1
0
        public static void SerializeDescriptionProperty(StringBuilder sb, string description, int indentation)
        {
            if (string.IsNullOrWhiteSpace(description))
            {
                return;
            }

            if (description.Contains(Environment.NewLine) || description.Contains("\r\n") || description.Contains("\n") || description.Contains("\r"))
            {
                RamlSerializerHelper.SerializeMultilineProperty(sb, "description", description, indentation);
                return;
            }

            sb.AppendFormat("{0}: {1}".Indent(indentation), "description", "\"" + description.Replace("\"", string.Empty) + "\"");
            sb.AppendLine();
        }
Beispiel #2
0
        public string Serialize(RamlDocument ramlDocument)
        {
            var sb = new StringBuilder(ramlDocument.Resources.Count + ramlDocument.Resources.Sum(r => r.Resources.Count) * 20);

            sb.AppendLine("#%RAML " + (ramlDocument.RamlVersion == RamlVersion.Version08 ? "0.8" : "1.0"));

            RamlSerializerHelper.SerializeProperty(sb, "title", ramlDocument.Title);

            RamlSerializerHelper.SerializeProperty(sb, "baseUri", ramlDocument.BaseUri);

            RamlSerializerHelper.SerializeProperty(sb, "version", ramlDocument.Version);

            RamlSerializerHelper.SerializeProperty(sb, "mediaType", ramlDocument.MediaType);

            SerializeArrayProperty(sb, "securedBy", ramlDocument.SecuredBy);

            SerializeProtocols(sb, ramlDocument.Protocols);

            SerializeParameters(sb, "uriParameters", ramlDocument.BaseUriParameters);

            if (ramlDocument.Documentation.Any())
            {
                sb.AppendLine("documentation:");
                foreach (var docItem in ramlDocument.Documentation)
                {
                    RamlSerializerHelper.SerializeProperty(sb, "- title", docItem.Title, 2);
                    RamlSerializerHelper.SerializeMultilineProperty(sb, "content", docItem.Content, 4);
                    raml1TypesSerializer.SerializeAnnotations(sb, docItem.Annotations, 4);
                }
                sb.AppendLine();
            }

            SerializeSecuritySchemes(sb, ramlDocument.SecuritySchemes);

            raml1TypesSerializer.Serialize(sb, ramlDocument.Types);

            SerializeSchemas(sb, ramlDocument.Schemas);

            SerializeResources(sb, ramlDocument.Resources);

            SerializeAnnotationTypes(sb, ramlDocument.AnnotationTypes);

            raml1TypesSerializer.SerializeAnnotations(sb, ramlDocument.Annotations);

            return(sb.ToString());
        }