Skip to content

Commit f1d0688

Browse files
committed
Fix up OpenAPI identifier issues
1 parent cb6f9fc commit f1d0688

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

lib/well-knowns.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,14 @@ const generateOpenAPISpec = (definitions, plugin, server, origin, identifier) =>
174174
} else if (!route.endsWith('/')) {
175175
route = route + '/';
176176
}
177+
let opIdentifier = identifier.replace(/\[(.*)\]/gi, '');
178+
let operationId = `${opIdentifier}${parts.length ? ('.' + parts.join('.')) : ''}`;
179+
operationId = operationId.replace(/[^A-Z0-9_]+/gi, '_');
180+
operationId = operationId.replace(/^_+/gi, '');
181+
operationId = operationId.replace(/_+$/gi, '');
177182
let pathData = {
178183
description: def.description,
179-
operationId: `${identifier}${parts.length ? ('.' + parts.join('.')) : ''}`,
184+
operationId: operationId
180185
};
181186
// If we have at least one required parameter...
182187
if (def.params.filter(param => !param.hasOwnProperty('defaultValue').length > 0)) {
@@ -335,7 +340,10 @@ const wellKnowns = {
335340
const AIPlugin = {};
336341
AIPlugin.schema_version = 'v1';
337342
AIPlugin.name_for_human = plugin.name.slice(0, 20);
338-
AIPlugin.name_for_model = plugin.forModel.name.slice(0, 50).replace(/[^A-Z0-9_]+/gi, '_');
343+
AIPlugin.name_for_model = plugin.forModel.name.slice(0, 50);
344+
AIPlugin.name_for_model = AIPlugin.name_for_model.replace(/[^A-Z0-9_]+/gi, '_');
345+
AIPlugin.name_for_model = AIPlugin.name_for_model.replace(/^_+/gi, '');
346+
AIPlugin.name_for_model = AIPlugin.name_for_model.replace(/_+$/gi, '');
339347
AIPlugin.description_for_human = plugin.description.slice(0, 100);
340348
AIPlugin.description_for_model = plugin.forModel.description.slice(0, 8000);
341349
AIPlugin.auth = {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "functionscript",
3-
"version": "2.10.3",
3+
"version": "2.10.4",
44
"description": "An API gateway and framework for turning functions into web services",
55
"author": "Keith Horwood <keithwhor@gmail.com>",
66
"main": "index.js",

tests/gateway/tests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5594,7 +5594,7 @@ module.exports = (expect) => {
55945594
expect(result).to.exist;
55955595
expect(result.schema_version).to.equal('v1');
55965596
expect(result.name_for_human).to.equal('(No name provided)');
5597-
expect(result.name_for_model).to.equal('(No name provided)');
5597+
expect(result.name_for_model).to.equal('No_name_provided');
55985598
expect(result.description_for_human).to.equal('(No description provided)');
55995599
expect(result.description_for_model).to.equal('(No description provided)');
56005600
expect(result.api).to.exist;
@@ -5627,7 +5627,7 @@ module.exports = (expect) => {
56275627
expect(result.paths['/my_function/']).to.exist;
56285628
expect(result.paths['/my_function/'].post).to.exist;
56295629
expect(result.paths['/my_function/'].post.description).to.equal('My function');
5630-
expect(result.paths['/my_function/'].post.operationId).to.equal('service.localhost.my_function');
5630+
expect(result.paths['/my_function/'].post.operationId).to.equal('service_localhost_my_function');
56315631
expect(result.paths['/my_function/'].post.requestBody).to.exist;
56325632
expect(result.paths['/my_function/'].post.requestBody.content).to.exist;
56335633
expect(result.paths['/my_function/'].post.requestBody.content['application/json']).to.exist;

0 commit comments

Comments
 (0)