diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PostmanCollectionCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PostmanCollectionCodegen.java index 104ca898608..700e41a6d4f 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PostmanCollectionCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PostmanCollectionCodegen.java @@ -8,6 +8,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode; import io.swagger.v3.core.util.Json; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.examples.Example; +import io.swagger.v3.oas.models.media.Schema; import io.swagger.v3.oas.models.servers.ServerVariable; import org.openapitools.codegen.*; import org.openapitools.codegen.meta.GeneratorMetadata; @@ -462,6 +463,24 @@ public class PostmanCollectionCodegen extends DefaultCodegen implements CodegenC return input; } + /** + * Return the default value of the property + *

+ * Return null when the default is not defined + * + * @param schema Property schema + * @return string presentation of the default value of the property + */ + @SuppressWarnings("static-method") + @Override + public String toDefaultValue(Schema schema) { + if (schema.getDefault() != null) { + return schema.getDefault().toString(); + } + + return null; + } + /** * Escape single and/or double quote to avoid code injection * 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 62bfa5f52d9..fa7225826f8 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 @@ -485,7 +485,10 @@ public class PostmanCollectionCodegenTest { TestUtils.assertFileExists(path); TestUtils.assertFileContains(path, "{ \"key\": \"Content-Type\", \"value\": \"application/json\""); TestUtils.assertFileContains(path, "{ \"key\": \"Accept\", \"value\": \"application/json\""); - TestUtils.assertFileContains(path, "{ \"key\": \"Custom-Header\", \"value\": \"null\""); + // header without default value + TestUtils.assertFileContains(path, "{ \"key\": \"Custom-Header\", \"value\": \"\""); + // header with default value + TestUtils.assertFileContains(path, "{ \"key\": \"Another-Custom-Header\", \"value\": \"abc\""); } diff --git a/modules/openapi-generator/src/test/resources/3_0/postman-collection/SampleProject.yaml b/modules/openapi-generator/src/test/resources/3_0/postman-collection/SampleProject.yaml index 68880c12bc1..97786ebeeb4 100644 --- a/modules/openapi-generator/src/test/resources/3_0/postman-collection/SampleProject.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/postman-collection/SampleProject.yaml @@ -52,6 +52,12 @@ paths: in: header schema: type: string + - description: Custom HTTP header with default + name: Another-Custom-Header + in: header + schema: + type: string + default: abc responses: '200': diff --git a/samples/client/petstore/csharp/OpenAPIClient-generichost-net6.0-nrt/src/Org.OpenAPITools/Api/FakeApi.cs b/samples/client/petstore/csharp/OpenAPIClient-generichost-net6.0-nrt/src/Org.OpenAPITools/Api/FakeApi.cs index 7868e9af673..a7044ed145e 100644 --- a/samples/client/petstore/csharp/OpenAPIClient-generichost-net6.0-nrt/src/Org.OpenAPITools/Api/FakeApi.cs +++ b/samples/client/petstore/csharp/OpenAPIClient-generichost-net6.0-nrt/src/Org.OpenAPITools/Api/FakeApi.cs @@ -2023,15 +2023,20 @@ namespace Org.OpenAPITools.Api ///

/// Validates the request parameters /// + /// /// /// /// /// /// /// + /// /// private void ValidateTestEnumParameters(Option> enumHeaderStringArray, Option> enumQueryStringArray, Option> enumFormStringArray, Option enumHeaderString, Option enumQueryString, Option enumFormString) { + if (enumHeaderString.IsSet && enumHeaderString.Value == null) + throw new ArgumentNullException(nameof(enumHeaderString)); + if (enumHeaderStringArray.IsSet && enumHeaderStringArray.Value == null) throw new ArgumentNullException(nameof(enumHeaderStringArray)); @@ -2049,6 +2054,9 @@ namespace Org.OpenAPITools.Api if (enumFormString.IsSet && enumFormString.Value == null) throw new ArgumentNullException(nameof(enumFormString)); + + if (enumQueryString.IsSet && enumQueryString.Value == null) + throw new ArgumentNullException(nameof(enumQueryString)); } /// diff --git a/samples/schema/postman-collection/postman.json b/samples/schema/postman-collection/postman.json index 3e411b1726e..a0951aaa1c7 100644 --- a/samples/schema/postman-collection/postman.json +++ b/samples/schema/postman-collection/postman.json @@ -35,7 +35,7 @@ }, { "key": "strCode2", - "value": "null" + "value": "" } ], "body": { @@ -95,7 +95,7 @@ }, { "key": "strCode2", - "value": "null" + "value": "" } ], "body": { @@ -151,7 +151,11 @@ }, { "key": "Custom-Header", - "value": "null" + "value": "" + }, + { + "key": "Another-Custom-Header", + "value": "abc" } ], "body": {