forked from loafle/openapi-generator-original
[BUG] Change default value for header parameter (#15990)
* Override toDefaultValue method * Regenerate sample
This commit is contained in:
parent
9170306ffa
commit
315fbff680
@ -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
|
||||
* <p>
|
||||
* 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
|
||||
*
|
||||
|
@ -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\"");
|
||||
}
|
||||
|
||||
|
||||
|
@ -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':
|
||||
|
@ -2023,15 +2023,20 @@ namespace Org.OpenAPITools.Api
|
||||
/// <summary>
|
||||
/// Validates the request parameters
|
||||
/// </summary>
|
||||
/// <param name="enumHeaderString"></param>
|
||||
/// <param name="enumHeaderStringArray"></param>
|
||||
/// <param name="enumQueryStringArray"></param>
|
||||
/// <param name="enumFormStringArray"></param>
|
||||
/// <param name="enumHeaderString"></param>
|
||||
/// <param name="enumQueryString"></param>
|
||||
/// <param name="enumFormString"></param>
|
||||
/// <param name="enumQueryString"></param>
|
||||
/// <returns></returns>
|
||||
private void ValidateTestEnumParameters(Option<List<string>> enumHeaderStringArray, Option<List<string>> enumQueryStringArray, Option<List<string>> enumFormStringArray, Option<string> enumHeaderString, Option<string> enumQueryString, Option<string> 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));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -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": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user