Home Reference Source

src/complex-schema.test.js

  1. import {default as Schema} from "../fixtures/basic-refs.schema";
  2. import {default as Data} from "../fixtures/basic-refs.data";
  3. import {default as Swagger} from "../fixtures/OpenAPIv2";
  4. import {default as OpenAPIv3} from "../fixtures/OpenAPIv3";
  5. import {default as JSONSchema4} from "../fixtures/json-schema-draft04.schema";
  6. import {default as basicAPI} from "../fixtures/petstore.v2"
  7. import {Model} from "./Model";
  8.  
  9. describe("Basic Refs", () => {
  10. describe("ref handling", () => {
  11. it("should validate schema containing $refs and definitions", (done) => {
  12. const _owner = new Model({schemas: [Schema]});
  13. _owner.subscribe({
  14. next: (model) => {
  15. expect(_owner.errors).toBe(null);
  16. expect(model.toJSON()).toEqual(Data);
  17. done();
  18. },
  19. error: (e) => {
  20. done(`${e}`);
  21. }
  22. });
  23. _owner.model = Data;
  24. });
  25. });
  26.  
  27. describe("OPenAPI Tests", () => {
  28. it("should load and validate Swagger Schema", () => {
  29. const _owner = new Model({
  30. meta: [JSONSchema4],
  31. schemas: [Swagger],
  32. use: "http://swagger.io/v2/schema.json#",
  33. });
  34. _owner.model = basicAPI;
  35. // test to ensure no errors were logged
  36. expect(_owner.errors).toBe(null);
  37. // test for completeness
  38. expect(_owner.toJSON()).toEqual(basicAPI);
  39. });
  40.  
  41. it("should load and validate OpenAPIv3 Schema", () => {
  42. const _d = {
  43. openapi: "3.0.1",
  44. info: {
  45. title: "testing",
  46. version: "1.0.0",
  47. },
  48. paths: {},
  49. };
  50. const _owner = new Model({
  51. meta: [JSONSchema4],
  52. schemas: [OpenAPIv3],
  53. use: "http://openapis.org/v3/schema.json#",
  54. });
  55. _owner.model = _d;
  56. // test to ensure no errors were logged
  57. expect(_owner.errors).toBe(null);
  58. // test for completeness
  59. expect(_owner.toJSON()).toEqual(_d);
  60. });
  61. });
  62. });