[Postman Collections] Keep original header name (#15907)

* Define baseName for Postman headers

* Use header original name

* Commit regenerated files
This commit is contained in:
Beppe Catanese 2023-07-02 17:36:23 +02:00 committed by GitHub
parent 22e1e4e450
commit 3224e86377
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 5 deletions

View File

@ -226,6 +226,7 @@ public class PostmanCollectionCodegen extends DefaultCodegen implements CodegenC
// produces mediaType as `Accept` header (use first mediaType only)
String mediaType = codegenOperation.produces.get(0).get("mediaType");
CodegenParameter acceptHeader = new CodegenParameter();
acceptHeader.baseName = "Accept";
acceptHeader.paramName = "Accept";
CodegenProperty schema = new CodegenProperty();
schema.defaultValue = mediaType;
@ -237,6 +238,8 @@ public class PostmanCollectionCodegen extends DefaultCodegen implements CodegenC
// consumes mediaType as `Content-Type` header (use first mediaType only)
String mediaType = codegenOperation.consumes.get(0).get("mediaType");
CodegenParameter contentTypeHeader = new CodegenParameter();
contentTypeHeader.baseName = "Content-Type";
contentTypeHeader.paramName = "Content-Type";
CodegenProperty schema = new CodegenProperty();
schema.defaultValue = mediaType;

View File

@ -10,7 +10,7 @@
"header": [
{{#headerParams}}
{
"key": "{{paramName}}",
"key": "{{baseName}}",
"value": "{{schema.defaultValue}}"
}{{^-last}},{{/-last}}
{{/headerParams}}

View File

@ -6,10 +6,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.junit.Assert;
import org.junit.Test;
import org.openapitools.codegen.ClientOptInput;
import org.openapitools.codegen.CodegenParameter;
import org.openapitools.codegen.CodegenProperty;
import org.openapitools.codegen.DefaultGenerator;
import org.openapitools.codegen.*;
import org.openapitools.codegen.config.CodegenConfigurator;
import org.openapitools.codegen.languages.PostmanCollectionCodegen;
@ -466,6 +463,32 @@ public class PostmanCollectionCodegenTest {
}
@Test
public void testHeaderParameters() throws IOException {
File output = Files.createTempDirectory("postmantest_").toFile();
output.deleteOnExit();
final CodegenConfigurator configurator = new CodegenConfigurator()
.setGeneratorName("postman-collection")
.setInputSpec("./src/test/resources/SampleProject.yaml")
.setInputSpec("src/test/resources/3_0/postman-collection/SampleProject.yaml")
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));
final ClientOptInput clientOptInput = configurator.toClientOptInput();
DefaultGenerator generator = new DefaultGenerator();
List<File> files = generator.opts(clientOptInput).generate();
files.forEach(File::deleteOnExit);
Path path = Paths.get(output + "/postman.json");
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\"");
}
@Test
public void testFormatDescription() {

View File

@ -47,6 +47,11 @@ paths:
schema:
type: string
example: 888
- description: Custom HTTP header
name: Custom-Header
in: header
schema:
type: string
responses:
'200':

View File

@ -148,6 +148,10 @@
{
"key": "Accept",
"value": "application/json"
},
{
"key": "Custom-Header",
"value": "null"
}
],
"body": {