From ac78f1e85bb16f06b5531c527d9a1d64a2128d83 Mon Sep 17 00:00:00 2001 From: Beppe Catanese <1771700+gcatanese@users.noreply.github.com> Date: Sat, 2 Dec 2023 10:41:05 +0100 Subject: [PATCH] [POSTMAN] Enabling required query parameters (#17281) * Enable required query parameters * Generate samples --- .../postman-collection/item.mustache | 3 ++- .../postman/PostmanCollectionCodegenTest.java | 24 +++++++++++++++++++ .../schema/postman-collection/postman.json | 3 ++- 3 files changed, 28 insertions(+), 2 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 a9cc9c49da7..806e62688be 100644 --- a/modules/openapi-generator/src/main/resources/postman-collection/item.mustache +++ b/modules/openapi-generator/src/main/resources/postman-collection/item.mustache @@ -48,7 +48,8 @@ {{#queryParams}} { "key": "{{paramName}}", - "value": "{{example}}" + "value": "{{example}}", + "disabled": {{#required}}false{{/required}}{{^required}}true{{/required}} }{{^-last}},{{/-last}} {{/queryParams}} ] 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 4463a2c5c08..0ee6f5a8f35 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 @@ -755,4 +755,28 @@ public class PostmanCollectionCodegenTest { assertEquals(true, postmanV2Generator.codegenOperationsByTag.containsKey("default")); } + @Test + public void testRequiredQueryParameter() throws IOException { + + File output = Files.createTempDirectory("postmantest_").toFile(); + output.deleteOnExit(); + + final CodegenConfigurator configurator = new CodegenConfigurator() + .setGeneratorName("postman-collection") + .setInputSpec("src/test/resources/3_0/postman-collection/SampleProject.yaml") + .setOutputDir(output.getAbsolutePath().replace("\\", "/")); + + DefaultGenerator generator = new DefaultGenerator(); + List files = generator.opts(configurator.toClientOptInput()).generate(); + + System.out.println(files); + files.forEach(File::deleteOnExit); + + Path path = Paths.get(output + "/postman.json"); + TestUtils.assertFileExists(path); + // verify param pUserId is set as disabled=false + TestUtils.assertFileContains(path, "{ \"key\": \"pUserId\", \"value\": \"888\", \"disabled\": false"); + + } + } diff --git a/samples/schema/postman-collection/postman.json b/samples/schema/postman-collection/postman.json index 8a39ae60676..cd19d5735d1 100644 --- a/samples/schema/postman-collection/postman.json +++ b/samples/schema/postman-collection/postman.json @@ -285,7 +285,8 @@ "query": [ { "key": "pUserId", - "value": "888" + "value": "888", + "disabled": false } ] },