Ejemplo n.º 1
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);
 }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 3
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);
 }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
 }
Ejemplo n.º 6
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);
 }
Ejemplo n.º 7
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);
 }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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);
            }
        }
Ejemplo n.º 10
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());
        }
Ejemplo n.º 11
0
 private static void SerializeTypeProperty(StringBuilder sb, int indentation, string type)
 {
     RamlSerializerHelper.SerializeProperty(sb, "type", type, indentation + 4);
 }