|
3 | 3 | 'use strict' |
4 | 4 | const path = require('path'); |
5 | 5 | const _ = require('lodash'); |
| 6 | +const examples = require('./src/generator/examples'); |
6 | 7 | const argv = require('yargs')(process.argv.slice(2)) |
7 | 8 | .option('c', { |
8 | 9 | alias: 'configuration', |
@@ -77,14 +78,18 @@ _.forEach(endpointsParsed, function (endpointParsed, i) { |
77 | 78 | endpointsParsed[i].authorization = require('./src/parser/authorization.js')(endpointParsed.verb, endpointParsed.path, authorizationTokens) |
78 | 79 | endpointsParsed[i].queryParams = require('./src/parser/'+version+'/queryParams.js')(endpointParsed.verb, endpointParsed.path) |
79 | 80 | 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) |
80 | 82 | }); |
| 83 | + |
81 | 84 | //GENERATOR-------------------------------- */ |
82 | 85 | let endpointsPostman = []; |
83 | 86 | const endpoints = require('./src/generator/endpoints.js')(endpointsParsed); |
| 87 | + |
84 | 88 | _.forEach(endpoints, function (endpoint, i) { |
85 | 89 | endpoint = require('./src/generator/testStatus.js')(endpoint); |
86 | 90 | endpoint = require('./src/generator/testBody.js')(endpoint, configurationFile); |
87 | 91 | endpoint = require('./src/generator/contentType.js')(endpoint); |
| 92 | + endpoint = require("./src/generator/microcks.js")(endpoint); |
88 | 93 | endpoint = require('./src/generator/authorization.js')(endpoint, endpoint.aux.status) |
89 | 94 | global.currentId = endpoint.request.method + endpoint.request.url.path[0] |
90 | 95 | global.currentId = global.currentId.replace(/{{/g,'{').replace(/}}/g,'}').split('?')[0] |
@@ -148,8 +153,36 @@ _.forEach(environments, function (element) { |
148 | 153 | if ( element.read_only ) { |
149 | 154 | exclude.write = true |
150 | 155 | } |
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 | + |
153 | 186 | if (element.has_scopes) { |
154 | 187 | let actualLength = endpointsStage.length; |
155 | 188 | for (let i = 0; i < actualLength; i++) { |
|
0 commit comments