private void GenerateDocFileContent(Type metricsType, string docsDir)
        {
            StringBuilder docBuilder = new StringBuilder();

            PropertyInfo[] moduleProperties = metricsType.GetProperties().OrderBy(x => x.Name).ToArray();

            string moduleName = metricsType.FullName.Replace("Nethermind.", "").Replace(".Metrics", "");

            docBuilder.AppendLine(@$ "# {moduleName}");
            docBuilder.AppendLine();
            moduleName = moduleName.ToLower();
            docBuilder.AppendLine("| Metric | Description |");
            docBuilder.AppendLine("| :--- | :--- |");

            if (moduleProperties.Length == 0)
            {
                return;
            }

            foreach (PropertyInfo property in moduleProperties)
            {
                Attribute attr = property.GetCustomAttribute(typeof(DescriptionAttribute));
                docBuilder.AppendLine($"| {GetMetricName(property.Name)} | {((DescriptionAttribute)attr)?.Description ?? ""} |");
            }
            _sharedContent.Save(moduleName, docsDir + "/ethereum-client/metrics", docBuilder);
        }
Exemple #2
0
        public void Generate()
        {
            string docsDir    = DocsDirFinder.FindDocsDir();
            string runnerDir  = DocsDirFinder.FindRunnerDir();
            string moduleName = "sample-configuration";

            string[] configs = { "mainnet.cfg", "goerli.cfg", "rinkeby.cfg", "ropsten.cfg" };

            StringBuilder docBuilder = new StringBuilder();

            docBuilder.AppendLine("---");
            docBuilder.AppendLine("description: Sample Fast Sync configurations for Nethermind");
            docBuilder.AppendLine("---");
            docBuilder.AppendLine();
            docBuilder.AppendLine("# Sample configuration");
            docBuilder.AppendLine();
            _markdownGenerator.OpenTabs(docBuilder);

            foreach (string config in configs)
            {
                _markdownGenerator.CreateTab(docBuilder, config);
                docBuilder.AppendLine("```yaml");
                string[] configData = File.ReadAllLines($"{runnerDir}/configs/{config}");

                foreach (string line in configData)
                {
                    docBuilder.AppendLine(line);
                }
                docBuilder.AppendLine("```");
                _markdownGenerator.CloseTab(docBuilder);
            }

            // Write sample docker-compose .env file
            var env = "mainnet_env";

            _markdownGenerator.CreateTab(docBuilder, env);
            docBuilder.AppendLine("```yaml");
            string[] envData = File.ReadAllLines($"./envs/{env}");

            foreach (string line in envData)
            {
                docBuilder.AppendLine(line);
            }
            docBuilder.AppendLine("```");
            _markdownGenerator.CloseTab(docBuilder);

            _markdownGenerator.CloseTabs(docBuilder);

            string path = string.Concat(docsDir, "/ethereum-client/configuration");

            _sharedContent.Save(moduleName, path, docBuilder);
        }
Exemple #3
0
        private void GenerateDocFileContent(Type configType, string docsDir)
        {
            Attribute attribute = configType.GetCustomAttribute(typeof(ConfigCategoryAttribute));

            if (((ConfigCategoryAttribute)attribute)?.HiddenFromDocs ?? false)
            {
                return;
            }

            StringBuilder docBuilder = new StringBuilder();
            string        moduleName = configType.Name.Substring(1).Replace("Config", "");

            PropertyInfo[] moduleProperties = configType.GetProperties().OrderBy(p => p.Name).ToArray();

            docBuilder.AppendLine(@$ "# {moduleName}");
            moduleName = moduleName.ToLower();
            docBuilder.AppendLine();
            docBuilder.AppendLine($"{((ConfigCategoryAttribute)attribute)?.Description ?? ""}");
            docBuilder.AppendLine();
            docBuilder.AppendLine("| Property | Description | Default |");
            docBuilder.AppendLine("| :--- | :--- | :--- |");

            if (moduleProperties.Length == 0)
            {
                return;
            }

            foreach (PropertyInfo property in moduleProperties)
            {
                Attribute attr = property.GetCustomAttribute(typeof(ConfigItemAttribute));
                if (((ConfigItemAttribute)attr)?.HiddenFromDocs ?? false)
                {
                    continue;
                }
                docBuilder.AppendLine($"| {property.Name} | {((ConfigItemAttribute)attr)?.Description ?? ""} | {((ConfigItemAttribute)attr)?.DefaultValue ?? ""} |");
            }

            string path = string.Concat(docsDir, "/ethereum-client/configuration");

            _sharedContent.Save(moduleName, path, docBuilder);
        }
Exemple #4
0
        private void GenerateDocFileContent(Type rpcType, string docsDir)
        {
            StringBuilder docBuilder = new StringBuilder();

            string moduleName = rpcType.Name.Substring(1).Replace("Module", "");

            MethodInfo[] moduleMethods = rpcType.GetMethods().OrderBy(m => m.Name).ToArray();
            List <Type>  rpcTypesToDescribe;

            docBuilder.AppendLine(@$ "# {moduleName}");
            docBuilder.AppendLine();
            moduleName = moduleName.ToLower();

            foreach (MethodInfo method in moduleMethods)
            {
                JsonRpcMethodAttribute attribute = method.GetCustomAttribute <JsonRpcMethodAttribute>();
                bool isImplemented = attribute == null || attribute.IsImplemented;

                if (!isImplemented)
                {
                    continue;
                }

                string methodName = method.Name.Substring(method.Name.IndexOf('_'));
                docBuilder.AppendLine(@$ "## {moduleName}{methodName}");
                docBuilder.AppendLine();
                docBuilder.AppendLine(@$ "{attribute?.Description ?? " "} ");
                docBuilder.AppendLine();
                _markdownGenerator.OpenTabs(docBuilder);
                _markdownGenerator.CreateTab(docBuilder, "Request");
                docBuilder.AppendLine(@"### **Parameters**");
                docBuilder.AppendLine();

                ParameterInfo[] parameters = method.GetParameters();
                rpcTypesToDescribe = new List <Type>();

                if (parameters.Length == 0)
                {
                    docBuilder.AppendLine("_None_");
                }
                else
                {
                    docBuilder.AppendLine("| Parameter name | Type |");
                    docBuilder.AppendLine("| :--- | :--- |");
                    string rpcParameterType;
                    foreach (ParameterInfo parameter in method.GetParameters())
                    {
                        rpcParameterType = _sharedContent.GetTypeToWrite(parameter.ParameterType, rpcTypesToDescribe);
                        docBuilder.AppendLine($"| {parameter.Name} | `{rpcParameterType}` |");
                    }
                }

                _markdownGenerator.CloseTab(docBuilder);
                docBuilder.AppendLine();
                _markdownGenerator.CreateTab(docBuilder, "Response");
                docBuilder.AppendLine(@$ "### Return type");
                docBuilder.AppendLine();

                Type   returnType    = GetTypeFromWrapper(method.ReturnType);
                string returnRpcType = _sharedContent.GetTypeToWrite(returnType, rpcTypesToDescribe);

                docBuilder.AppendLine(@$ "`{returnRpcType}`");

                _markdownGenerator.CloseTab(docBuilder);

                if (rpcTypesToDescribe.Count != 0)
                {
                    docBuilder.AppendLine();
                    _markdownGenerator.CreateTab(docBuilder, "Object definitions");
                    _sharedContent.AddObjectsDescription(docBuilder, rpcTypesToDescribe);
                    _markdownGenerator.CloseTab(docBuilder);
                }

                _markdownGenerator.CloseTabs(docBuilder);
                docBuilder.AppendLine();
            }

            _sharedContent.Save(moduleName, docsDir + "/json-rpc-modules", docBuilder);
        }
        private void GenerateDocFileContent(string moduleName, Dictionary <string, MethodData> moduleMethods, string docsDir)
        {
            StringBuilder rpcBuilder = new StringBuilder();
            StringBuilder cliBuilder = new StringBuilder();

            rpcBuilder.AppendLine($"# {moduleName}");
            rpcBuilder.AppendLine();

            cliBuilder.AppendLine($"# {moduleName}");
            cliBuilder.AppendLine();

            string[] methodsNames = moduleMethods.Keys.OrderBy(n => n).ToArray();
            foreach (string methodName in methodsNames)
            {
                moduleMethods.TryGetValue(methodName, out MethodData methodData);

                if (methodData == null)
                {
                    continue;
                }

                string rpcMethodName = $"{moduleName}_{methodName}";
                string cliMethodName = $"{moduleName}.{methodName}";


                ParameterInfo[] parameters       = methodData.Parameters;
                List <string>   defaultArguments = new List <string>();
                List <string>   exampleArguments = new List <string>();
                List <Type>     typesToDescribe  = new List <Type>();

                StringBuilder paramBuilder   = new StringBuilder();
                StringBuilder returnBuilder  = new StringBuilder();
                StringBuilder objectsBuilder = new StringBuilder();


                if (parameters.Length > 0)
                {
                    paramBuilder.AppendLine("| Parameter | Type | Description |");
                    paramBuilder.AppendLine("| :--- | :--- | :--- |");
                    foreach (ParameterInfo parameter in parameters)
                    {
                        JsonRpcParameterAttribute parameterAttribute =
                            parameter.GetCustomAttribute <JsonRpcParameterAttribute>();
                        string parameterType = _sharedContent.GetTypeToWrite(parameter.ParameterType, typesToDescribe);
                        paramBuilder.AppendLine(
                            $"| {parameter.Name} | `{parameterType}` | {parameterAttribute?.Description ?? ""} |");
                        defaultArguments.Add(parameter.Name);
                        if (parameterAttribute?.ExampleValue?.Length > 0)
                        {
                            exampleArguments.Add(parameterAttribute.ExampleValue);
                        }
                    }
                }
                else
                {
                    paramBuilder.AppendLine("| This method doesn't have parameters. |");
                    paramBuilder.AppendLine("| :--- |");
                }

                string rpcInvocation = _markdownGenerator.GetRpcInvocationExample(rpcMethodName, defaultArguments);
                string cliInvocation = _markdownGenerator.GetCliInvocationExample(cliMethodName, defaultArguments, methodData.IsFunction);

                if (exampleArguments.Count != defaultArguments.Count)
                {
                    exampleArguments = defaultArguments;
                }


                if (methodData.InvocationType != InvocationType.Cli)
                {
                    bool isImplemented = methodData.IsImplemented ?? true;
                    if (!isImplemented)
                    {
                        continue;
                    }

                    Type   returnType        = GetTypeFromWrapper(methodData.ReturnType);
                    string returnTypeToWrite = _sharedContent.GetTypeToWrite(returnType, typesToDescribe);
                    returnBuilder.AppendLine("| Returned type | Description |");
                    returnBuilder.AppendLine("| :--- | :--- |");
                    returnBuilder.AppendLine(@$ "| `{returnTypeToWrite}` | {methodData.ResponseDescription} |");

                    rpcBuilder.AppendLine($"## {rpcMethodName}");
                    TryAddDescription(rpcBuilder, methodData.Description);
                    TryAddHint(rpcBuilder, methodData.EdgeCaseHint);
                    cliBuilder.AppendLine();
                    rpcBuilder.AppendLine("| Invocation |");
                    rpcBuilder.AppendLine("| :--- |");
                    rpcBuilder.AppendLine($"| `{rpcInvocation}` |");
                    rpcBuilder.AppendLine();
                    rpcBuilder.Append(paramBuilder);
                    rpcBuilder.AppendLine();
                    rpcBuilder.Append(returnBuilder);
                    rpcBuilder.AppendLine();

                    _markdownGenerator.OpenTabs(rpcBuilder);
                    _markdownGenerator.CreateTab(rpcBuilder, $"Example request of {rpcMethodName}");
                    _markdownGenerator.CreateCurlExample(rpcBuilder, rpcMethodName, exampleArguments);
                    _markdownGenerator.CloseTab(rpcBuilder);

                    if (methodData.ExampleResponse != null)
                    {
                        string exampleResponse = CreateRpcExampleResponse(methodData.ExampleResponse);
                        _markdownGenerator.CreateTab(rpcBuilder, $"Example response of {rpcMethodName}");
                        _markdownGenerator.CreateCodeBlock(rpcBuilder, exampleResponse);
                        _markdownGenerator.CloseTab(rpcBuilder);
                    }

                    if (typesToDescribe.Count != 0)
                    {
                        objectsBuilder.AppendLine();
                        _markdownGenerator.CreateTab(objectsBuilder, $"Objects in {rpcMethodName}");
                        _sharedContent.AddObjectsDescription(objectsBuilder, typesToDescribe);
                        _markdownGenerator.CloseTab(objectsBuilder);
                    }

                    rpcBuilder.Append(objectsBuilder);
                    _markdownGenerator.CloseTabs(rpcBuilder);
                    rpcBuilder.AppendLine();

                    if (methodData.InvocationType == InvocationType.Both)
                    {
                        rpcBuilder.AppendLine($"[See also CLI {cliMethodName}](https://docs.nethermind.io/nethermind/nethermind-utilities/cli/{moduleName}#{moduleName.ToLower()}-{methodName.ToLower()})");

                        CreateCliContent(cliBuilder, paramBuilder, returnBuilder, objectsBuilder, cliMethodName, exampleArguments, cliInvocation, methodData);
                        cliBuilder.AppendLine($"[See also JSON RPC {rpcMethodName}](https://docs.nethermind.io/nethermind/ethereum-client/json-rpc/{moduleName}#{rpcMethodName.ToLower()})");
                    }
                }
                else
                {
                    Type   returnType        = methodData.ReturnType;
                    string returnTypeToWrite = _sharedContent.GetTypeToWrite(returnType, typesToDescribe);
                    returnBuilder.AppendLine("| Returned type | Description |");
                    returnBuilder.AppendLine("| :--- | :--- |");
                    returnBuilder.AppendLine(@$ "| `{returnTypeToWrite}` | {methodData.ResponseDescription} |");

                    CreateCliContent(cliBuilder, paramBuilder, returnBuilder, objectsBuilder, cliMethodName, exampleArguments, cliInvocation, methodData);
                }
            }

            int emptyModuleLength = "# only_some_module_name".Length;

            if (rpcBuilder.Length > emptyModuleLength)
            {
                _sharedContent.Save(moduleName, string.Concat(docsDir, "/ethereum-client/json-rpc"), rpcBuilder);
            }
            if (cliBuilder.Length > emptyModuleLength)
            {
                _sharedContent.Save(moduleName, string.Concat(docsDir, "/nethermind-utilities/cli"), cliBuilder);
            }
        }