From 2aa75802dcfdc738fc2d1bea22baf3a8718c6f12 Mon Sep 17 00:00:00 2001 From: Beppe Catanese <1771700+gcatanese@users.noreply.github.com> Date: Fri, 7 Jul 2023 19:06:32 +0200 Subject: [PATCH] [POSTMAN] Mark request header as disabled (#16028) * Disable headers without a value * Update samples --- .../postman-collection/item.mustache | 3 +- .../postman/PostmanCollectionCodegenTest.java | 9 ++--- .../schema/postman-collection/postman.json | 36 ++++++++++++------- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/postman-collection/item.mustache b/modules/openapi-generator/src/main/resources/postman-collection/item.mustache index 51174aa657b..416e0d8cdad 100644 --- a/modules/openapi-generator/src/main/resources/postman-collection/item.mustache +++ b/modules/openapi-generator/src/main/resources/postman-collection/item.mustache @@ -11,7 +11,8 @@ {{#headerParams}} { "key": "{{baseName}}", - "value": "{{schema.defaultValue}}" + "value": "{{schema.defaultValue}}", + "disabled": {{#schema.defaultValue}}false{{/schema.defaultValue}}{{^schema.defaultValue}}true{{/schema.defaultValue}} }{{^-last}},{{/-last}} {{/headerParams}} ], diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/postman/PostmanCollectionCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/postman/PostmanCollectionCodegenTest.java index 4f679903b5e..374d591b549 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/postman/PostmanCollectionCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/postman/PostmanCollectionCodegenTest.java @@ -494,10 +494,11 @@ public class PostmanCollectionCodegenTest { TestUtils.assertFileExists(path); TestUtils.assertFileContains(path, "{ \"key\": \"Content-Type\", \"value\": \"application/json\""); TestUtils.assertFileContains(path, "{ \"key\": \"Accept\", \"value\": \"application/json\""); - // header without default value - TestUtils.assertFileContains(path, "{ \"key\": \"Custom-Header\", \"value\": \"\""); - // header with default value - TestUtils.assertFileContains(path, "{ \"key\": \"Another-Custom-Header\", \"value\": \"abc\""); + // header without default value (disabled: true) + TestUtils.assertFileContains(path, "{ \"key\": \"Custom-Header\", \"value\": \"\", \"disabled\": true"); + // header with default value (disabled: false) + TestUtils.assertFileContains(path, "{ \"key\": \"Another-Custom-Header\", \"value\": \"abc\", \"disabled\": false"); + } diff --git a/samples/schema/postman-collection/postman.json b/samples/schema/postman-collection/postman.json index e787aceb749..d89081648a1 100644 --- a/samples/schema/postman-collection/postman.json +++ b/samples/schema/postman-collection/postman.json @@ -23,19 +23,23 @@ "header": [ { "key": "Content-Type", - "value": "application/json" + "value": "application/json", + "disabled": false }, { "key": "Accept", - "value": "application/json" + "value": "application/json", + "disabled": false }, { "key": "strCode", - "value": "code_one" + "value": "code_one", + "disabled": false }, { "key": "strCode2", - "value": "" + "value": "", + "disabled": true } ], "body": { @@ -134,15 +138,18 @@ "header": [ { "key": "Accept", - "value": "application/json" + "value": "application/json", + "disabled": false }, { "key": "strCode", - "value": "code_one" + "value": "code_one", + "disabled": false }, { "key": "strCode2", - "value": "" + "value": "", + "disabled": true } ], "body": { @@ -194,15 +201,18 @@ "header": [ { "key": "Accept", - "value": "application/json" + "value": "application/json", + "disabled": false }, { "key": "Custom-Header", - "value": "" + "value": "", + "disabled": true }, { "key": "Another-Custom-Header", - "value": "abc" + "value": "abc", + "disabled": false } ], "body": { @@ -247,11 +257,13 @@ "header": [ { "key": "Content-Type", - "value": "application/json" + "value": "application/json", + "disabled": false }, { "key": "Accept", - "value": "application/json" + "value": "application/json", + "disabled": false } ], "body": {