@aloma.io/integration-sdk 3.8.50 → 3.8.52
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.
- package/OPENAPI_TO_CONNECTOR.md +216 -0
- package/README.md +15 -1
- package/build/cli.mjs +57 -1
- package/build/internal/fetcher/fetcher.d.mts +1 -0
- package/build/openapi-to-connector.d.mts +35 -0
- package/build/openapi-to-connector.mjs +252 -0
- package/examples/generate-connector.sh +35 -0
- package/examples/generated-controller.mts +81 -0
- package/examples/sample-api.json +325 -0
- package/examples/sample-api.yaml +222 -0
- package/examples/simple-api.json +39 -0
- package/package.json +11 -4
- package/src/builder/index.mts +3 -3
- package/src/builder/runtime-context.mts +2 -2
- package/src/cli.mts +65 -1
- package/src/controller/index.mts +2 -2
- package/src/internal/connector/server/on-connect/index.mts +9 -9
- package/src/internal/fetcher/fetcher.mts +5 -5
- package/src/internal/websocket/transport/index.mjs +4 -5
- package/src/openapi-to-connector.mts +305 -0
- package/test/openapi-to-connector.test.mts +207 -0
@@ -0,0 +1,207 @@
|
|
1
|
+
import { describe, it } from 'mocha';
|
2
|
+
import { expect } from 'chai';
|
3
|
+
import { OpenAPIToConnector } from '../build/openapi-to-connector.mjs';
|
4
|
+
|
5
|
+
describe('OpenAPIToConnector', () => {
|
6
|
+
const validOpenAPISpec = {
|
7
|
+
openapi: '3.0.0' as const,
|
8
|
+
info: {
|
9
|
+
title: 'Test API',
|
10
|
+
version: '1.0.0',
|
11
|
+
description: 'A test API'
|
12
|
+
},
|
13
|
+
paths: {
|
14
|
+
'/users': {
|
15
|
+
get: {
|
16
|
+
operationId: 'getUsers',
|
17
|
+
summary: 'Get all users',
|
18
|
+
description: 'Retrieve a list of all users',
|
19
|
+
responses: {
|
20
|
+
'200': {
|
21
|
+
description: 'Successful response',
|
22
|
+
content: {
|
23
|
+
'application/json': {
|
24
|
+
schema: {
|
25
|
+
type: 'array' as const,
|
26
|
+
items: {
|
27
|
+
type: 'object' as const,
|
28
|
+
properties: {
|
29
|
+
id: { type: 'string' as const },
|
30
|
+
name: { type: 'string' as const }
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
34
|
+
}
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
38
|
+
},
|
39
|
+
post: {
|
40
|
+
operationId: 'createUser',
|
41
|
+
summary: 'Create a new user',
|
42
|
+
description: 'Create a new user in the system',
|
43
|
+
requestBody: {
|
44
|
+
required: true,
|
45
|
+
content: {
|
46
|
+
'application/json': {
|
47
|
+
schema: {
|
48
|
+
type: 'object' as const,
|
49
|
+
properties: {
|
50
|
+
name: { type: 'string' as const },
|
51
|
+
email: { type: 'string' as const }
|
52
|
+
}
|
53
|
+
}
|
54
|
+
}
|
55
|
+
}
|
56
|
+
},
|
57
|
+
responses: {
|
58
|
+
'201': {
|
59
|
+
description: 'User created successfully'
|
60
|
+
}
|
61
|
+
}
|
62
|
+
}
|
63
|
+
},
|
64
|
+
'/users/{id}': {
|
65
|
+
get: {
|
66
|
+
operationId: 'getUserById',
|
67
|
+
summary: 'Get user by ID',
|
68
|
+
parameters: [
|
69
|
+
{
|
70
|
+
name: 'id',
|
71
|
+
in: 'path' as const,
|
72
|
+
required: true,
|
73
|
+
schema: { type: 'string' as const },
|
74
|
+
description: 'User ID'
|
75
|
+
}
|
76
|
+
],
|
77
|
+
responses: {
|
78
|
+
'200': {
|
79
|
+
description: 'User found'
|
80
|
+
}
|
81
|
+
}
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
85
|
+
};
|
86
|
+
|
87
|
+
describe('parseSpec', () => {
|
88
|
+
it('should parse valid OpenAPI 3.0 JSON spec', () => {
|
89
|
+
const specString = JSON.stringify(validOpenAPISpec);
|
90
|
+
const result = OpenAPIToConnector.parseSpec(specString);
|
91
|
+
|
92
|
+
expect(result.openapi).to.equal('3.0.0');
|
93
|
+
expect(result.info.title).to.equal('Test API');
|
94
|
+
expect(result.paths).to.have.property('/users');
|
95
|
+
});
|
96
|
+
|
97
|
+
it('should parse valid OpenAPI 3.0 YAML spec', () => {
|
98
|
+
const yamlSpec = `
|
99
|
+
openapi: 3.0.0
|
100
|
+
info:
|
101
|
+
title: Test API
|
102
|
+
version: 1.0.0
|
103
|
+
description: A test API
|
104
|
+
paths:
|
105
|
+
/users:
|
106
|
+
get:
|
107
|
+
operationId: getUsers
|
108
|
+
summary: Get all users
|
109
|
+
responses:
|
110
|
+
'200':
|
111
|
+
description: Successful response
|
112
|
+
`;
|
113
|
+
const result = OpenAPIToConnector.parseSpec(yamlSpec);
|
114
|
+
|
115
|
+
expect(result.openapi).to.equal('3.0.0');
|
116
|
+
expect(result.info.title).to.equal('Test API');
|
117
|
+
});
|
118
|
+
|
119
|
+
it('should reject invalid OpenAPI version', () => {
|
120
|
+
const invalidSpec = {
|
121
|
+
...validOpenAPISpec,
|
122
|
+
openapi: '2.0.0'
|
123
|
+
};
|
124
|
+
|
125
|
+
expect(() => {
|
126
|
+
OpenAPIToConnector.parseSpec(JSON.stringify(invalidSpec));
|
127
|
+
}).to.throw('Invalid OpenAPI 3.x specification');
|
128
|
+
});
|
129
|
+
|
130
|
+
it('should reject spec without required fields', () => {
|
131
|
+
const invalidSpec = {
|
132
|
+
openapi: '3.0.0'
|
133
|
+
// Missing info and paths
|
134
|
+
};
|
135
|
+
|
136
|
+
expect(() => {
|
137
|
+
OpenAPIToConnector.parseSpec(JSON.stringify(invalidSpec));
|
138
|
+
}).to.throw('Invalid OpenAPI 3.x specification');
|
139
|
+
});
|
140
|
+
|
141
|
+
it('should reject invalid JSON/YAML', () => {
|
142
|
+
expect(() => {
|
143
|
+
OpenAPIToConnector.parseSpec('invalid json {');
|
144
|
+
}).to.throw('Failed to parse OpenAPI spec');
|
145
|
+
});
|
146
|
+
});
|
147
|
+
|
148
|
+
describe('generateController', () => {
|
149
|
+
it('should generate controller with all operations', () => {
|
150
|
+
const generator = new OpenAPIToConnector(validOpenAPISpec, 'Test Connector');
|
151
|
+
const controllerCode = generator.generateController();
|
152
|
+
|
153
|
+
expect(controllerCode).to.include('import {AbstractController}');
|
154
|
+
expect(controllerCode).to.include('export default class Controller extends AbstractController');
|
155
|
+
expect(controllerCode).to.include('async getUsers(args: any)');
|
156
|
+
expect(controllerCode).to.include('async createUser(args: any)');
|
157
|
+
expect(controllerCode).to.include('async get_users_{id}(args: any)');
|
158
|
+
});
|
159
|
+
|
160
|
+
it('should generate proper JSDoc comments', () => {
|
161
|
+
const generator = new OpenAPIToConnector(validOpenAPISpec, 'Test Connector');
|
162
|
+
const controllerCode = generator.generateController();
|
163
|
+
|
164
|
+
expect(controllerCode).to.include('* Get all users');
|
165
|
+
expect(controllerCode).to.include('* Retrieve a list of all users');
|
166
|
+
expect(controllerCode).to.include('* @param args.body - Request body');
|
167
|
+
expect(controllerCode).to.include('* @param args.id - User ID');
|
168
|
+
});
|
169
|
+
|
170
|
+
it('should handle operations without operationId', () => {
|
171
|
+
const specWithoutOperationId = {
|
172
|
+
...validOpenAPISpec,
|
173
|
+
paths: {
|
174
|
+
'/test': {
|
175
|
+
get: {
|
176
|
+
summary: 'Test endpoint',
|
177
|
+
responses: {
|
178
|
+
'200': {
|
179
|
+
description: 'Success'
|
180
|
+
}
|
181
|
+
}
|
182
|
+
}
|
183
|
+
}
|
184
|
+
}
|
185
|
+
};
|
186
|
+
|
187
|
+
const generator = new OpenAPIToConnector(specWithoutOperationId, 'Test Connector');
|
188
|
+
const controllerCode = generator.generateController();
|
189
|
+
|
190
|
+
expect(controllerCode).to.include('async get_test(args: any)');
|
191
|
+
});
|
192
|
+
|
193
|
+
it('should throw error for empty spec', () => {
|
194
|
+
const emptySpec = {
|
195
|
+
openapi: '3.0.0',
|
196
|
+
info: { title: 'Test', version: '1.0.0' },
|
197
|
+
paths: {}
|
198
|
+
};
|
199
|
+
|
200
|
+
const generator = new OpenAPIToConnector(emptySpec, 'Test Connector');
|
201
|
+
|
202
|
+
expect(() => {
|
203
|
+
generator.generateController();
|
204
|
+
}).to.throw('No operations found in OpenAPI specification');
|
205
|
+
});
|
206
|
+
});
|
207
|
+
});
|