public NormalizationApiOperation(NormalizationApiOperation copyFrom)
            : base(copyFrom)
        {
            BasePath = copyFrom.BasePath;
            Description = copyFrom.Description;
            HttpMethod = copyFrom.HttpMethod;
            Name = copyFrom.Name;
            Path = copyFrom.Path;
            ResourcePath = copyFrom.ResourcePath;
            Response = new NormalizationApiOperationResponse(copyFrom.Response);
            SupportsStreaming = copyFrom.SupportsStreaming;

            if (copyFrom.Parameters.Any())
            {
                Parameters.AddRange(copyFrom.Parameters);
            }
        }
Example #2
0
        public NormalizationApiOperation(NormalizationApiOperation copyFrom) : base(copyFrom)
        {
            BasePath                  = copyFrom.BasePath;
            Description               = copyFrom.Description;
            HttpMethod                = copyFrom.HttpMethod;
            Name                      = copyFrom.Name;
            Path                      = copyFrom.Path;
            ResourcePath              = copyFrom.ResourcePath;
            Response                  = new NormalizationApiOperationResponse(copyFrom.Response);
            SupportsStreamingUpload   = copyFrom.SupportsStreamingUpload;
            SupportsStreamingDownload = copyFrom.SupportsStreamingDownload;

            if (copyFrom.Parameters.Any())
            {
                Parameters.AddRange(copyFrom.Parameters);
            }
        }
        private QualifiedName ExtractName(NormalizationApiOperation op)
        {
            var name = op.Name;
            var resourceName = op.ResourcePath.ResourceNameFromPath();

            if (name.StartsWith(resourceName))
            {
                name = name.Substring(resourceName.Length);
            }

            if (name[0] == '_')
            {
                name = name.Substring(1);
            }

            if (char.IsLower(name[0]))
            {
                name = char.ToUpperInvariant(name[0]) + name.Substring(1);
            }

            return new QualifiedName(name);
        }
        private NormalizationApiOperation ParseOperationData(object obj)
        {
            dynamic extractedOp = obj;
            var opObj = extractedOp.JObject;

            var op = new NormalizationApiOperation
            {
                ApiVersion = (string) extractedOp.ApiVersion,
                BasePath = (string) extractedOp.BasePath,
                Path = (string) extractedOp.OperationPath,
                ResourcePath = (string) extractedOp.ResourcePath,
                HttpMethod = (opObj.ContainsKey("method") ? (string) opObj.method : string.Empty).ParseHttpMethodType(),
                Description = opObj.ContainsKey("summary") ? (string) opObj.summary : string.Empty,
                Name = opObj.ContainsKey("nickname") ? (string) opObj.nickname : string.Empty
            };

            op.Parameters.AddRange(ParseParameters(opObj));
            op.Response = ParseResponse(opObj);
            op.SupportsStreaming = ParseSupportsStreaming(opObj);

            return op;
        }
 private ResponseDefinition NormalizeResponseDefinition(NormalizationApiOperation op)
 {
     var dt = op.Response.AsDataType();
     return new ResponseDefinition(op.Response.AsMetadata())
     {
         DataType = dt
     };
 }
        private OperationPath NormalizeOperationPath(NormalizationApiOperation op)
        {
            var pathBuilder = new StringBuilder('/');

            var basePath = NormalizeBasePath(op.BasePath);
            if (!string.IsNullOrWhiteSpace(basePath))
            {
                pathBuilder.Append(basePath);
            }
            if (!string.IsNullOrWhiteSpace(op.Path))
            {
                var opPath = op.Path;
                if (opPath.StartsWith("/", StringComparison.InvariantCultureIgnoreCase))
                {
                    opPath = opPath.Length == 1 ? string.Empty : opPath.Substring(1);
                }
                pathBuilder.Append(opPath);
            }

            var path = pathBuilder.ToString();

            var versionParam = op.Parameters.FirstOrDefault(x => x.Name.IndexOf(Constants.ParameterName_Version, StringComparison.InvariantCultureIgnoreCase) >= 0);
            if (versionParam != null)
            {
                var template = new UriTemplate(path, true);
                template.SetParameter(versionParam.Name, op.ApiVersion);
                path = template.Resolve();
                op.Parameters.Remove(versionParam);
            }

            return new OperationPath(path);
        }