@unispechq/unispec-core 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,126 +1,126 @@
1
- import test from "node:test";
2
- import assert from "node:assert/strict";
3
-
4
- import * as core from "../dist/index.js";
5
-
6
- const { toOpenAPI, toGraphQLSDL, toWebSocketModel } = core;
7
-
8
- test("toOpenAPI produces basic OpenAPI structure from UniSpec document", () => {
9
- const doc = {
10
- unispecVersion: "0.1.0",
11
- service: {
12
- name: "test-service",
13
- title: "Service",
14
- description: "Desc",
15
- protocols: {
16
- rest: {
17
- servers: [{ url: "https://api.example.com" }],
18
- paths: {
19
- "/ping": {
20
- get: {},
21
- },
22
- },
23
- components: {
24
- schemas: {
25
- PingResponse: {
26
- type: "object",
27
- },
28
- },
29
- },
30
- security: [{ bearerAuth: [] }],
31
- tags: [
32
- {
33
- name: "ping",
34
- description: "Ping operations",
35
- },
36
- ],
37
- "x-extra-rest-field": true,
38
- },
39
- },
40
- },
41
- };
42
-
43
- const openapi = toOpenAPI(doc);
44
-
45
- assert.equal(openapi.openapi, "3.1.0");
46
- assert.equal(openapi.info.title, "Service");
47
- assert.equal(openapi.info.description, "Desc");
48
- assert.ok(openapi.paths["/ping"]);
49
- assert.ok(openapi.components);
50
- assert.ok(openapi.components.schemas.PingResponse);
51
- assert.ok(Array.isArray(openapi.security));
52
- assert.ok(Array.isArray(openapi.tags));
53
- assert.equal(openapi["x-extra-rest-field"], true);
54
- });
55
-
56
- test("toGraphQLSDL returns SDL string wrapper", () => {
57
- const doc = {
58
- unispecVersion: "0.1.0",
59
- service: {
60
- name: "test-service",
61
- title: "GraphQL Service",
62
- description: "GraphQL description",
63
- protocols: {
64
- graphql: {
65
- schema: {
66
- sdl: "type Query { hello: String! }",
67
- },
68
- },
69
- },
70
- },
71
- };
72
-
73
- const result = toGraphQLSDL(doc);
74
-
75
- assert.equal(typeof result, "object");
76
- assert.equal(typeof result.sdl, "string");
77
- assert.equal(result.sdl, "type Query { hello: String! }");
78
- });
79
-
80
- test("toWebSocketModel returns WS model wrapper", () => {
81
- const doc = {
82
- unispecVersion: "0.1.0",
83
- service: {
84
- name: "test-service",
85
- title: "WS Service",
86
- description: "WebSocket description",
87
- protocols: {
88
- websocket: {
89
- channels: {
90
- ping: {
91
- summary: "Ping channel",
92
- description: "Ping messages",
93
- direction: "bidirectional",
94
- messages: [
95
- {
96
- name: "ping",
97
- summary: "Ping message",
98
- },
99
- ],
100
- },
101
- },
102
- },
103
- },
104
- },
105
- };
106
-
107
- const model = toWebSocketModel(doc);
108
-
109
- assert.equal(typeof model, "object");
110
- assert.ok(model["x-unispec-ws"]);
111
- assert.deepEqual(model.service, {
112
- name: "test-service",
113
- title: "WS Service",
114
- description: "WebSocket description",
115
- });
116
- assert.ok(Array.isArray(model.channels));
117
- assert.equal(model.channels.length, 1);
118
- assert.equal(model.channels[0].name, "ping");
119
- assert.equal(model.channels[0].summary, "Ping channel");
120
- assert.equal(model.channels[0].description, "Ping messages");
121
- assert.equal(model.channels[0].direction, "bidirectional");
122
- assert.ok(Array.isArray(model.channels[0].messages));
123
- assert.equal(model.channels[0].messages[0].name, "ping");
124
- assert.equal(model.channels[0].messages[0].summary, "Ping message");
125
- assert.ok(model.rawProtocol);
126
- });
1
+ import test from "node:test";
2
+ import assert from "node:assert/strict";
3
+
4
+ import * as core from "../dist/index.js";
5
+
6
+ const { toOpenAPI, toGraphQLSDL, toWebSocketModel } = core;
7
+
8
+ test("toOpenAPI produces basic OpenAPI structure from UniSpec document", () => {
9
+ const doc = {
10
+ unispecVersion: "0.1.0",
11
+ service: {
12
+ name: "test-service",
13
+ title: "Service",
14
+ description: "Desc",
15
+ protocols: {
16
+ rest: {
17
+ servers: [{ url: "https://api.example.com" }],
18
+ paths: {
19
+ "/ping": {
20
+ get: {},
21
+ },
22
+ },
23
+ components: {
24
+ schemas: {
25
+ PingResponse: {
26
+ type: "object",
27
+ },
28
+ },
29
+ },
30
+ security: [{ bearerAuth: [] }],
31
+ tags: [
32
+ {
33
+ name: "ping",
34
+ description: "Ping operations",
35
+ },
36
+ ],
37
+ "x-extra-rest-field": true,
38
+ },
39
+ },
40
+ },
41
+ };
42
+
43
+ const openapi = toOpenAPI(doc);
44
+
45
+ assert.equal(openapi.openapi, "3.1.0");
46
+ assert.equal(openapi.info.title, "Service");
47
+ assert.equal(openapi.info.description, "Desc");
48
+ assert.ok(openapi.paths["/ping"]);
49
+ assert.ok(openapi.components);
50
+ assert.ok(openapi.components.schemas.PingResponse);
51
+ assert.ok(Array.isArray(openapi.security));
52
+ assert.ok(Array.isArray(openapi.tags));
53
+ assert.equal(openapi["x-extra-rest-field"], true);
54
+ });
55
+
56
+ test("toGraphQLSDL returns SDL string wrapper", () => {
57
+ const doc = {
58
+ unispecVersion: "0.1.0",
59
+ service: {
60
+ name: "test-service",
61
+ title: "GraphQL Service",
62
+ description: "GraphQL description",
63
+ protocols: {
64
+ graphql: {
65
+ schema: {
66
+ sdl: "type Query { hello: String! }",
67
+ },
68
+ },
69
+ },
70
+ },
71
+ };
72
+
73
+ const result = toGraphQLSDL(doc);
74
+
75
+ assert.equal(typeof result, "object");
76
+ assert.equal(typeof result.sdl, "string");
77
+ assert.equal(result.sdl, "type Query { hello: String! }");
78
+ });
79
+
80
+ test("toWebSocketModel returns WS model wrapper", () => {
81
+ const doc = {
82
+ unispecVersion: "0.1.0",
83
+ service: {
84
+ name: "test-service",
85
+ title: "WS Service",
86
+ description: "WebSocket description",
87
+ protocols: {
88
+ websocket: {
89
+ channels: {
90
+ ping: {
91
+ summary: "Ping channel",
92
+ description: "Ping messages",
93
+ direction: "bidirectional",
94
+ messages: [
95
+ {
96
+ name: "ping",
97
+ summary: "Ping message",
98
+ },
99
+ ],
100
+ },
101
+ },
102
+ },
103
+ },
104
+ },
105
+ };
106
+
107
+ const model = toWebSocketModel(doc);
108
+
109
+ assert.equal(typeof model, "object");
110
+ assert.ok(model["x-unispec-ws"]);
111
+ assert.deepEqual(model.service, {
112
+ name: "test-service",
113
+ title: "WS Service",
114
+ description: "WebSocket description",
115
+ });
116
+ assert.ok(Array.isArray(model.channels));
117
+ assert.equal(model.channels.length, 1);
118
+ assert.equal(model.channels[0].name, "ping");
119
+ assert.equal(model.channels[0].summary, "Ping channel");
120
+ assert.equal(model.channels[0].description, "Ping messages");
121
+ assert.equal(model.channels[0].direction, "bidirectional");
122
+ assert.ok(Array.isArray(model.channels[0].messages));
123
+ assert.equal(model.channels[0].messages[0].name, "ping");
124
+ assert.equal(model.channels[0].messages[0].summary, "Ping message");
125
+ assert.ok(model.rawProtocol);
126
+ });