Exemplo n.º 1
0
        private void SerializeParameter(StringBuilder sb, KeyValuePair <string, Parameter> parameter, int indentation)
        {
            sb.AppendFormat("{0}:".Indent(indentation), parameter.Key);
            sb.AppendLine();

            RamlSerializerHelper.SerializeParameterProperties(sb, parameter.Value, indentation);
        }
Exemplo n.º 2
0
 private void SerializeArrayProperties(StringBuilder sb, int indentation, ArrayType arrayType)
 {
     RamlSerializerHelper.SerializeProperty(sb, "minItems", arrayType.MinItems, indentation);
     RamlSerializerHelper.SerializeProperty(sb, "maxItems", arrayType.MaxItems, indentation);
     RamlSerializerHelper.SerializeProperty(sb, "uniqueItems", arrayType.UniqueItems, indentation);
     SerializeCommonProperties(sb, arrayType.Items, indentation);
 }
Exemplo n.º 3
0
        private void SerializeMethod(StringBuilder sb, Method method, int indentation)
        {
            sb.AppendLine((method.Verb + ":").Indent(indentation));
            RamlSerializerHelper.SerializeDescriptionProperty(sb, method.Description, indentation + 2);
            //SerializeType(sb, method.Type, indentation + 2);

            if (method.Headers != null)
            {
                sb.AppendLine("headers:".Indent(indentation + 2));
                foreach (var header in method.Headers)
                {
                    sb.AppendLine(header.Key + ":".Indent(indentation + 4));
                    RamlSerializerHelper.SerializeParameterProperties(sb, header.Value, indentation + 6);
                }
            }

            SerializeArrayProperty(sb, "is", method.Is, indentation + 2);
            SerializeProtocols(sb, method.Protocols, indentation + 2);
            SerializeArrayProperty(sb, "securedBy", method.SecuredBy, indentation + 2);
            SerializeParameters(sb, "baseUriParameters", method.BaseUriParameters, indentation + 2);
            SerializeParameters(sb, "queryParameters", method.QueryParameters, indentation + 2);
            SerializeBody(sb, method.Body, indentation + 2);
            SerializeResponses(sb, method.Responses, indentation + 2);
            raml1TypesSerializer.SerializeAnnotations(sb, method.Annotations, indentation + 2);
        }
Exemplo n.º 4
0
 private void SerializeScalar(StringBuilder sb, RamlType ramlType, int indentation)
 {
     RamlSerializerHelper.SerializeCommonParameterProperties(sb, ramlType.Scalar, indentation);
     RamlSerializerHelper.SerializeProperty(sb, "multipleOf", ramlType.Scalar.MultipleOf, indentation);
     RamlSerializerHelper.SerializeListProperty(sb, "fileTypes", ramlType.Scalar.FileTypes, indentation);
     SerializeFormat(sb, indentation, ramlType.Scalar.Format);
     SerializeAnnotations(sb, ramlType.Scalar.Annotations, indentation);
 }
Exemplo n.º 5
0
 private void SerializeObject(StringBuilder sb, RamlType ramlType, int indentation)
 {
     RamlSerializerHelper.SerializeProperty(sb, "maxProperties", ramlType.Object.MaxProperties, indentation + 4);
     RamlSerializerHelper.SerializeProperty(sb, "minProperties", ramlType.Object.MinProperties, indentation + 4);
     RamlSerializerHelper.SerializeProperty(sb, "discriminator", ramlType.Object.Discriminator as string, indentation + 4);
     RamlSerializerHelper.SerializeProperty(sb, "discriminatorValue", ramlType.Object.DiscriminatorValue, indentation + 4);
     SerializeObjectProperties(sb, ramlType.Object.Properties, indentation + 4);
 }
Exemplo n.º 6
0
        private static void SerializeCommonProperties(StringBuilder sb, RamlType ramlType, int indentation)
        {
            RamlSerializerHelper.SerializeProperty(sb, "description", ramlType.Description, indentation + 4);

            RamlSerializerHelper.SerializeProperty(sb, "displayName", ramlType.DisplayName, indentation + 4);

            RamlSerializerHelper.SerializeProperty(sb, "example", ramlType.Example, indentation + 4);

            SerializeFacets(sb, ramlType.Facets, indentation + 4);
        }
Exemplo n.º 7
0
 private void SerializeMimeType(StringBuilder sb, KeyValuePair <string, MimeType> mimeType, int indentation)
 {
     sb.AppendLine((mimeType.Key + ":").Indent(indentation));
     RamlSerializerHelper.SerializeDescriptionProperty(sb, mimeType.Value.Description, indentation + 2);
     RamlSerializerHelper.SerializeProperty(sb, "type", mimeType.Value.Type, indentation + 2);
     SerializeParameters(sb, "formParameters", mimeType.Value.FormParameters, indentation + 2);
     RamlSerializerHelper.SerializeProperty(sb, "schema", mimeType.Value.Schema, indentation + 2);
     RamlSerializerHelper.SerializeProperty(sb, "example", mimeType.Value.Example, indentation + 2);
     raml1TypesSerializer.SerializeAnnotations(sb, mimeType.Value.Annotations, indentation + 2);
 }
Exemplo n.º 8
0
        private static void SerializeExternal(StringBuilder sb, RamlType ramlType, int indentation)
        {
            if (!string.IsNullOrWhiteSpace(ramlType.External.Schema))
            {
                RamlSerializerHelper.SerializeSchema(sb, "schema", ramlType.External.Schema, indentation + 4);
            }

            if (!string.IsNullOrWhiteSpace(ramlType.External.Xml))
            {
                RamlSerializerHelper.SerializeSchema(sb, "schema", ramlType.External.Xml, indentation + 4);
            }
        }
Exemplo n.º 9
0
        private void SerializeSchemas(StringBuilder sb, IEnumerable <IDictionary <string, string> > schemas)
        {
            if (schemas == null || !schemas.Any() || schemas.All(x => !x.Any()))
            {
                return;
            }

            sb.AppendLine("schemas:");
            foreach (var kv in schemas.SelectMany(schemaDic => schemaDic))
            {
                RamlSerializerHelper.SerializeSchema(sb, kv.Key, kv.Value, 2);
            }
        }
Exemplo n.º 10
0
 private void SerializeAnnotationType(StringBuilder sb, AnnotationType annotationType)
 {
     RamlSerializerHelper.SerializeProperty(sb, "description", annotationType.Description, 8);
     RamlSerializerHelper.SerializeProperty(sb, "displayName", annotationType.DisplayName, 8);
     RamlSerializerHelper.SerializeProperty(sb, "allowMultiple", annotationType.AllowMultiple, 8);
     RamlSerializerHelper.SerializeProperty(sb, "usage", annotationType.Usage, 8);
     SerializeArrayProperty(sb, "allowedTargets", annotationType.AllowedTargets, 8);
     foreach (var parameter in annotationType.Parameters)
     {
         SerializeParameter(sb, parameter, 8);
     }
     raml1TypesSerializer.SerializeAnnotations(sb, annotationType.Annotations, 8);
 }
Exemplo n.º 11
0
 private void SerializeResource(StringBuilder sb, Resource resource, int indentation)
 {
     sb.AppendLine((resource.RelativeUri + ":").Indent(indentation));
     SerializeParameters(sb, "baseUriParameters", resource.BaseUriParameters, indentation + 2);
     RamlSerializerHelper.SerializeDescriptionProperty(sb, resource.Description, indentation + 2);
     RamlSerializerHelper.SerializeProperty(sb, "displayName", resource.DisplayName, indentation + 2);
     SerializeProtocols(sb, resource.Protocols, indentation + 2);
     SerializeParameters(sb, "uriParameters", resource.UriParameters, indentation + 2);
     SerializeMethods(sb, resource.Methods, indentation + 2);
     //SerializeType(sb, resource.Type, indentation + 2);
     SerializeResources(sb, resource.Resources, indentation + 2);
     raml1TypesSerializer.SerializeAnnotations(sb, resource.Annotations, indentation + 2);
 }
Exemplo n.º 12
0
        private void SerializeSecuritySettings(StringBuilder sb, SecuritySettings settings, int indent)
        {
            if (settings == null)
            {
                return;
            }

            sb.AppendLine("settings:".Indent(indent));
            RamlSerializerHelper.SerializeProperty(sb, "accessTokenUri", settings.AccessTokenUri, indent + 2);
            RamlSerializerHelper.SerializeProperty(sb, "authorizationUri", settings.AuthorizationUri, indent + 2);
            RamlSerializerHelper.SerializeProperty(sb, "requestTokenUri", settings.RequestTokenUri, indent + 2);
            RamlSerializerHelper.SerializeProperty(sb, "tokenCredentialsUri", settings.TokenCredentialsUri, indent + 2);
            SerializeArrayProperty(sb, "authorizationGrants", settings.AuthorizationGrants, indent + 2);
            RamlSerializerHelper.SerializeListProperty(sb, "scopes", settings.Scopes, indent + 2);
        }
Exemplo n.º 13
0
        private void SerializeSecurityScheme(StringBuilder sb, IDictionary <string, SecurityScheme> scheme, int indent)
        {
            foreach (var securityScheme in scheme)
            {
                sb.AppendLine(("- " + securityScheme.Key + ":").Indent(indent));
                RamlSerializerHelper.SerializeDescriptionProperty(sb, securityScheme.Value.Description, indent + 4);
                if (securityScheme.Value.Type != null && securityScheme.Value.Type.Any())
                {
                    RamlSerializerHelper.SerializeProperty(sb, "type", securityScheme.Value.Type.First().Key, indent + 4);
                }

                SerializeSecurityDescriptor(sb, securityScheme.Value.DescribedBy, indent + 4);
                SerializeSecuritySettings(sb, securityScheme.Value.Settings, indent + 4);
            }
        }
Exemplo n.º 14
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();
        }
Exemplo n.º 15
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());
        }
Exemplo n.º 16
0
 private static void SerializeTypeProperty(StringBuilder sb, int indentation, string type)
 {
     RamlSerializerHelper.SerializeProperty(sb, "type", type, indentation + 4);
 }
Exemplo n.º 17
0
 private void SerializeResponse(StringBuilder sb, Response response, int indentation)
 {
     sb.AppendLine(response.Code.Indent(indentation) + ":");
     RamlSerializerHelper.SerializeDescriptionProperty(sb, response.Description, indentation + 2);
     SerializeBody(sb, response.Body, indentation + 2);
 }