From fd8afecfcbade0455e2db2e56aba9bb2f6c586ac Mon Sep 17 00:00:00 2001 From: markusthegeek Date: Thu, 13 Feb 2025 16:09:54 -0800 Subject: [PATCH 1/9] allow to add $. in front of JSON example keys; this will then use "jsonpath" vs "json" and can be used when not all keys can be compared via "json" mode e.g. eTags, last modified date, dynamic URLs --- index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 9d87f78..64dbd8b 100644 --- a/index.js +++ b/index.js @@ -171,8 +171,14 @@ async function generateWorkflow (file, options) { step.http.check.schema = responseContent.schema } + const jsonPathIndicator = "$." + if (options.check.examples) { - step.http.check.json = responseContent.example || (responseContent.examples ? Object.values(responseContent.examples)[0].value : undefined) + if (responseContent.example && JSON.stringify(responseContent.example).includes(jsonPathIndicator) || (responseContent.examples && JSON.stringify(Object.values(responseContent.examples)[0].value).includes(jsonPathIndicator))) { + step.http.check.jsonpath = responseContent.example || (responseContent.examples ? Object.values(responseContent.examples)[0].value : undefined) + } else { + step.http.check.json = responseContent.example || (responseContent.examples ? Object.values(responseContent.examples)[0].value : undefined) + } } } } From b0d6599bdea3e2d0c6b4002c524d99fb9816b23a Mon Sep 17 00:00:00 2001 From: markusthegeek Date: Thu, 13 Feb 2025 17:03:24 -0800 Subject: [PATCH 2/9] fixing misc logic issues in previous paramter example(s) and request body example(s) code that would always use the fake Latin values --- index.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 64dbd8b..e4bcc29 100644 --- a/index.js +++ b/index.js @@ -23,7 +23,7 @@ const defaultOptions = { JSONSchemaFaker.format('binary', () => 'file.txt') -async function generateWorkflow (file, options) { +async function generateWorkflow(file, options) { options = merge(defaultOptions, options) JSONSchemaFaker.option({ @@ -73,8 +73,8 @@ async function generateWorkflow (file, options) { const value = param.schema?.default || param.example - || (param.examples && Object.keys(param.examples > 0) ? Object.values(param.examples)[0].value : false) - || param.schema ? JSONSchemaFaker.generate(param.schema, taggedSchemas) : false + || (param.examples && Object.keys(param.examples).length > 0 ? Object.values(param.examples)[0] : false) + || (param.schema ? JSONSchemaFaker.generate(param.schema, taggedSchemas) : false) if (param.in === 'path' && options.generator.pathParams) { step.http.url = step.http.url.replace(`{${param.name}}`, value) @@ -103,8 +103,8 @@ async function generateWorkflow (file, options) { for (const contentType in requestBody) { const body = requestBody[contentType].example - || (requestBody[contentType].examples && Object.keys(requestBody[contentType].examples) > 0) ? Object.values(requestBody[contentType].examples)[0].value : false - || JSONSchemaFaker.generate(requestBody[contentType].schema, taggedSchemas) + || ((requestBody[contentType].examples && Object.keys(requestBody[contentType].examples).length > 0) ? Object.values(requestBody[contentType].examples)[0].value : false) + || (requestBody[contentType].schema ? JSONSchemaFaker.generate(requestBody[contentType].schema, taggedSchemas) : false) if (!step.http.headers) step.http.headers = {} const bodyExists = step.http.json || step.http.xml || step.http.body || step.http.form || step.http.formData @@ -153,7 +153,7 @@ async function generateWorkflow (file, options) { if (swagger.paths[path][method].responses) { const response = Object.values(swagger.paths[path][method].responses)[0] - const responseContent = response.content?.[options.contentType] + const responseContent = response.content?.[options.contentType] if (response) { if (Object.keys(options.check).length !== 0) step.http.check = {} @@ -210,7 +210,7 @@ async function generateWorkflow (file, options) { return workflow } -async function generateWorkflowFile (file, output, options) { +async function generateWorkflowFile(file, output, options) { return fs.promises.writeFile(output, dump(await generateWorkflow(file, options), { quotingType: '"' })) From d04f050e2e166fc44c5e538a0781de596dd68d2f Mon Sep 17 00:00:00 2001 From: markusthegeek Date: Thu, 13 Feb 2025 19:13:32 -0800 Subject: [PATCH 3/9] increase version --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7234d13..36b2a20 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@stepci/plugin-openapi", - "version": "0.4.2", + "version": "0.4.3", "description": "Step CI OpenAPI Plugin", "main": "index.js", "repository": { @@ -22,4 +22,4 @@ "js-yaml": "^4.1.0", "json-schema-faker": "^0.5.0-rcv.44" } -} +} \ No newline at end of file From 751ee9f3d8fd2ebd77ea08bef9a1d9543f8c71d9 Mon Sep 17 00:00:00 2001 From: markusthegeek Date: Tue, 18 Feb 2025 12:30:42 -0800 Subject: [PATCH 4/9] only use "$" to detect jsonpath e.g. for $[0] --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index e4bcc29..8c96c45 100644 --- a/index.js +++ b/index.js @@ -171,7 +171,7 @@ async function generateWorkflow(file, options) { step.http.check.schema = responseContent.schema } - const jsonPathIndicator = "$." + const jsonPathIndicator = "$" if (options.check.examples) { if (responseContent.example && JSON.stringify(responseContent.example).includes(jsonPathIndicator) || (responseContent.examples && JSON.stringify(Object.values(responseContent.examples)[0].value).includes(jsonPathIndicator))) { From b4d7fdd0ed38ff52b2bf9a37e72330ec091a68fb Mon Sep 17 00:00:00 2001 From: markusthegeek Date: Mon, 24 Feb 2025 17:19:50 -0800 Subject: [PATCH 5/9] add test file; do not add schema section to workflow file by default --- index.js | 2 +- tests/index-jsonpath.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 tests/index-jsonpath.js diff --git a/index.js b/index.js index 8c96c45..9f8b084 100644 --- a/index.js +++ b/index.js @@ -11,7 +11,7 @@ const defaultOptions = { optionalParams: true, useExampleValues: true, useDefaultValues: true, - inlineSchema: true + inlineSchema: false }, check: { status: true, diff --git a/tests/index-jsonpath.js b/tests/index-jsonpath.js new file mode 100644 index 0000000..d3c669e --- /dev/null +++ b/tests/index-jsonpath.js @@ -0,0 +1,14 @@ +const { generateWorkflowFile } = require('../index.js') +generateWorkflowFile('./tests/swagger.json', 'workflow.yml', { + check: { + schema: false + }, + generator: { + pathParams: true, + requestBody: true, + optionalParams: true, + useExampleValues: true, + useDefaultValues: false, + inlineSchema: false + } +}) From 08ac02aa995d2ea6eea7208b21470b96646f411a Mon Sep 17 00:00:00 2001 From: markusthegeek Date: Mon, 24 Feb 2025 17:28:27 -0800 Subject: [PATCH 6/9] fix args in the ts file as well --- index.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 859e2d6..12b5177 100644 --- a/index.d.ts +++ b/index.d.ts @@ -4,7 +4,8 @@ export declare type GenerateWorkflowOptions = { requestBody: boolean, optionalParams: boolean, useExampleValues: boolean, - useDefaultValues: boolean + useDefaultValues: boolean, + inlineSchema: boolean }, check: { status: boolean, From fe1da5ebe93bd9f59471d2e007416a7c283c3e7a Mon Sep 17 00:00:00 2001 From: markusthegeek Date: Mon, 24 Feb 2025 18:34:57 -0800 Subject: [PATCH 7/9] update version so that npm does not reinstal old version from cache --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 36b2a20..2e5414c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@stepci/plugin-openapi", - "version": "0.4.3", + "version": "0.4.4", "description": "Step CI OpenAPI Plugin", "main": "index.js", "repository": { From 883e864557fb2f873b15d9d3723b882ce56e8482 Mon Sep 17 00:00:00 2001 From: markusthegeek Date: Thu, 6 Mar 2025 13:49:20 -0800 Subject: [PATCH 8/9] determine the schema generation based on the check schema test option --- index.d.ts | 3 +-- index.js | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/index.d.ts b/index.d.ts index 12b5177..859e2d6 100644 --- a/index.d.ts +++ b/index.d.ts @@ -4,8 +4,7 @@ export declare type GenerateWorkflowOptions = { requestBody: boolean, optionalParams: boolean, useExampleValues: boolean, - useDefaultValues: boolean, - inlineSchema: boolean + useDefaultValues: boolean }, check: { status: boolean, diff --git a/index.js b/index.js index 9f8b084..0c7f46c 100644 --- a/index.js +++ b/index.js @@ -11,7 +11,7 @@ const defaultOptions = { optionalParams: true, useExampleValues: true, useDefaultValues: true, - inlineSchema: false + //inlineSchema: true }, check: { status: true, @@ -46,7 +46,7 @@ async function generateWorkflow(file, options) { const taggedSchemas = [] if (swagger.components?.schemas) { - if (options.generator.inlineSchema) { + if (options.check.schema) { workflow.components = { schemas: swagger.components?.schemas } From aace49d3f15c0393214018bad054e551d7a7c6b1 Mon Sep 17 00:00:00 2001 From: markusthegeek Date: Fri, 7 Mar 2025 15:39:17 -0800 Subject: [PATCH 9/9] increase version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2e5414c..a8ae747 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@stepci/plugin-openapi", - "version": "0.4.4", + "version": "0.4.5", "description": "Step CI OpenAPI Plugin", "main": "index.js", "repository": {