From 76d3be8f67d672a130787431b7f1151c660fbb8c Mon Sep 17 00:00:00 2001 From: Tim <> Date: Fri, 5 Jun 2020 12:51:28 +0200 Subject: [PATCH] #204 Added support for path variables, using examples based on the configuration option "requestParametersResolution" --- lib/schemaUtils.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/schemaUtils.js b/lib/schemaUtils.js index 6cad6234f..5049dec5d 100644 --- a/lib/schemaUtils.js +++ b/lib/schemaUtils.js @@ -761,13 +761,21 @@ module.exports = { } else { _.forEach(commonPathVars, (variable) => { - let description = this.getParameterDescription(variable); + let description = this.getParameterDescription(variable), + paramValue = options.schemaFaker ? + safeSchemaFaker(variable.schema || {}, 'schema', components, 'REQUEST', + SCHEMA_FORMATS.DEFAULT, options.indentCharacter, schemaCache) : ''; + + // Use path variable example value as param value + // Reference to https://github.com/postmanlabs/openapi-to-postman/issues/204 + if (options.requestParametersResolution === 'example' && variable.schema && variable.schema.example) { + paramValue = variable.schema.example; + } + variables.push({ key: variable.name, // we only fake the schema for param-level pathVars - value: options.schemaFaker ? - safeSchemaFaker(variable.schema || {}, 'schema', components, 'REQUEST', - SCHEMA_FORMATS.DEFAULT, options.indentCharacter, schemaCache) : '', + value: paramValue, description: description }); });