Skip to content

Commit 3b484ab

Browse files
EnriqueGomez12dariocloudappiadmin-cloudappi
authored
Microcks headers added (#33)
* A function is added that if there are examples, add them to the headers with the key X-Microcks-Response-Name key --------- Co-authored-by: Dario Quinde <dario.quinde@cloudappi.net> Co-authored-by: admin-cloudappi <admin@cloudappi.net>
1 parent d999656 commit 3b484ab

19 files changed

+1539
-393
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [2.1.0] - 2024-10-8
9+
10+
## Added
11+
12+
### Microcks headers added
13+
14+
- Added 'microcks_headers' parameter in the environments config section to auto configure the Micrkocs headers.
15+
16+
17+
[2.1.0]: https://github.com/openapi2postman/releases/tag/2.1.0

example/o2p_config_file.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"target_folder": "pruebas",
3232
"has_scopes": false,
3333
"application_token": false,
34-
"number_of_scopes": 0
34+
"number_of_scopes": 0,
35+
"microcks_headers": false
3536
},
3637
{
3738
"name" : "PROD",
@@ -44,7 +45,8 @@
4445
"custom_authorizations_file": "authorizations.postman_collection.json",
4546
"has_scopes": false,
4647
"application_token": true,
47-
"number_of_scopes": 0
48+
"number_of_scopes": 0,
49+
"microcks_headers": false
4850
}
4951
]
5052
}

index.js

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
'use strict'
44
const path = require('path');
55
const _ = require('lodash');
6+
const examples = require('./src/generator/examples');
67
const argv = require('yargs')(process.argv.slice(2))
78
.option('c', {
89
alias: 'configuration',
@@ -77,14 +78,18 @@ _.forEach(endpointsParsed, function (endpointParsed, i) {
7778
endpointsParsed[i].authorization = require('./src/parser/authorization.js')(endpointParsed.verb, endpointParsed.path, authorizationTokens)
7879
endpointsParsed[i].queryParams = require('./src/parser/'+version+'/queryParams.js')(endpointParsed.verb, endpointParsed.path)
7980
endpointsParsed[i].summary = require('./src/parser/summary.js')(endpointParsed.verb, endpointParsed.path)
81+
endpointsParsed[i].microcks = require('./src/parser/openapi3/microcks.js')(endpointParsed.verb, endpointParsed.path)
8082
});
83+
8184
//GENERATOR-------------------------------- */
8285
let endpointsPostman = [];
8386
const endpoints = require('./src/generator/endpoints.js')(endpointsParsed);
87+
8488
_.forEach(endpoints, function (endpoint, i) {
8589
endpoint = require('./src/generator/testStatus.js')(endpoint);
8690
endpoint = require('./src/generator/testBody.js')(endpoint, configurationFile);
8791
endpoint = require('./src/generator/contentType.js')(endpoint);
92+
endpoint = require("./src/generator/microcks.js")(endpoint);
8893
endpoint = require('./src/generator/authorization.js')(endpoint, endpoint.aux.status)
8994
global.currentId = endpoint.request.method + endpoint.request.url.path[0]
9095
global.currentId = global.currentId.replace(/{{/g,'{').replace(/}}/g,'}').split('?')[0]
@@ -148,8 +153,36 @@ _.forEach(environments, function (element) {
148153
if ( element.read_only ) {
149154
exclude.write = true
150155
}
151-
// Se añaden casos de éxito por cada scope indicado en el fichero de configuración
152-
// También se añaden los nuevos tokens como variables en la cabecera Authorization
156+
if (element.microcks_headers) {
157+
let actualLength = endpointsStage.length;
158+
for (let i = 0; i < actualLength; i++) {
159+
const endpoint = endpointsStage[i];
160+
const responseNameHeader = endpoint.request.header.find(
161+
(h) => h.key === 'X-Microcks-Response-Name'
162+
);
163+
164+
if (!responseNameHeader) {
165+
if (!endpoint.request.header) {
166+
endpoint.request.header = [];
167+
}
168+
const pathArray = endpoint.request.url.path;
169+
const path = '/' + pathArray.join('/');
170+
const method = endpoint.request.method;
171+
const status = endpoint.aux.status.toString();
172+
173+
const exampleName = examples(path, method, status);
174+
175+
const headerValue = exampleName || 'default';
176+
177+
endpoint.request.header.push({
178+
key: 'X-Microcks-Response-Name',
179+
value: headerValue
180+
});
181+
}
182+
}
183+
}
184+
185+
153186
if (element.has_scopes) {
154187
let actualLength = endpointsStage.length;
155188
for (let i = 0; i < actualLength; i++) {

0 commit comments

Comments
 (0)