Inheritance: RestApiItemViewModelBase
コード例 #1
0
        private static IEnumerable<XRefSpec> GetXRefInfo(RestApiRootItemViewModel rootItem, string key)
        {
            yield return new XRefSpec
            {
                Uid = rootItem.Uid,
                Name = rootItem.Name,
                Href = key,
            };

            if (rootItem.Children != null)
            {
                foreach (var child in rootItem.Children)
                {
                    yield return new XRefSpec
                    {
                        Uid = child.Uid,
                        Name = child.OperationId,
                        Href = key,
                    };
                }
            }

            if (rootItem.Tags != null)
            {
                foreach (var tag in rootItem.Tags)
                {
                    yield return new XRefSpec
                    {
                        Uid = tag.Uid,
                        Name = tag.Name,
                        Href = key,
                    };
                }
            }
        }
コード例 #2
0
 private static void FillInBookmarks(FileModel model, RestApiRootItemViewModel restModel)
 {
     model.Bookmarks[restModel.Uid] = string.Empty;
     restModel.Children?.ForEach(c => model.Bookmarks[c.Uid] = c.HtmlId);
     restModel.Tags?.ForEach(t => model.Bookmarks[t.Uid] = t.HtmlId);
 }
コード例 #3
0
        public static RestApiRootItemViewModel FromSwaggerModel(SwaggerModel swagger)
        {
            var uid = GetUid(swagger);
            var vm = new RestApiRootItemViewModel
            {
                Name = swagger.Info.Title,
                Uid = uid,
                HtmlId = GetHtmlId(uid),
                Metadata = swagger.Metadata,
                Description = swagger.Description,
                Summary = swagger.Summary,
                Children = new List<RestApiChildItemViewModel>(),
                Raw = swagger.Raw,
                Tags = new List<RestApiTagViewModel>()
            };
            if (swagger.Tags != null)
            {
                foreach (var tag in swagger.Tags)
                {
                    vm.Tags.Add(new RestApiTagViewModel
                    {
                        Name = tag.Name,
                        Description = tag.Description,
                        HtmlId = string.IsNullOrEmpty(tag.BookmarkId) ? GetHtmlId(tag.Name) : tag.BookmarkId, // Fall back to tag name's html id
                        Metadata = tag.Metadata,
                        Uid = GetUidForTag(uid, tag)
                    });
                }
            }
            if (swagger.Paths != null)
            {
                foreach (var path in swagger.Paths)
                {
                    var commonParameters = path.Value.Parameters;
                    foreach (var op in path.Value.Metadata)
                    {
                        // fetch operations from metadata
                        if (OperationNames.Contains(op.Key, StringComparer.OrdinalIgnoreCase))
                        {
                            var opJObject = op.Value as JObject;
                            if (opJObject == null)
                            {
                                throw new InvalidOperationException($"Value of {op.Key} should be JObject");
                            }

                            // convert operation from JObject to OperationObject
                            var operation = opJObject.ToObject<OperationObject>();
                            var parameters = GetParametersForOperation(operation.Parameters, commonParameters);
                            var itemUid = GetUidForOperation(uid, operation);
                            var itemVm = new RestApiChildItemViewModel
                            {
                                Path = path.Key,
                                OperationName = op.Key,
                                OperationId = operation.OperationId,
                                HtmlId = GetHtmlId(itemUid),
                                Uid = itemUid,
                                Metadata = operation.Metadata,
                                Description = operation.Description,
                                Summary = operation.Summary,
                                Parameters = parameters?.Select(s => new RestApiParameterViewModel
                                {
                                    Description = s.Description,
                                    Name = s.Name,
                                    Metadata = s.Metadata
                                }).ToList(),
                                Responses = operation.Responses?.Select(s => new RestApiResponseViewModel
                                {
                                    Metadata = s.Value.Metadata,
                                    Description = s.Value.Description,
                                    Summary = s.Value.Summary,
                                    HttpStatusCode = s.Key,
                                    Examples = s.Value.Examples?.Select(example => new RestApiResponseExampleViewModel
                                    {
                                        MimeType = example.Key,
                                        Content = example.Value != null ? JsonUtility.Serialize(example.Value) : null,
                                    }).ToList(),
                                }).ToList(),
                            };

                            // TODO: line number
                            object value;
                            if (swagger.Metadata.TryGetValue(Constants.PropertyName.Source, out value))
                            {
                                itemVm.Metadata[Constants.PropertyName.Source] = value;
                            }
                            else
                            {
                                itemVm.Metadata[Constants.PropertyName.Source] = null;
                            }
                            vm.Children.Add(itemVm);
                        }
                    }
                }
            }

            return vm;
        }