forked from loafle/openapi-generator-original
[Postman Collections] Keep original header name (#15907)
* Define baseName for Postman headers * Use header original name * Commit regenerated files
This commit is contained in:
parent
22e1e4e450
commit
3224e86377
@ -226,6 +226,7 @@ public class PostmanCollectionCodegen extends DefaultCodegen implements CodegenC
|
|||||||
// produces mediaType as `Accept` header (use first mediaType only)
|
// produces mediaType as `Accept` header (use first mediaType only)
|
||||||
String mediaType = codegenOperation.produces.get(0).get("mediaType");
|
String mediaType = codegenOperation.produces.get(0).get("mediaType");
|
||||||
CodegenParameter acceptHeader = new CodegenParameter();
|
CodegenParameter acceptHeader = new CodegenParameter();
|
||||||
|
acceptHeader.baseName = "Accept";
|
||||||
acceptHeader.paramName = "Accept";
|
acceptHeader.paramName = "Accept";
|
||||||
CodegenProperty schema = new CodegenProperty();
|
CodegenProperty schema = new CodegenProperty();
|
||||||
schema.defaultValue = mediaType;
|
schema.defaultValue = mediaType;
|
||||||
@ -237,6 +238,8 @@ public class PostmanCollectionCodegen extends DefaultCodegen implements CodegenC
|
|||||||
// consumes mediaType as `Content-Type` header (use first mediaType only)
|
// consumes mediaType as `Content-Type` header (use first mediaType only)
|
||||||
String mediaType = codegenOperation.consumes.get(0).get("mediaType");
|
String mediaType = codegenOperation.consumes.get(0).get("mediaType");
|
||||||
CodegenParameter contentTypeHeader = new CodegenParameter();
|
CodegenParameter contentTypeHeader = new CodegenParameter();
|
||||||
|
|
||||||
|
contentTypeHeader.baseName = "Content-Type";
|
||||||
contentTypeHeader.paramName = "Content-Type";
|
contentTypeHeader.paramName = "Content-Type";
|
||||||
CodegenProperty schema = new CodegenProperty();
|
CodegenProperty schema = new CodegenProperty();
|
||||||
schema.defaultValue = mediaType;
|
schema.defaultValue = mediaType;
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
"header": [
|
"header": [
|
||||||
{{#headerParams}}
|
{{#headerParams}}
|
||||||
{
|
{
|
||||||
"key": "{{paramName}}",
|
"key": "{{baseName}}",
|
||||||
"value": "{{schema.defaultValue}}"
|
"value": "{{schema.defaultValue}}"
|
||||||
}{{^-last}},{{/-last}}
|
}{{^-last}},{{/-last}}
|
||||||
{{/headerParams}}
|
{{/headerParams}}
|
||||||
|
@ -6,10 +6,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
|
|||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.openapitools.codegen.ClientOptInput;
|
import org.openapitools.codegen.*;
|
||||||
import org.openapitools.codegen.CodegenParameter;
|
|
||||||
import org.openapitools.codegen.CodegenProperty;
|
|
||||||
import org.openapitools.codegen.DefaultGenerator;
|
|
||||||
import org.openapitools.codegen.config.CodegenConfigurator;
|
import org.openapitools.codegen.config.CodegenConfigurator;
|
||||||
import org.openapitools.codegen.languages.PostmanCollectionCodegen;
|
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
|
@Test
|
||||||
public void testFormatDescription() {
|
public void testFormatDescription() {
|
||||||
|
|
||||||
|
@ -47,6 +47,11 @@ paths:
|
|||||||
schema:
|
schema:
|
||||||
type: string
|
type: string
|
||||||
example: 888
|
example: 888
|
||||||
|
- description: Custom HTTP header
|
||||||
|
name: Custom-Header
|
||||||
|
in: header
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
|
@ -148,6 +148,10 @@
|
|||||||
{
|
{
|
||||||
"key": "Accept",
|
"key": "Accept",
|
||||||
"value": "application/json"
|
"value": "application/json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "Custom-Header",
|
||||||
|
"value": "null"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"body": {
|
"body": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user