Example #1
0
        private static void BuildParams(SwaggerPath.SwaggerPathApi path, StringBuilder stringBuild, SwaggerDocumentCoreV3 documentCoreV3)
        {
            stringBuild.Replace("${requestType}",
                                path.RequestBody != null
                    ? $"请求参数内容类型\n`{string.Join(", ", path.RequestBody.Content.Select(x => x.Key))}`"
                    : "");
            if (path.Parameters != null)
            {
                foreach (var parameter in path.Parameters)
                {
                    var @in = parameter.In;
                    if (@in == "body")
                    {
                        var inputKey = parameter.Schema.Ref.Substring(parameter.Schema.Ref.LastIndexOf("/", StringComparison.Ordinal) + 1);

                        ComplexProperty(documentCoreV3, stringBuild, inputKey, string.Empty, true);
                    }
                    else
                    {
                        var required = parameter.Required ? "是" : "否";

                        var des = string.IsNullOrWhiteSpace(parameter.Description) ? "无" : parameter.Description;
                        stringBuild.Replace("${params}", $"|{parameter.Name}|{required}|{parameter.Schema.Type}|{des}|{Environment.NewLine}${{params}}");
                    }
                }
            }
            else if (path.RequestBody != null)
            {
                var inputKey = path.RequestBody.Content.First().Value.Schema.Ref.Substring(path.RequestBody.Content.First().Value.Schema.Ref.LastIndexOf("/", StringComparison.Ordinal) + 1);

                ComplexProperty(documentCoreV3, stringBuild, inputKey, string.Empty, true);
            }
        }
Example #2
0
        private static void BuildResponseParams(SwaggerPath.SwaggerPathApi path, StringBuilder stringBuild, SwaggerDocumentCoreV3 documentCoreV3)
        {
            if (path.Responses == null || path.Responses.Count <= 0)
            {
                stringBuild.Replace("${responseType}", "");
                return;
            }
            var success = path.Responses.ContainsKey("Success") ? path.Responses["Success"] : null;

            if (success?.Content == null || success.Content.Count <= 0)
            {
                stringBuild.Replace("${responseType}", "");
                return;
            }
            stringBuild.Replace("${responseType}", $"响应内容类型\n`{string.Join(", ", success.Content.Select(x => x.Key))}`");

            var schema = success.Content.First().Value.Schema;

            if (string.IsNullOrWhiteSpace(schema.Ref))
            {
                if (schema.Items?.Ref != null)
                {
                    ComplexProperty(documentCoreV3, stringBuild, schema.Items.Ref.Substring(schema.Items.Ref.LastIndexOf("/", StringComparison.Ordinal) + 1), schema.Type + " -", false);
                    return;
                }
                ReplaceParams(stringBuild, string.Empty, schema.Type, schema.Type, schema.Type, false);
            }
            else
            {
                var key = schema.Ref.Substring(schema.Ref.LastIndexOf("/", StringComparison.Ordinal) + 1);
                ComplexProperty(documentCoreV3, stringBuild, key, string.Empty, false);
            }
        }
Example #3
0
        private static ShowDocRequest PathToRequest(SwaggerPath.SwaggerPathApi path, SwaggerDocumentCoreV3 documentCoreV3, string apiUrl, string httpMethod)
        {
            if (path == null)
            {
                return(null);
            }

            return(new ShowDocRequest
            {
                CatName = path.Tags[0].Replace(":", "").Replace("\n", "").Trim().Replace(" ", ""),
                PageTitle = path.Summary ?? apiUrl,
                PageContent = BuildMarkdown(path, documentCoreV3, apiUrl, httpMethod)
            });
        }
Example #4
0
        private static string BuildMarkdown(SwaggerPath.SwaggerPathApi path, SwaggerDocumentCoreV3 documentCoreV3, string apiUrl, string httpMethod)
        {
            var stringBuild = new StringBuilder(MarkdownTemplate);

            stringBuild.Replace("${ApiTitle}", path.Summary ?? apiUrl);
            stringBuild.Replace("${ApiUrl}", apiUrl);
            stringBuild.Replace("${HttpMethod} ", httpMethod);
            if (apiUrl.Contains("/api/TokenAuth/GetExternalAuthenticationProviders"))
            {
            }
            BuildParams(path, stringBuild, documentCoreV3);
            BuildResponseParams(path, stringBuild, documentCoreV3);

            stringBuild.Replace("${HttpMethod} ", httpMethod);

            var result = stringBuild.ToString();


            if (result.Contains("|参数名|必选|类型|说明|" + Environment.NewLine + "|:----|:---|:-----|-----|" + Environment.NewLine + "${params}"))
            {
                stringBuild.Replace("|参数名|必选|类型|说明|" + Environment.NewLine + "|:----|:---|:-----|-----|" + Environment.NewLine + "${params}", "无");
            }
            else
            {
                stringBuild.Replace("${params}", "");
            }
            if (result.Contains("|参数名|类型|说明|" + Environment.NewLine + "|:-----|:-----|-----|" + Environment.NewLine + "${responseParams}"))
            {
                stringBuild.Replace("|参数名|类型|说明|" + Environment.NewLine + "|:-----|:-----|-----|" + Environment.NewLine + "${responseParams}", "无");
            }
            else
            {
                stringBuild.Replace("${responseParams}", "");
            }

            return(stringBuild.ToString());
        }
Example #5
0
        private static void BuildResponseParams(SwaggerPath.SwaggerPathApi path, StringBuilder stringBuild, SwaggerDocumentCoreV2 document)
        {
            if (path.Produces != null && path.Produces.Length > 0)
            {
                stringBuild.Replace("${responseType}", $"响应内容类型\n`{string.Join(", ", path.Produces)}`");
            }
            else
            {
                stringBuild.Replace("${responseType}", "");
            }

            if (path.Responses == null || path.Responses.Count <= 0)
            {
                return;
            }
            var success = path.Responses.ContainsKey("Success") ? path.Responses["Success"] : null;

            if (success?.Schema == null)
            {
                return;
            }
            if (string.IsNullOrWhiteSpace(success.Schema.Ref))
            {
                if (success.Schema.Items?.Ref != null)
                {
                    ComplexProperty(document, stringBuild, success.Schema.Items.Ref.Substring(success.Schema.Items.Ref.LastIndexOf("/", StringComparison.Ordinal) + 1), success.Schema.Type + " -", false);
                    return;
                }
                ReplaceParams(stringBuild, string.Empty, success.Schema.Type, success.Schema.Type, success.Schema.Type, false);
            }
            else
            {
                var key = success.Schema.Ref.Substring(success.Schema.Ref.LastIndexOf("/", StringComparison.Ordinal) + 1);
                ComplexProperty(document, stringBuild, key, string.Empty, false);
            }
        }