You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

961 lines
24 KiB

  1. import { createXMLExample, sampleFromSchema } from "corePlugins/samples/fn"
  2. import expect from "expect"
  3. describe("sampleFromSchema", function() {
  4. it("returns object with no readonly fields for parameter", function () {
  5. var definition = {
  6. type: "object",
  7. properties: {
  8. id: {
  9. type: "integer"
  10. },
  11. readOnlyDog: {
  12. readOnly: true,
  13. type: "string"
  14. }
  15. },
  16. xml: {
  17. name: "animals"
  18. }
  19. }
  20. var expected = {
  21. id: 0
  22. }
  23. expect(sampleFromSchema(definition, { includeReadOnly: false })).toEqual(expected)
  24. })
  25. it("returns object with readonly fields for parameter, with includeReadOnly", function () {
  26. var definition = {
  27. type: "object",
  28. properties: {
  29. id: {
  30. type: "integer"
  31. },
  32. readOnlyDog: {
  33. readOnly: true,
  34. type: "string"
  35. }
  36. },
  37. xml: {
  38. name: "animals"
  39. }
  40. }
  41. var expected = {
  42. id: 0,
  43. readOnlyDog: "string"
  44. }
  45. expect(sampleFromSchema(definition, { includeReadOnly: true })).toEqual(expected)
  46. })
  47. it("returns object without writeonly fields for parameter", function () {
  48. var definition = {
  49. type: "object",
  50. properties: {
  51. id: {
  52. type: "integer"
  53. },
  54. writeOnlyDog: {
  55. writeOnly: true,
  56. type: "string"
  57. }
  58. },
  59. xml: {
  60. name: "animals"
  61. }
  62. }
  63. var expected = {
  64. id: 0
  65. }
  66. expect(sampleFromSchema(definition)).toEqual(expected)
  67. })
  68. it("returns object with writeonly fields for parameter, with includeWriteOnly", function () {
  69. var definition = {
  70. type: "object",
  71. properties: {
  72. id: {
  73. type: "integer"
  74. },
  75. writeOnlyDog: {
  76. writeOnly: true,
  77. type: "string"
  78. }
  79. },
  80. xml: {
  81. name: "animals"
  82. }
  83. }
  84. var expected = {
  85. id: 0,
  86. writeOnlyDog: "string"
  87. }
  88. expect(sampleFromSchema(definition, { includeWriteOnly: true })).toEqual(expected)
  89. })
  90. })
  91. describe("createXMLExample", function () {
  92. var sut = createXMLExample
  93. describe("simple types with xml property", function () {
  94. it("returns tag <newtagname>string</newtagname> when passing type string and xml:{name: \"newtagname\"}", function () {
  95. var definition = {
  96. type: "string",
  97. xml: {
  98. name: "newtagname"
  99. }
  100. }
  101. expect(sut(definition)).toEqual("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<newtagname>string</newtagname>")
  102. })
  103. it("returns tag <test:newtagname>string</test:newtagname> when passing type string and xml:{name: \"newtagname\", prefix:\"test\"}", function () {
  104. var definition = {
  105. type: "string",
  106. xml: {
  107. name: "newtagname",
  108. prefix: "test"
  109. }
  110. }
  111. expect(sut(definition)).toEqual("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test:newtagname>string</test:newtagname>")
  112. })
  113. it("returns tag <test:tagname xmlns:sample=\"http://swagger.io/schema/sample\">string</test:tagname> when passing type string and xml:{\"namespace\": \"http://swagger.io/schema/sample\", \"prefix\": \"sample\"}", function () {
  114. var definition = {
  115. type: "string",
  116. xml: {
  117. namespace: "http://swagger.io/schema/sample",
  118. prefix: "sample",
  119. name: "name"
  120. }
  121. }
  122. expect(sut(definition)).toEqual("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<sample:name xmlns:sample=\"http://swagger.io/schema/sample\">string</sample:name>")
  123. })
  124. it("returns tag <test:tagname >string</test:tagname> when passing type string and xml:{\"namespace\": \"http://swagger.io/schema/sample\"}", function () {
  125. var definition = {
  126. type: "string",
  127. xml: {
  128. namespace: "http://swagger.io/schema/sample",
  129. name: "name"
  130. }
  131. }
  132. expect(sut(definition)).toEqual("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<name xmlns=\"http://swagger.io/schema/sample\">string</name>")
  133. })
  134. it("returns tag <newtagname>test</newtagname> when passing default value", function () {
  135. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<newtagname>test</newtagname>"
  136. var definition = {
  137. type: "string",
  138. "default": "test",
  139. xml: {
  140. name: "newtagname"
  141. }
  142. }
  143. expect(sut(definition)).toEqual(expected)
  144. })
  145. it("returns default value when enum provided", function () {
  146. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<newtagname>one</newtagname>"
  147. var definition = {
  148. type: "string",
  149. "default": "one",
  150. "enum": ["two", "one"],
  151. xml: {
  152. name: "newtagname"
  153. }
  154. }
  155. expect(sut(definition)).toEqual(expected)
  156. })
  157. it("returns example value when provided", function () {
  158. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<newtagname>two</newtagname>"
  159. var definition = {
  160. type: "string",
  161. "default": "one",
  162. "example": "two",
  163. "enum": ["two", "one"],
  164. xml: {
  165. name: "newtagname"
  166. }
  167. }
  168. expect(sut(definition)).toEqual(expected)
  169. })
  170. it("sets first enum if provided", function () {
  171. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<newtagname>one</newtagname>"
  172. var definition = {
  173. type: "string",
  174. "enum": ["one", "two"],
  175. xml: {
  176. name: "newtagname"
  177. }
  178. }
  179. expect(sut(definition)).toEqual(expected)
  180. })
  181. })
  182. describe("array", function () {
  183. it("returns tag <tagname>string</tagname> when passing string items", function () {
  184. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<tagname>string</tagname>"
  185. var definition = {
  186. type: "array",
  187. items: {
  188. type: "string"
  189. },
  190. xml: {
  191. name: "tagname"
  192. }
  193. }
  194. expect(sut(definition)).toEqual(expected)
  195. })
  196. it("returns tag <animal>string</animal> when passing string items with name", function () {
  197. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animal>string</animal>"
  198. var definition = {
  199. type: "array",
  200. items: {
  201. type: "string",
  202. xml: {
  203. name: "animal"
  204. }
  205. },
  206. xml: {
  207. name: "animals"
  208. }
  209. }
  210. expect(sut(definition)).toEqual(expected)
  211. })
  212. it("returns tag <animals><animal>string</animal></animals> when passing string items with name", function () {
  213. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<animal>string</animal>\n</animals>"
  214. var definition = {
  215. type: "array",
  216. items: {
  217. type: "string",
  218. xml: {
  219. name: "animal"
  220. }
  221. },
  222. xml: {
  223. wrapped: true,
  224. name: "animals"
  225. }
  226. }
  227. expect(sut(definition)).toEqual(expected)
  228. })
  229. it("return correct nested wrapped array", function () {
  230. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<aliens>\n\t<dog>string</dog>\n</aliens>"
  231. var definition = {
  232. type: "array",
  233. items: {
  234. type: "array",
  235. items: {
  236. type: "string"
  237. },
  238. xml: {
  239. name: "dog"
  240. }
  241. },
  242. xml: {
  243. wrapped: true,
  244. name: "aliens"
  245. }
  246. }
  247. expect(sut(definition)).toEqual(expected)
  248. })
  249. it("return correct nested wrapped array with xml", function () {
  250. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<aliens>\n\t<dogs>\n\t\t<dog>string</dog>\n\t</dogs>\n</aliens>"
  251. var definition = {
  252. type: "array",
  253. items: {
  254. type: "array",
  255. items: {
  256. type: "string",
  257. xml: {
  258. name: "dog"
  259. }
  260. },
  261. xml: {
  262. name: "dogs",
  263. wrapped: true
  264. }
  265. },
  266. xml: {
  267. wrapped: true,
  268. name: "aliens"
  269. }
  270. }
  271. expect(sut(definition)).toEqual(expected)
  272. })
  273. it("adds namespace to array", function () {
  274. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<dog xmlns=\"test\">string</dog>"
  275. var definition = {
  276. type: "array",
  277. items: {
  278. type: "string",
  279. xml: {
  280. name: "dog",
  281. namespace: "test"
  282. }
  283. },
  284. xml: {
  285. name: "aliens",
  286. namespace: "test_new"
  287. }
  288. }
  289. expect(sut(definition)).toEqual(expected)
  290. })
  291. it("adds prefix to array", function () {
  292. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test:dog>string</test:dog>"
  293. var definition = {
  294. type: "array",
  295. items: {
  296. type: "string",
  297. xml: {
  298. name: "dog",
  299. prefix: "test"
  300. }
  301. },
  302. xml: {
  303. name: "aliens",
  304. prefix: "test_new"
  305. }
  306. }
  307. expect(sut(definition)).toEqual(expected)
  308. })
  309. it("adds prefix to array with no xml in items", function () {
  310. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test:dog>string</test:dog>"
  311. var definition = {
  312. type: "array",
  313. items: {
  314. type: "string"
  315. },
  316. xml: {
  317. name: "dog",
  318. prefix: "test"
  319. }
  320. }
  321. expect(sut(definition)).toEqual(expected)
  322. })
  323. it("adds namespace to array with no xml in items", function () {
  324. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<dog xmlns=\"test\">string</dog>"
  325. var definition = {
  326. type: "array",
  327. items: {
  328. type: "string"
  329. },
  330. xml: {
  331. name: "dog",
  332. namespace: "test"
  333. }
  334. }
  335. expect(sut(definition)).toEqual(expected)
  336. })
  337. it("adds namespace to array with wrapped", function () {
  338. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<aliens xmlns=\"test\">\n\t<dog>string</dog>\n</aliens>"
  339. var definition = {
  340. type: "array",
  341. items: {
  342. type: "string",
  343. xml: {
  344. name: "dog"
  345. }
  346. },
  347. xml: {
  348. wrapped: true,
  349. name: "aliens",
  350. namespace: "test"
  351. }
  352. }
  353. expect(sut(definition)).toEqual(expected)
  354. })
  355. it("adds prefix to array with wrapped", function () {
  356. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test:aliens>\n\t<dog>string</dog>\n</test:aliens>"
  357. var definition = {
  358. type: "array",
  359. items: {
  360. type: "string",
  361. xml: {
  362. name: "dog"
  363. }
  364. },
  365. xml: {
  366. wrapped: true,
  367. name: "aliens",
  368. prefix: "test"
  369. }
  370. }
  371. expect(sut(definition)).toEqual(expected)
  372. })
  373. it("returns wrapped array when type is not passed", function () {
  374. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<animal>string</animal>\n</animals>"
  375. var definition = {
  376. items: {
  377. type: "string",
  378. xml: {
  379. name: "animal"
  380. }
  381. },
  382. xml: {
  383. wrapped: true,
  384. name: "animals"
  385. }
  386. }
  387. expect(sut(definition)).toEqual(expected)
  388. })
  389. it("returns array with default values", function () {
  390. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animal>one</animal>\n<animal>two</animal>"
  391. var definition = {
  392. items: {
  393. type: "string",
  394. xml: {
  395. name: "animal"
  396. }
  397. },
  398. "default": ["one", "two"],
  399. xml: {
  400. name: "animals"
  401. }
  402. }
  403. expect(sut(definition)).toEqual(expected)
  404. })
  405. it("returns array with default values with wrapped=true", function () {
  406. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<animal>one</animal>\n\t<animal>two</animal>\n</animals>"
  407. var definition = {
  408. items: {
  409. type: "string",
  410. xml: {
  411. name: "animal"
  412. }
  413. },
  414. "default": ["one", "two"],
  415. xml: {
  416. wrapped: true,
  417. name: "animals"
  418. }
  419. }
  420. expect(sut(definition)).toEqual(expected)
  421. })
  422. it("returns array with default values", function () {
  423. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animal>one</animal>"
  424. var definition = {
  425. items: {
  426. type: "string",
  427. "enum": ["one", "two"],
  428. xml: {
  429. name: "animal"
  430. }
  431. },
  432. xml: {
  433. name: "animals"
  434. }
  435. }
  436. expect(sut(definition)).toEqual(expected)
  437. })
  438. it("returns array with default values with wrapped=true", function () {
  439. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<animal>1</animal>\n\t<animal>2</animal>\n</animals>"
  440. var definition = {
  441. items: {
  442. "enum": ["one", "two"],
  443. type: "string",
  444. xml: {
  445. name: "animal"
  446. }
  447. },
  448. "default": ["1", "2"],
  449. xml: {
  450. wrapped: true,
  451. name: "animals"
  452. }
  453. }
  454. expect(sut(definition)).toEqual(expected)
  455. })
  456. it("returns array with example values with ", function () {
  457. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<animal>1</animal>\n\t<animal>2</animal>\n</animals>"
  458. var definition = {
  459. type: "object",
  460. properties: {
  461. "animal": {
  462. "type": "array",
  463. "items": {
  464. "type": "string"
  465. },
  466. "example": [
  467. "1",
  468. "2"
  469. ]
  470. }
  471. },
  472. xml: {
  473. name: "animals"
  474. }
  475. }
  476. expect(sut(definition)).toEqual(expected)
  477. })
  478. it("returns array with example values with wrapped=true", function () {
  479. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<animal>1</animal>\n\t<animal>2</animal>\n</animals>"
  480. var definition = {
  481. type: "array",
  482. items: {
  483. type: "string",
  484. xml: {
  485. name: "animal"
  486. }
  487. },
  488. "example": [ "1", "2" ],
  489. xml: {
  490. wrapped: true,
  491. name: "animals"
  492. }
  493. }
  494. expect(sut(definition)).toEqual(expected)
  495. })
  496. })
  497. describe("object", function () {
  498. it("returns object with 2 properties", function () {
  499. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<aliens>\n\t<alien>string</alien>\n\t<dog>0</dog>\n</aliens>"
  500. var definition = {
  501. type: "object",
  502. properties: {
  503. alien: {
  504. type: "string"
  505. },
  506. dog: {
  507. type: "integer"
  508. }
  509. },
  510. xml: {
  511. name: "aliens"
  512. }
  513. }
  514. expect(sut(definition)).toEqual(expected)
  515. })
  516. it("returns object with integer property and array property", function () {
  517. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<aliens>string</aliens>\n\t<dog>0</dog>\n</animals>"
  518. var definition = {
  519. type: "object",
  520. properties: {
  521. aliens: {
  522. type: "array",
  523. items: {
  524. type: "string"
  525. }
  526. },
  527. dog: {
  528. type: "integer"
  529. }
  530. },
  531. xml: {
  532. name: "animals"
  533. }
  534. }
  535. expect(sut(definition)).toEqual(expected)
  536. })
  537. it("returns nested objects", function () {
  538. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<aliens>\n\t\t<alien>string</alien>\n\t</aliens>\n\t<dog>string</dog>\n</animals>"
  539. var definition = {
  540. type: "object",
  541. properties: {
  542. aliens: {
  543. type: "object",
  544. properties: {
  545. alien: {
  546. type: "string",
  547. xml: {
  548. name: "alien"
  549. }
  550. }
  551. }
  552. },
  553. dog: {
  554. type: "string"
  555. }
  556. },
  557. xml: {
  558. name: "animals"
  559. }
  560. }
  561. expect(sut(definition)).toEqual(expected)
  562. })
  563. it("returns object with no readonly fields for parameter", function () {
  564. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<id>0</id>\n</animals>"
  565. var definition = {
  566. type: "object",
  567. properties: {
  568. id: {
  569. type: "integer"
  570. },
  571. dog: {
  572. readOnly: true,
  573. type: "string"
  574. }
  575. },
  576. xml: {
  577. name: "animals"
  578. }
  579. }
  580. expect(sut(definition, { includeReadOnly: false })).toEqual(expected)
  581. })
  582. it("returns object with readonly fields for parameter, with includeReadOnly", function () {
  583. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<id>0</id>\n\t<dog>string</dog>\n</animals>"
  584. var definition = {
  585. type: "object",
  586. properties: {
  587. id: {
  588. type: "integer"
  589. },
  590. dog: {
  591. readOnly: true,
  592. type: "string"
  593. }
  594. },
  595. xml: {
  596. name: "animals"
  597. }
  598. }
  599. expect(sut(definition, { includeReadOnly: true })).toEqual(expected)
  600. })
  601. it("returns object without writeonly fields for parameter", function () {
  602. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<id>0</id>\n</animals>"
  603. var definition = {
  604. type: "object",
  605. properties: {
  606. id: {
  607. type: "integer"
  608. },
  609. dog: {
  610. writeOnly: true,
  611. type: "string"
  612. }
  613. },
  614. xml: {
  615. name: "animals"
  616. }
  617. }
  618. expect(sut(definition)).toEqual(expected)
  619. })
  620. it("returns object with writeonly fields for parameter, with includeWriteOnly", function () {
  621. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<id>0</id>\n\t<dog>string</dog>\n</animals>"
  622. var definition = {
  623. type: "object",
  624. properties: {
  625. id: {
  626. type: "integer"
  627. },
  628. dog: {
  629. writeOnly: true,
  630. type: "string"
  631. }
  632. },
  633. xml: {
  634. name: "animals"
  635. }
  636. }
  637. expect(sut(definition, { includeWriteOnly: true })).toEqual(expected)
  638. })
  639. it("returns object with passed property as attribute", function () {
  640. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals id=\"0\">\n\t<dog>string</dog>\n</animals>"
  641. var definition = {
  642. type: "object",
  643. properties: {
  644. id: {
  645. type: "integer",
  646. xml: {
  647. attribute: true
  648. }
  649. },
  650. dog: {
  651. type: "string"
  652. }
  653. },
  654. xml: {
  655. name: "animals"
  656. }
  657. }
  658. expect(sut(definition)).toEqual(expected)
  659. })
  660. it("returns object with passed property as attribute with custom name", function () {
  661. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals test=\"0\">\n\t<dog>string</dog>\n</animals>"
  662. var definition = {
  663. type: "object",
  664. properties: {
  665. id: {
  666. type: "integer",
  667. xml: {
  668. attribute: true,
  669. name: "test"
  670. }
  671. },
  672. dog: {
  673. type: "string"
  674. }
  675. },
  676. xml: {
  677. name: "animals"
  678. }
  679. }
  680. expect(sut(definition)).toEqual(expected)
  681. })
  682. it("returns object with example values in attribute", function () {
  683. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user id=\"42\">\n\t<role>admin</role>\n</user>"
  684. var definition = {
  685. type: "object",
  686. properties: {
  687. id: {
  688. type: "integer",
  689. xml: {
  690. attribute: true
  691. }
  692. },
  693. role:{
  694. type: "string"
  695. }
  696. },
  697. xml: {
  698. name: "user"
  699. },
  700. example: {
  701. id: 42,
  702. role: "admin"
  703. }
  704. }
  705. expect(sut(definition)).toEqual(expected)
  706. })
  707. it("returns object with enum values in attribute", function () {
  708. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user id=\"one\">\n\t<role>string</role>\n</user>"
  709. var definition = {
  710. type: "object",
  711. properties: {
  712. id: {
  713. type: "string",
  714. "enum": ["one", "two"],
  715. xml: {
  716. attribute: true
  717. }
  718. },
  719. role:{
  720. type: "string"
  721. }
  722. },
  723. xml: {
  724. name: "user"
  725. }
  726. }
  727. expect(sut(definition)).toEqual(expected)
  728. })
  729. it("returns object with default values in attribute", function () {
  730. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user id=\"one\">\n\t<role>string</role>\n</user>"
  731. var definition = {
  732. type: "object",
  733. properties: {
  734. id: {
  735. type: "string",
  736. "default": "one",
  737. xml: {
  738. attribute: true
  739. }
  740. },
  741. role:{
  742. type: "string"
  743. }
  744. },
  745. xml: {
  746. name: "user"
  747. }
  748. }
  749. expect(sut(definition)).toEqual(expected)
  750. })
  751. it("returns object with default values in attribute", function () {
  752. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user id=\"one\">\n\t<role>string</role>\n</user>"
  753. var definition = {
  754. type: "object",
  755. properties: {
  756. id: {
  757. type: "string",
  758. "example": "one",
  759. xml: {
  760. attribute: true
  761. }
  762. },
  763. role:{
  764. type: "string"
  765. }
  766. },
  767. xml: {
  768. name: "user"
  769. }
  770. }
  771. expect(sut(definition)).toEqual(expected)
  772. })
  773. it("returns object with example value", function () {
  774. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>\n\t<id>42</id>\n\t<role>admin</role>\n</user>"
  775. var definition = {
  776. type: "object",
  777. properties: {
  778. id: {
  779. type: "integer"
  780. },
  781. role:{
  782. type: "string"
  783. }
  784. },
  785. xml: {
  786. name: "user"
  787. },
  788. example: {
  789. id: 42,
  790. role: "admin"
  791. }
  792. }
  793. expect(sut(definition)).toEqual(expected)
  794. })
  795. it("returns object with additional props", function () {
  796. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<dog>string</dog>\n\t<additionalProp>string</additionalProp>\n</animals>"
  797. var definition = {
  798. type: "object",
  799. properties: {
  800. dog: {
  801. type: "string"
  802. }
  803. },
  804. additionalProperties: {
  805. type: "string"
  806. },
  807. xml: {
  808. name: "animals"
  809. }
  810. }
  811. expect(sut(definition)).toEqual(expected)
  812. })
  813. it("returns object with additional props =true", function () {
  814. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<dog>string</dog>\n\t<additionalProp>Anything can be here</additionalProp>\n</animals>"
  815. var definition = {
  816. type: "object",
  817. properties: {
  818. dog: {
  819. type: "string"
  820. }
  821. },
  822. additionalProperties: true,
  823. xml: {
  824. name: "animals"
  825. }
  826. }
  827. expect(sut(definition)).toEqual(expected)
  828. })
  829. it("returns object with 2 properties with no type passed but properties", function () {
  830. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<aliens>\n\t<alien>string</alien>\n\t<dog>0</dog>\n</aliens>"
  831. var definition = {
  832. properties: {
  833. alien: {
  834. type: "string"
  835. },
  836. dog: {
  837. type: "integer"
  838. }
  839. },
  840. xml: {
  841. name: "aliens"
  842. }
  843. }
  844. expect(sut(definition)).toEqual(expected)
  845. })
  846. it("returns object with additional props with no type passed", function () {
  847. var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<additionalProp>string</additionalProp>\n</animals>"
  848. var definition = {
  849. additionalProperties: {
  850. type: "string"
  851. },
  852. xml: {
  853. name: "animals"
  854. }
  855. }
  856. expect(sut(definition)).toEqual(expected)
  857. })
  858. })
  859. })