我正在使用它放心并验证JSON模式。我使用jsonschema.net(草案7)生成了模式,并将生成的模式保存在文件中,并将生成的模式与GET API的响应进行匹配。 但是输出错误的代码如下:
Actual: {"success":true,"message":"FacilityAttributes List","error":{},"result":[{"id":"aa2cdb2e-89cd-4970-a976-42df3349df74","name":"INTERNATIONAL","rank":null,"data_type":"BOOLEAN","default_value":"false","mandatory":false,"business_unit":"TRA","options":null,"facility_type":null,"group_name":"BusinessType","description":"Please check if facility is international!"},{"id":"144e7c1c-9df4-4c65-ae7e-685013566731","name":"HEAVY","rank":null,"data_type":"BOOLEAN","default_value":"false","mandatory":false,"business_unit":"TRA","options":null,"facility_type":null,"group_name":"BusinessType","description":"Please check if facility can handle heavy goods!"},{"id":"ca20c185-4c9a-425e-82e4-a5b244b5ef9d","name":"B2B","rank":5,"data_type":"BOOLEAN","default_value":"false","mandatory":false,"business_unit":"TRA","options":null,"facility_type":null,"group_name":"BusinessType","description":null},{"id":"12a2c7f3-7da7-4682-953c-2e06ab8c8335","name":"B2C","rank":4,"data_type":"BOOLEAN","default_value":"false","mandatory":false,"business_unit":"TRA","options":null,"facility_type":null,"group_name":"BusinessType","description":null},{"id":"34ef64ee-33dc-43ea-9ef0-722aeb2377f8","name":"HLD","rank":2,"data_type":"BOOLEAN","default_value":"false","mandatory":false,"business_unit":"TRA","options":null,"facility_type":null,"group_name":"BusinessType","description":null},{"id":"5147ec36-59ac-4843-9f46-a881548e33aa","name":"dock_count","rank":null,"data_type":"INTEGER","default_value":"0","mandatory":false,"business_unit":"TRA","options":null,"facility_type":null,"group_name":"Facility Attributes","description":"Dock Door count in Facility!"},{"id":"1bdd7e0f-3a47-4d57-b641-439ba8790e48","name":"capacity","rank":null,"data_type":"INTEGER","default_value":"0","mandatory":false,"business_unit":"TRA","options":null,"facility_type":null,"group_name":"Facility Attributes","description":"Facility Capacity!"},{"id":"16e81b0c-fe3b-4827-bcf0-dbfd6f2cc386","name":"dimention_unit","rank":null,"data_type":"OPTION","default_value":"CM","mandatory":false,"business_unit":"TRA","options":["CM","IN"],"facility_type":null,"group_name":"Facility Attributes","description":"Dimention unit on facility works!"},{"id":"75569bc1-f5f0-40c1-8e36-f3ef88940486","name":"weight_unit","rank":null,"data_type":"OPTION","default_value":"KG","mandatory":false,"business_unit":"TRA","options":["KG","GM","LB"],"facility_type":null,"group_name":"Facility Attributes","description":"Weight unit on facility works!"},{"id":"48b121ba-e142-4f10-955c-12be4c33f787","name":"sort_code","rank":null,"data_type":"TEXT","default_value":null,"mandatory":false,"business_unit":"TRA","options":null,"facility_type":null,"group_name":"Facility Attributes","description":"Facility sort code!"},{"id":"dc5cc52c-2f65-4b92-beaa-d8165dfdc157","name":"slab_rate","rank":null,"data_type":"FLOAT","default_value":"0","mandatory":false,"business_unit":"TRA","options":null,"facility_type":null,"group_name":"Facility Attributes","description":"Slab rate of facility"},{"id":"d6b3ac6d-5f97-46a5-8e71-72b96f2aa419","name":"slab_type","rank":null,"data_type":"OPTION","default_value":"Incentive Based","mandatory":false,"business_unit":"TRA","options":["Incentive Based","Fuel Based"],"facility_type":null,"group_name":"Facility Attributes","description":"Slab rate of facility"},{"id":"03654f31-150f-4420-837c-f22bda1bc476","name":"ProductivityBenchmark","rank":null,"data_type":"INTEGER","default_value":"0","mandatory":false,"business_unit":"TRA","options":null,"facility_type":null,"group_name":"Productivity","description":"Productivity Benchmark of facility!"},{"id":"ad471316-0858-4ed7-b817-7b554c780536","name":"ReverseDispatchCutoff","rank":null,"data_type":"TIME","default_value":"09:00","mandatory":false,"business_unit":"TRA","options":null,"facility_type":null,"group_name":"Facility Timings","description":"Reverse Dispatch Cutoff time"},{"id":"18041d87-a88d-4ed3-b457-9c6e96c2c250","name":"ForwardDispatchCutoff","rank":null,"data_type":"TIME","default_value":"12:00","mandatory":false,"business_unit":"TRA","options":null,"facility_type":null,"group_name":"Facility Timings","description":"Forward Dispatch Cutoff time"},{"id":"c3e677a7-5b21-4c6b-8384-27c936720177","name":"Implant_enabled","rank":13,"data_type":"BOOLEAN","default_value":"false","mandatory":false,"business_unit":"TRA","options":null,"facility_type":null,"group_name":"Flags","description":"Please check Implant is enabled in Facility!"},{"id":"0fcd0fbe-c448-455a-b825-8b1eb2fcc8b3","name":"DG_enabled","rank":12,"data_type":"BOOLEAN","default_value":"false","mandatory":false,"business_unit":"TRA","options":null,"facility_type":null,"group_name":"Flags","description":"Please check DG is enabled in Facility!"},{"id":"34067f20-ece0-4775-8596-4447f74c5084","name":"FMODx_enabled","rank":11,"data_type":"BOOLEAN","default_value":"false","mandatory":false,"business_unit":"TRA","options":null,"facility_type":null,"group_name":"Flags","description":"Please check Odx FM is enabled in Facility!"},{"id":"6237f744-e685-4aca-906a-48bd1bad9160","name":"FEApp_enabled","rank":9,"data_type":"BOOLEAN","default_value":"false","mandatory":false,"business_unit":"TRA","options":null,"facility_type":null,"group_name":"Flags","description":"Please check FE App is enabled in Facility!"},{"id":"5ceb5fd0-74db-46fc-97a1-afbbaabc3686","name":"PayTM_enabled","rank":8,"data_type":"BOOLEAN","default_value":"false","mandatory":false,"business_unit":"TRA","options":null,"facility_type":null,"group_name":"Flags","description":"Please check if PayTM is enabled in facility!"},{"id":"f69817cb-8662-4f38-b44b-fb875703e9cd","name":"CardOnDelivery_enabled","rank":7,"data_type":"BOOLEAN","default_value":"false","mandatory":false,"business_unit":"TRA","options":null,"facility_type":null,"group_name":"Flags","description":"Please check if Card On Delivery is enabled in facility!"},{"id":"a3bcf54b-d734-4f95-92fd-a15bb2a00be3","name":"BagGuide_enabled","rank":6,"data_type":"BOOLEAN","default_value":"false","mandatory":false,"business_unit":"TRA","options":null,"facility_type":null,"group_name":"Flags","description":"Please check if BagGuide is enabled in facility!"},{"id":"19cfc5d1-f5fb-4666-a13f-7519588e3bb2","name":"LMOdx_enabled","rank":5,"data_type":"BOOLEAN","default_value":"false","mandatory":false,"business_unit":"TRA","options":null,"facility_type":null,"group_name":"Flags","description":"Please check if LMOdx is enabled in facility!"},{"id":"dc99d927-5925-4b09-a686-9c0231259337","name":"Constellation_enabled","rank":4,"data_type":"BOOLEAN","default_value":"false","mandatory":false,"business_unit":"TRA","options":null,"facility_type":null,"group_name":"Flags","description":"Please check if Constellation is enabled in facility!"},{"id":"41ba47fe-ec23-4649-bf0b-51101e631e68","name":"Bagging_enabled","rank":3,"data_type":"BOOLEAN","default_value":"false","mandatory":false,"business_unit":"TRA","options":null,"facility_type":null,"group_name":"Flags","description":"Please check if Bagging is enabled in facility!"},{"id":"7ead8afd-2e98-4330-8e15-40d4cb944a3c","name":"MidMile_enabled","rank":2,"data_type":"BOOLEAN","default_value":"false","mandatory":false,"business_unit":"TRA","options":null,"facility_type":null,"group_name":"Flags","description":"Please check if MidMile is enabled in facility!"},{"id":"4b9ffcab-b5df-4f19-bbd9-52e208168039","name":"Sorter_enabled","rank":1,"data_type":"BOOLEAN","default_value":"false","mandatory":false,"business_unit":"TRA","options":null,"facility_type":null,"group_name":"Flags","description":"Please check if sorter is enabled in facility!"},{"id":"c81e981d-2c44-4bd7-9cc9-5ea20a3eaa3a","name":"Can_Handle_Palletised_Load","rank":null,"data_type":"BOOLEAN","default_value":"false","mandatory":false,"business_unit":"TRA","options":null,"facility_type":null,"group_name":"Flags","description":"Check if facility Can Handle Palletised Load"}]}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:77)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrap.callConstructor(ConstructorSite.java:84)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:247)
at io.restassured.internal.ResponseSpecificationImpl$HamcrestAssertionClosure.validate(ResponseSpecificationImpl.groovy:471)
at io.restassured.internal.ResponseSpecificationImpl$HamcrestAssertionClosure$validate$1.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at io.restassured.internal.ResponseSpecificationImpl.validateResponseIfRequired(ResponseSpecificationImpl.groovy:643)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
at io.restassured.internal.ResponseSpecificationImpl.content(ResponseSpecificationImpl.groovy:94)
at io.restassured.specification.ResponseSpecification$content$0.callCurrent(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:174)
at io.restassured.internal.ResponseSpecificationImpl.body(ResponseSpecificationImpl.groovy:244)
at io.restassured.internal.ValidatableResponseOptionsImpl.body(ValidatableResponseOptionsImpl.java:262)
at com.ums.api.AppTest.GetserData(AppTest.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:669)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:877)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1201)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:776)
at org.testng.TestRunner.run(TestRunner.java:634)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:425)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:420)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:385)
at org.testng.SuiteRunner.run(SuiteRunner.java:334)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1318)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1243)
at org.testng.TestNG.runSuites(TestNG.java:1161)
at org.testng.TestNG.run(TestNG.java:1129)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
我的生成模式是schema link
响应api API repsonse
答案 0 :(得分:0)
当前的REST Assured库可能会工作到草案4.我正在使用json-schema-generator工具在草案4中生成json模式并能够验证响应。
安装和生成架构的命令: -
npm install -g json-schema-generator
json-schema-generator path/to/input_response.json -o path/to/json_schema.json