public void WhenInputOpenapiJson()
        {
            var openapiJson = "{\"openapi\":\"3.0.1\",\"info\":{\"title\":\"SwaggerPetstore\",\"description\":\"ThisisasampleserverPetstoreserver.YoucanfindoutmoreaboutSwaggerat[http://swagger.io](http://swagger.io)oron[irc.freenode.net,#swagger](http://swagger.io/irc/).Forthissample,youcanusetheapikey`special-key`totesttheauthorizationfilters.\",\"termsOfService\":\"http://swagger.io/terms/\",\"contact\":{\"email\":\"[email protected]\"},\"license\":{\"name\":\"Apache2.0\",\"url\":\"http://www.apache.org/licenses/LICENSE-2.0.html\"},\"version\":\"1.0.0\"},\"externalDocs\":{\"description\":\"FindoutmoreaboutSwagger\",\"url\":\"http://swagger.io\"},\"servers\":[{\"url\":\"https://petstore.swagger.io/v2\"},{\"url\":\"http://petstore.swagger.io/v2\"}],\"tags\":[{\"name\":\"pet\",\"description\":\"EverythingaboutyourPets\",\"externalDocs\":{\"description\":\"Findoutmore\",\"url\":\"http://swagger.io\"}},{\"name\":\"store\",\"description\":\"AccesstoPetstoreorders\"},{\"name\":\"user\",\"description\":\"Operationsaboutuser\",\"externalDocs\":{\"description\":\"Findoutmoreaboutourstore\",\"url\":\"http://swagger.io\"}}],\"paths\":{\"/pet\":{\"put\":{\"tags\":[\"pet\"],\"summary\":\"Updateanexistingpet\",\"operationId\":\"updatePet\",\"requestBody\":{\"description\":\"Petobjectthatneedstobeaddedtothestore\",\"content\":{\"application/json\":{\"schema\":{\"$ref\":\"#/components/schemas/Pet\"}},\"application/xml\":{\"schema\":{\"$ref\":\"#/components/schemas/Pet\"}}},\"required\":true},\"responses\":{\"400\":{\"description\":\"InvalidIDsupplied\",\"content\":{}},\"404\":{\"description\":\"Petnotfound\",\"content\":{}},\"405\":{\"description\":\"Validationexception\",\"content\":{}}},\"security\":[{\"petstore_auth\":[\"write:pets\",\"read:pets\"]}],\"x-codegen-request-body-name\":\"body\"},\"post\":{\"tags\":[\"pet\"],\"summary\":\"Addanewpettothestore\",\"operationId\":\"addPet\",\"requestBody\":{\"description\":\"Petobjectthatneedstobeaddedtothestore\",\"content\":{\"application/json\":{\"schema\":{\"$ref\":\"#/components/schemas/Pet\"}},\"application/xml\":{\"schema\":{\"$ref\":\"#/components/schemas/Pet\"}}},\"required\":true},\"responses\":{\"405\":{\"description\":\"Invalidinput\",\"content\":{}}},\"security\":[{\"petstore_auth\":[\"write:pets\",\"read:pets\"]}],\"x-codegen-request-body-name\":\"body\"}},\"/pet/findByStatus\":{\"get\":{\"tags\":[\"pet\"],\"summary\":\"FindsPetsbystatus\",\"description\":\"Multiplestatusvaluescanbeprovidedwithcommaseparatedstrings\",\"operationId\":\"findPetsByStatus\",\"parameters\":[{\"name\":\"status\",\"in\":\"query\",\"description\":\"Statusvaluesthatneedtobeconsideredforfilter\",\"required\":true,\"style\":\"form\",\"explode\":true,\"schema\":{\"type\":\"array\",\"items\":{\"type\":\"string\",\"default\":\"available\",\"enum\":[\"available\",\"pending\",\"sold\"]}}}],\"responses\":{\"200\":{\"description\":\"successfuloperation\",\"content\":{\"application/xml\":{\"schema\":{\"type\":\"array\",\"items\":{\"$ref\":\"#/components/schemas/Pet\"}}},\"application/json\":{\"schema\":{\"type\":\"array\",\"items\":{\"$ref\":\"#/components/schemas/Pet\"}}}}},\"400\":{\"description\":\"Invalidstatusvalue\",\"content\":{}}},\"security\":[{\"petstore_auth\":[\"write:pets\",\"read:pets\"]}]}},\"/pet/findByTags\":{\"get\":{\"tags\":[\"pet\"],\"summary\":\"FindsPetsbytags\",\"description\":\"Mulipletagscanbeprovidedwithcommaseparatedstrings.Usetag1,tag2,tag3fortesting.\",\"operationId\":\"findPetsByTags\",\"parameters\":[{\"name\":\"tags\",\"in\":\"query\",\"description\":\"Tagstofilterby\",\"required\":true,\"style\":\"form\",\"explode\":true,\"schema\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}}}],\"responses\":{\"200\":{\"description\":\"successfuloperation\",\"content\":{\"application/xml\":{\"schema\":{\"type\":\"array\",\"items\":{\"$ref\":\"#/components/schemas/Pet\"}}},\"application/json\":{\"schema\":{\"type\":\"array\",\"items\":{\"$ref\":\"#/components/schemas/Pet\"}}}}},\"400\":{\"description\":\"Invalidtagvalue\",\"content\":{}}},\"deprecated\":true,\"security\":[{\"petstore_auth\":[\"write:pets\",\"read:pets\"]}]}},\"/pet/{petId}\":{\"get\":{\"tags\":[\"pet\"],\"summary\":\"FindpetbyID\",\"description\":\"Returnsasinglepet\",\"operationId\":\"getPetById\",\"parameters\":[{\"name\":\"petId\",\"in\":\"path\",\"description\":\"IDofpettoreturn\",\"required\":true,\"schema\":{\"type\":\"integer\",\"format\":\"int64\"}}],\"responses\":{\"200\":{\"description\":\"successfuloperation\",\"content\":{\"application/xml\":{\"schema\":{\"$ref\":\"#/components/schemas/Pet\"}},\"application/json\":{\"schema\":{\"$ref\":\"#/components/schemas/Pet\"}}}},\"400\":{\"description\":\"InvalidIDsupplied\",\"content\":{}},\"404\":{\"description\":\"Petnotfound\",\"content\":{}}},\"security\":[{\"api_key\":[]}]},\"post\":{\"tags\":[\"pet\"],\"summary\":\"Updatesapetinthestorewithformdata\",\"operationId\":\"updatePetWithForm\",\"parameters\":[{\"name\":\"petId\",\"in\":\"path\",\"description\":\"IDofpetthatneedstobeupdated\",\"required\":true,\"schema\":{\"type\":\"integer\",\"format\":\"int64\"}}],\"requestBody\":{\"content\":{\"application/x-www-form-urlencoded\":{\"schema\":{\"properties\":{\"name\":{\"type\":\"string\",\"description\":\"Updatednameofthepet\"},\"status\":{\"type\":\"string\",\"description\":\"Updatedstatusofthepet\"}}}}}},\"responses\":{\"405\":{\"description\":\"Invalidinput\",\"content\":{}}},\"security\":[{\"petstore_auth\":[\"write:pets\",\"read:pets\"]}]},\"delete\":{\"tags\":[\"pet\"],\"summary\":\"Deletesapet\",\"operationId\":\"deletePet\",\"parameters\":[{\"name\":\"api_key\",\"in\":\"header\",\"schema\":{\"type\":\"string\"}},{\"name\":\"petId\",\"in\":\"path\",\"description\":\"Petidtodelete\",\"required\":true,\"schema\":{\"type\":\"integer\",\"format\":\"int64\"}}],\"responses\":{\"400\":{\"description\":\"InvalidIDsupplied\",\"content\":{}},\"404\":{\"description\":\"Petnotfound\",\"content\":{}}},\"security\":[{\"petstore_auth\":[\"write:pets\",\"read:pets\"]}]}},\"/pet/{petId}/uploadImage\":{\"post\":{\"tags\":[\"pet\"],\"summary\":\"uploadsanimage\",\"operationId\":\"uploadFile\",\"parameters\":[{\"name\":\"petId\",\"in\":\"path\",\"description\":\"IDofpettoupdate\",\"required\":true,\"schema\":{\"type\":\"integer\",\"format\":\"int64\"}}],\"requestBody\":{\"content\":{\"multipart/form-data\":{\"schema\":{\"properties\":{\"additionalMetadata\":{\"type\":\"string\",\"description\":\"Additionaldatatopasstoserver\"},\"file\":{\"type\":\"string\",\"description\":\"filetoupload\",\"format\":\"binary\"}}}}}},\"responses\":{\"200\":{\"description\":\"successfuloperation\",\"content\":{\"application/json\":{\"schema\":{\"$ref\":\"#/components/schemas/ApiResponse\"}}}}},\"security\":[{\"petstore_auth\":[\"write:pets\",\"read:pets\"]}]}},\"/store/inventory\":{\"get\":{\"tags\":[\"store\"],\"summary\":\"Returnspetinventoriesbystatus\",\"description\":\"Returnsamapofstatuscodestoquantities\",\"operationId\":\"getInventory\",\"responses\":{\"200\":{\"description\":\"successfuloperation\",\"content\":{\"application/json\":{\"schema\":{\"type\":\"object\",\"additionalProperties\":{\"type\":\"integer\",\"format\":\"int32\"}}}}}},\"security\":[{\"api_key\":[]}]}},\"/store/order\":{\"post\":{\"tags\":[\"store\"],\"summary\":\"Placeanorderforapet\",\"operationId\":\"placeOrder\",\"requestBody\":{\"description\":\"orderplacedforpurchasingthepet\",\"content\":{\"*/*\":{\"schema\":{\"$ref\":\"#/components/schemas/Order\"}}},\"required\":true},\"responses\":{\"200\":{\"description\":\"successfuloperation\",\"content\":{\"application/xml\":{\"schema\":{\"$ref\":\"#/components/schemas/Order\"}},\"application/json\":{\"schema\":{\"$ref\":\"#/components/schemas/Order\"}}}},\"400\":{\"description\":\"InvalidOrder\",\"content\":{}}},\"x-codegen-request-body-name\":\"body\"}},\"/store/order/{orderId}\":{\"get\":{\"tags\":[\"store\"],\"summary\":\"FindpurchaseorderbyID\",\"description\":\"ForvalidresponsetryintegerIDswithvalue>=1and<=10.Othervalueswillgeneratedexceptions\",\"operationId\":\"getOrderById\",\"parameters\":[{\"name\":\"orderId\",\"in\":\"path\",\"description\":\"IDofpetthatneedstobefetched\",\"required\":true,\"schema\":{\"maximum\":10,\"minimum\":1,\"type\":\"integer\",\"format\":\"int64\"}}],\"responses\":{\"200\":{\"description\":\"successfuloperation\",\"content\":{\"application/xml\":{\"schema\":{\"$ref\":\"#/components/schemas/Order\"}},\"application/json\":{\"schema\":{\"$ref\":\"#/components/schemas/Order\"}}}},\"400\":{\"description\":\"InvalidIDsupplied\",\"content\":{}},\"404\":{\"description\":\"Ordernotfound\",\"content\":{}}}},\"delete\":{\"tags\":[\"store\"],\"summary\":\"DeletepurchaseorderbyID\",\"description\":\"ForvalidresponsetryintegerIDswithpositiveintegervalue.Negativeornon-integervalueswillgenerateAPIerrors\",\"operationId\":\"deleteOrder\",\"parameters\":[{\"name\":\"orderId\",\"in\":\"path\",\"description\":\"IDoftheorderthatneedstobedeleted\",\"required\":true,\"schema\":{\"minimum\":1,\"type\":\"integer\",\"format\":\"int64\"}}],\"responses\":{\"400\":{\"description\":\"InvalidIDsupplied\",\"content\":{}},\"404\":{\"description\":\"Ordernotfound\",\"content\":{}}}}},\"/user\":{\"post\":{\"tags\":[\"user\"],\"summary\":\"Createuser\",\"description\":\"Thiscanonlybedonebytheloggedinuser.\",\"operationId\":\"createUser\",\"requestBody\":{\"description\":\"Createduserobject\",\"content\":{\"*/*\":{\"schema\":{\"$ref\":\"#/components/schemas/User\"}}},\"required\":true},\"responses\":{\"default\":{\"description\":\"successfuloperation\",\"content\":{}}},\"x-codegen-request-body-name\":\"body\"}},\"/user/createWithArray\":{\"post\":{\"tags\":[\"user\"],\"summary\":\"Createslistofuserswithgiveninputarray\",\"operationId\":\"createUsersWithArrayInput\",\"requestBody\":{\"description\":\"Listofuserobject\",\"content\":{\"*/*\":{\"schema\":{\"type\":\"array\",\"items\":{\"$ref\":\"#/components/schemas/User\"}}}},\"required\":true},\"responses\":{\"default\":{\"description\":\"successfuloperation\",\"content\":{}}},\"x-codegen-request-body-name\":\"body\"}},\"/user/createWithList\":{\"post\":{\"tags\":[\"user\"],\"summary\":\"Createslistofuserswithgiveninputarray\",\"operationId\":\"createUsersWithListInput\",\"requestBody\":{\"description\":\"Listofuserobject\",\"content\":{\"*/*\":{\"schema\":{\"type\":\"array\",\"items\":{\"$ref\":\"#/components/schemas/User\"}}}},\"required\":true},\"responses\":{\"default\":{\"description\":\"successfuloperation\",\"content\":{}}},\"x-codegen-request-body-name\":\"body\"}},\"/user/login\":{\"get\":{\"tags\":[\"user\"],\"summary\":\"Logsuserintothesystem\",\"operationId\":\"loginUser\",\"parameters\":[{\"name\":\"username\",\"in\":\"query\",\"description\":\"Theusernameforlogin\",\"required\":true,\"schema\":{\"type\":\"string\"}},{\"name\":\"password\",\"in\":\"query\",\"description\":\"Thepasswordforloginincleartext\",\"required\":true,\"schema\":{\"type\":\"string\"}}],\"responses\":{\"200\":{\"description\":\"successfuloperation\",\"headers\":{\"X-Rate-Limit\":{\"description\":\"callsperhourallowedbytheuser\",\"schema\":{\"type\":\"integer\",\"format\":\"int32\"}},\"X-Expires-After\":{\"description\":\"dateinUTCwhentokenexpires\",\"schema\":{\"type\":\"string\",\"format\":\"date-time\"}}},\"content\":{\"application/xml\":{\"schema\":{\"type\":\"string\"}},\"application/json\":{\"schema\":{\"type\":\"string\"}}}},\"400\":{\"description\":\"Invalidusername/passwordsupplied\",\"content\":{}}}}},\"/user/logout\":{\"get\":{\"tags\":[\"user\"],\"summary\":\"Logsoutcurrentloggedinusersession\",\"operationId\":\"logoutUser\",\"responses\":{\"default\":{\"description\":\"successfuloperation\",\"content\":{}}}}},\"/user/{username}\":{\"get\":{\"tags\":[\"user\"],\"summary\":\"Getuserbyusername\",\"operationId\":\"getUserByName\",\"parameters\":[{\"name\":\"username\",\"in\":\"path\",\"description\":\"Thenamethatneedstobefetched.Useuser1fortesting.\",\"required\":true,\"schema\":{\"type\":\"string\"}}],\"responses\":{\"200\":{\"description\":\"successfuloperation\",\"content\":{\"application/xml\":{\"schema\":{\"$ref\":\"#/components/schemas/User\"}},\"application/json\":{\"schema\":{\"$ref\":\"#/components/schemas/User\"}}}},\"400\":{\"description\":\"Invalidusernamesupplied\",\"content\":{}},\"404\":{\"description\":\"Usernotfound\",\"content\":{}}}},\"put\":{\"tags\":[\"user\"],\"summary\":\"Updateduser\",\"description\":\"Thiscanonlybedonebytheloggedinuser.\",\"operationId\":\"updateUser\",\"parameters\":[{\"name\":\"username\",\"in\":\"path\",\"description\":\"namethatneedtobeupdated\",\"required\":true,\"schema\":{\"type\":\"string\"}}],\"requestBody\":{\"description\":\"Updateduserobject\",\"content\":{\"*/*\":{\"schema\":{\"$ref\":\"#/components/schemas/User\"}}},\"required\":true},\"responses\":{\"400\":{\"description\":\"Invalidusersupplied\",\"content\":{}},\"404\":{\"description\":\"Usernotfound\",\"content\":{}}},\"x-codegen-request-body-name\":\"body\"},\"delete\":{\"tags\":[\"user\"],\"summary\":\"Deleteuser\",\"description\":\"Thiscanonlybedonebytheloggedinuser.\",\"operationId\":\"deleteUser\",\"parameters\":[{\"name\":\"username\",\"in\":\"path\",\"description\":\"Thenamethatneedstobedeleted\",\"required\":true,\"schema\":{\"type\":\"string\"}}],\"responses\":{\"400\":{\"description\":\"Invalidusernamesupplied\",\"content\":{}},\"404\":{\"description\":\"Usernotfound\",\"content\":{}}}}}},\"components\":{\"schemas\":{\"Order\":{\"type\":\"object\",\"properties\":{\"id\":{\"type\":\"integer\",\"format\":\"int64\"},\"petId\":{\"type\":\"integer\",\"format\":\"int64\"},\"quantity\":{\"type\":\"integer\",\"format\":\"int32\"},\"shipDate\":{\"type\":\"string\",\"format\":\"date-time\"},\"status\":{\"type\":\"string\",\"description\":\"OrderStatus\",\"enum\":[\"placed\",\"approved\",\"delivered\"]},\"complete\":{\"type\":\"boolean\",\"default\":false}},\"xml\":{\"name\":\"Order\"}},\"Category\":{\"type\":\"object\",\"properties\":{\"id\":{\"type\":\"integer\",\"format\":\"int64\"},\"name\":{\"type\":\"string\"}},\"xml\":{\"name\":\"Category\"}},\"User\":{\"type\":\"object\",\"properties\":{\"id\":{\"type\":\"integer\",\"format\":\"int64\"},\"username\":{\"type\":\"string\"},\"firstName\":{\"type\":\"string\"},\"lastName\":{\"type\":\"string\"},\"email\":{\"type\":\"string\"},\"password\":{\"type\":\"string\"},\"phone\":{\"type\":\"string\"},\"userStatus\":{\"type\":\"integer\",\"description\":\"UserStatus\",\"format\":\"int32\"}},\"xml\":{\"name\":\"User\"}},\"Tag\":{\"type\":\"object\",\"properties\":{\"id\":{\"type\":\"integer\",\"format\":\"int64\"},\"name\":{\"type\":\"string\"}},\"xml\":{\"name\":\"Tag\"}},\"Pet\":{\"required\":[\"name\",\"photoUrls\"],\"type\":\"object\",\"properties\":{\"id\":{\"type\":\"integer\",\"format\":\"int64\"},\"category\":{\"$ref\":\"#/components/schemas/Category\"},\"name\":{\"type\":\"string\",\"example\":\"doggie\"},\"photoUrls\":{\"type\":\"array\",\"xml\":{\"name\":\"photoUrl\",\"wrapped\":true},\"items\":{\"type\":\"string\"}},\"tags\":{\"type\":\"array\",\"xml\":{\"name\":\"tag\",\"wrapped\":true},\"items\":{\"$ref\":\"#/components/schemas/Tag\"}},\"status\":{\"type\":\"string\",\"description\":\"petstatusinthestore\",\"enum\":[\"available\",\"pending\",\"sold\"]}},\"xml\":{\"name\":\"Pet\"}},\"ApiResponse\":{\"type\":\"object\",\"properties\":{\"code\":{\"type\":\"integer\",\"format\":\"int32\"},\"type\":{\"type\":\"string\"},\"message\":{\"type\":\"string\"}}}},\"securitySchemes\":{\"petstore_auth\":{\"type\":\"oauth2\",\"flows\":{\"implicit\":{\"authorizationUrl\":\"http://petstore.swagger.io/oauth/dialog\",\"scopes\":{\"write:pets\":\"modifypetsinyouraccount\",\"read:pets\":\"readyourpets\"}}}},\"api_key\":{\"type\":\"apiKey\",\"name\":\"api_key\",\"in\":\"header\"}}}}";
            var result      = CheckKeywords.GetCheckType(openapiJson);

            Assert.IsTrue(result == EnumCheckType.OpenApi);
        }
示例#2
0
        public ActionResult Check(string str)
        {
            var result = CheckKeywords.Check(str);
            var agent  = HttpContext.Request.Headers[HeaderNames.UserAgent][0].ToLower();

            if (PLAIN_TEXT_AGENTS.Any(t => agent.Contains(t)))
            {
                return(Content(ConvertCLI(result)));
            }
            return(new JsonResult(result));
        }
示例#3
0
        private async Task Check()
        {
            try
            {
                if (string.IsNullOrEmpty(Param))
                {
                    return;
                }

                if (Uri.IsWellFormedUriString(Param, UriKind.Absolute))
                {
                    SwaggerUrl = Param;
                    Param      = "loading..";
                    Param      = await Client.GetStringAsync(SwaggerUrl);
                }

                Result = CheckKeywords.Check(Param, SelectedLanguageNames.ToList());
                if (Result.Result != 1)
                {
                    var ParamWithTag = Param;
                    var keywords     = Result.Items.SelectMany(t => t.Words).Distinct().ToList();
                    var regTag       = Param.Contains("\"") ? "\"" : ",| ";
                    var keywordsStr  = string.Join("|", keywords);
                    var regex        = $"(?<=({regTag}|^))({keywordsStr})(?=({regTag}|$))";

                    ParamWithTag = Regex.Replace(ParamWithTag, regex, "<code>$2</code>");

                    //await JS.InvokeVoidAsync("csfunc.appendHtml", @"AAA", z);
                    ShowResultFragment = true;
                    ResultFragment     = (builder) => builder.AddMarkupContent(0, ParamWithTag);
                }
                else
                {
                    ShowResultFragment = false;
                }
            }
            catch (HttpRequestException)
            {
                ErrorInfo  = "error, please check your swagger url";
                Param      = SwaggerUrl;
                SwaggerUrl = string.Empty;
                Result     = new CheckResult
                {
                    Result = 0
                };
            }
            catch (Exception)
            {
                Result = new CheckResult
                {
                    Result = 0
                };
            }
        }
示例#4
0
 private void Check()
 {
     try
     {
         Result = CheckKeywords.Check(Param);
     }
     catch
     {
         Result = new CheckResult
         {
             Result = 0
         };
     }
 }
示例#5
0
        public void Test1()
        {
            var result = CheckKeywords.Check("public,function");

            if (result.Result == 3 && result.Items.Any(t => t.Type == 1 && t.Language == "C#") &&
                result.Items.Any(t => t.Type == 2 && t.Language == "javascript") &&
                result.Items.Any(t => t.Type == 1 && t.Language == "javascript"))
            {
                Assert.Pass("pass");
            }
            else
            {
                Assert.Fail("fail");
            }
        }
示例#6
0
        public ActionResult Check(string str)
        {
            var needCheckValue = Uri.UnescapeDataString(str);

            if (Uri.IsWellFormedUriString(needCheckValue, UriKind.Absolute))
            {
                var httpClient = new HttpClient();
                str = httpClient.GetStringAsync(needCheckValue).Result;
            }

            var result = CheckKeywords.Check(str);
            var agent  = HttpContext.Request.Headers[HeaderNames.UserAgent][0].ToLower();

            if (PLAIN_TEXT_AGENTS.Any(t => agent.Contains(t)))
            {
                return(Content(ConvertCLI(result)));
            }
            return(new JsonResult(result));
        }
示例#7
0
        private void Check()
        {
            var x = CheckKeywords.Check(param);

            Result = x;
        }
        public void WhenInputInvalidJsonReturnFalse(string jsonStr)
        {
            var result = CheckKeywords.GetCheckType(jsonStr);

            Assert.IsFalse(result == EnumCheckType.Json);
        }
        public void WhenInputJsonReturnTrue(string jsonStr)
        {
            var result = CheckKeywords.GetCheckType(jsonStr);

            Assert.IsTrue(result == EnumCheckType.Json);
        }