Exemplo n.º 1
0
        public override FileModel Load(FileAndType file, ImmutableDictionary<string, object> metadata)
        {
            switch (file.Type)
            {
                case DocumentType.Article:
                    var filePath = Path.Combine(file.BaseDir, file.File);
                    var swaggerContent = File.ReadAllText(filePath);
                    var swagger = SwaggerJsonParser.Parse(swaggerContent);
                    swagger.Metadata[DocumentTypeKey] = RestApiDocumentType;
                    swagger.Raw = swaggerContent;
                    var repoInfo = GitUtility.GetGitDetail(filePath);
                    if (repoInfo != null)
                    {
                        swagger.Metadata["source"] = new SourceDetail() { Remote = repoInfo };
                    }

                    swagger.Metadata = MergeMetadata(swagger.Metadata, metadata);
                    var vm = SwaggerModelConverter.FromSwaggerModel(swagger);
                    var displayLocalPath = PathUtility.MakeRelativePath(EnvironmentContext.BaseDirectory, file.FullPath);

                    return new FileModel(file, vm, serializer: Environment.Is64BitProcess ? null : new BinaryFormatter())
                    {
                        Uids = new[] { new UidDefinition(vm.Uid, displayLocalPath) }
                            .Concat(from item in vm.Children select new UidDefinition(item.Uid, displayLocalPath))
                            .Concat(from tag in vm.Tags select new UidDefinition(tag.Uid, displayLocalPath)).ToImmutableArray(),
                        LocalPathFromRepoRoot = repoInfo?.RelativePath ?? filePath.ToDisplayPath(),
                        LocalPathFromRoot = displayLocalPath
                    };
                case DocumentType.Overwrite:
                    // TODO: Refactor current behavior that overwrite file is read multiple times by multiple processors
                    return OverwriteDocumentReader.Read(file);
                default:
                    throw new NotSupportedException();
            }
        }
Exemplo n.º 2
0
        protected override FileModel LoadArticle(FileAndType file, ImmutableDictionary <string, object> metadata)
        {
            var filePath = Path.Combine(file.BaseDir, file.File);
            var swagger  = SwaggerJsonParser.Parse(filePath);

            swagger.Metadata[DocumentTypeKey] = RestApiDocumentType;
            swagger.Raw = EnvironmentContext.FileAbstractLayer.ReadAllText(filePath);
            CheckOperationId(swagger, file.File);

            var repoInfo = GitUtility.TryGetFileDetail(filePath);

            if (repoInfo != null)
            {
                swagger.Metadata["source"] = new SourceDetail()
                {
                    Remote = repoInfo
                };
            }

            swagger.Metadata = MergeMetadata(swagger.Metadata, metadata);
            var vm = SwaggerModelConverter.FromSwaggerModel(swagger);

            vm.Metadata[Constants.PropertyName.SystemKeys] = SystemKeys;
            var displayLocalPath = PathUtility.MakeRelativePath(EnvironmentContext.BaseDirectory, file.FullPath);

            return(new FileModel(file, vm, serializer: new BinaryFormatter())
            {
                Uids = new[] { new UidDefinition(vm.Uid, displayLocalPath) }
                .Concat(from item in vm.Children select new UidDefinition(item.Uid, displayLocalPath))
                .Concat(from tag in vm.Tags select new UidDefinition(tag.Uid, displayLocalPath)).ToImmutableArray(),
                LocalPathFromRoot = displayLocalPath
            });
        }