Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

241 строка
6.9 KiB

  1. const dedent = require("dedent")
  2. describe("feature: `example` field support", function () {
  3. describe("Swagger 2", function() {
  4. beforeEach(function (client, done) {
  5. client
  6. .url("localhost:3230")
  7. .page.main()
  8. client.waitForElementVisible(".download-url-input:not([disabled])", 5000)
  9. .clearValue(".download-url-input")
  10. .setValue(".download-url-input", "/test-specs/features/example.swagger.yaml")
  11. .click("button.download-url-button")
  12. .waitForElementVisible(".opblock", 10000)
  13. .click("#operations-default-put_one")
  14. .waitForElementVisible("#operations-default-put_one.is-open", 5000)
  15. done()
  16. })
  17. afterEach(function (client, done) {
  18. done()
  19. })
  20. // Parameters
  21. // Supports complex root `example` values in Schema objects for bodies
  22. // Supports nested `example` values in Schema objects for bodies
  23. describe("primitive parameters", function() {
  24. it("should respect a primitive x-example value", function (client) {
  25. client
  26. .click("button.try-out__btn")
  27. .assert.value(
  28. `tr[data-param-name="ValidParam"] input[type="text"]`,
  29. `12345`
  30. )
  31. })
  32. it("should ignore a primitive example value", function (client) {
  33. client
  34. .click("button.try-out__btn")
  35. .assert.value(
  36. `tr[data-param-name="NotValidParam"] input[type="text"]`,
  37. ``
  38. )
  39. })
  40. })
  41. describe("object parameters", function() {
  42. it("should correctly consider property-level schema examples", function(client) {
  43. client.assert.containsText(`div[data-param-name="body"] pre`,
  44. dedent(`
  45. {
  46. "one": "hello!",
  47. "two": {
  48. "uno": "wow!",
  49. "dos": "hey there!"
  50. }
  51. }
  52. `)
  53. )
  54. })
  55. it("should correctly consider root schema-level schema examples", function(client) {
  56. client.assert.containsText(`div[data-param-name="body2"] pre`,
  57. dedent(`
  58. {
  59. "foo": "hey",
  60. "bar": 123
  61. }
  62. `)
  63. )
  64. })
  65. it("should correctly consider nested schema-level schema examples", function(client) {
  66. client.assert.containsText(`div[data-param-name="body3"] pre`,
  67. dedent(`
  68. {
  69. "one": {
  70. "uno": "woohoo!",
  71. "dos": "amazing!"
  72. }
  73. }
  74. `)
  75. )
  76. })
  77. })
  78. describe("responses", function() {
  79. it("should correctly consider schema-level examples", function (client) {
  80. client.assert.containsText(`tr.response[data-code="201"] pre`,
  81. dedent(`
  82. {
  83. "code": 201,
  84. "payload": [
  85. {
  86. "id": 1,
  87. "code": "AE2",
  88. "name": "Yono"
  89. }
  90. ]
  91. }
  92. `)
  93. )
  94. })
  95. it("should correctly consider property-level examples", function (client) {
  96. client.assert.containsText(`tr.response[data-code="202"] pre`,
  97. dedent(`
  98. {
  99. "code": 202,
  100. "payload": [
  101. {
  102. "id": 1,
  103. "code": "AE2",
  104. "name": "Yono"
  105. }
  106. ]
  107. }
  108. `)
  109. )
  110. })
  111. })
  112. })
  113. describe("OpenAPI 3.0", function() {
  114. beforeEach(function (client, done) {
  115. client
  116. .url("localhost:3230")
  117. .page.main()
  118. client.waitForElementVisible(".download-url-input:not([disabled])", 5000)
  119. .clearValue(".download-url-input")
  120. .setValue(".download-url-input", "/test-specs/features/example.openapi.yaml")
  121. .click("button.download-url-button")
  122. .waitForElementVisible(".opblock-summary-description", 10000)
  123. .click("#operations-agent-editAgent")
  124. .waitForElementVisible("#operations-agent-editAgent.is-open", 5000)
  125. done()
  126. })
  127. describe("parameters", function() {
  128. it("should respect a primitive example value", function(client) {
  129. client
  130. .click("button.try-out__btn")
  131. .assert.value(
  132. `div.parameters-container > div > table > tbody > tr > td.col.parameters-col_description > input[type="text"]`,
  133. `12345`
  134. )
  135. })
  136. })
  137. describe("request bodies", function() {
  138. it("should correctly consider media type-level examples", function (client) {
  139. client
  140. .click(`select.content-type option[value="application/json_media-type-level"]`)
  141. .assert.containsText(`pre.body-param__example`,
  142. dedent(`
  143. {
  144. "code": "AE1",
  145. "name": "Andrew"
  146. }
  147. `)
  148. )
  149. })
  150. it("should correctly consider schema-level examples", function (client) {
  151. client
  152. .click(`select.content-type option[value="application/json_schema-level"]`)
  153. .assert.containsText(`pre.body-param__example`,
  154. dedent(`
  155. {
  156. "code": "AE1",
  157. "name": "Andrew"
  158. }
  159. `)
  160. )
  161. })
  162. it("should correctly consider property-level examples", function (client) {
  163. client
  164. .click(`select.content-type option[value="application/json_property-level"]`)
  165. .assert.containsText(`pre.body-param__example`,
  166. dedent(`
  167. {
  168. "code": "AE1",
  169. "name": "Andrew"
  170. }
  171. `)
  172. )
  173. })
  174. })
  175. describe("responses", function() {
  176. it("should correctly consider media type-level examples", function (client) {
  177. client.assert.containsText(`tr.response[data-code="200"] pre`,
  178. dedent(`
  179. {
  180. "code": 200,
  181. "payload": [
  182. {
  183. "id": 1,
  184. "code": "AE2",
  185. "name": "Yono"
  186. }
  187. ]
  188. }
  189. `)
  190. )
  191. })
  192. it("should correctly consider schema-level examples", function (client) {
  193. client.assert.containsText(`tr.response[data-code="201"] pre`,
  194. dedent(`
  195. {
  196. "code": 201,
  197. "payload": [
  198. {
  199. "id": 1,
  200. "code": "AE2",
  201. "name": "Yono"
  202. }
  203. ]
  204. }
  205. `)
  206. )
  207. })
  208. it("should correctly consider property-level examples", function (client) {
  209. client.assert.containsText(`tr.response[data-code="202"] pre`,
  210. dedent(`
  211. {
  212. "code": 202,
  213. "payload": [
  214. {
  215. "id": 1,
  216. "code": "AE2",
  217. "name": "Yono"
  218. }
  219. ]
  220. }
  221. `)
  222. )
  223. })
  224. })
  225. })
  226. })