forked from loafle/openapi-generator-original
[POSTMAN] Use parameter default value (#16027)
* Refactor to use defaultValue * Test parameter with defaultValue * Update samples
This commit is contained in:
parent
a5f1c01548
commit
30d6a2ff80
@ -135,7 +135,7 @@ public class PostmanCollectionCodegen extends DefaultCodegen implements CodegenC
|
|||||||
variables.add(new PostmanVariable()
|
variables.add(new PostmanVariable()
|
||||||
.addName(parameter.paramName)
|
.addName(parameter.paramName)
|
||||||
.addType(mapToPostmanType(parameter.dataType))
|
.addType(mapToPostmanType(parameter.dataType))
|
||||||
.addExample(parameter.example));
|
.addeDefaultValue(parameter.defaultValue));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ public class PostmanCollectionCodegen extends DefaultCodegen implements CodegenC
|
|||||||
variables.entrySet().stream().forEach(serverVariableEntry -> this.variables.add(new PostmanVariable()
|
variables.entrySet().stream().forEach(serverVariableEntry -> this.variables.add(new PostmanVariable()
|
||||||
.addName(serverVariableEntry.getKey())
|
.addName(serverVariableEntry.getKey())
|
||||||
.addType("string")
|
.addType("string")
|
||||||
.addExample(serverVariableEntry.getValue().getDefault())));
|
.addeDefaultValue(serverVariableEntry.getValue().getDefault())));
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.fromServerVariables(variables);
|
return super.fromServerVariables(variables);
|
||||||
@ -402,7 +402,7 @@ public class PostmanCollectionCodegen extends DefaultCodegen implements CodegenC
|
|||||||
variables.add(new PostmanVariable()
|
variables.add(new PostmanVariable()
|
||||||
.addName(var)
|
.addName(var)
|
||||||
.addType("string")
|
.addType("string")
|
||||||
.addExample(""));
|
.addeDefaultValue(""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -799,7 +799,7 @@ public class PostmanCollectionCodegen extends DefaultCodegen implements CodegenC
|
|||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private String type;
|
private String type;
|
||||||
private String example;
|
private String defaultValue;
|
||||||
|
|
||||||
public PostmanVariable addName(String name) {
|
public PostmanVariable addName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@ -811,8 +811,8 @@ public class PostmanCollectionCodegen extends DefaultCodegen implements CodegenC
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PostmanVariable addExample(String example) {
|
public PostmanVariable addeDefaultValue(String defaultValue) {
|
||||||
this.example = example;
|
this.defaultValue = defaultValue;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -832,12 +832,12 @@ public class PostmanCollectionCodegen extends DefaultCodegen implements CodegenC
|
|||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getExample() {
|
public String getDefaultValue() {
|
||||||
return example;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setExample(String example) {
|
public void setDefaultValue(String defaultValue) {
|
||||||
this.example = example;
|
this.defaultValue = defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -858,7 +858,7 @@ public class PostmanCollectionCodegen extends DefaultCodegen implements CodegenC
|
|||||||
return "PostmanVariable{" +
|
return "PostmanVariable{" +
|
||||||
"name='" + name + '\'' +
|
"name='" + name + '\'' +
|
||||||
", type='" + type + '\'' +
|
", type='" + type + '\'' +
|
||||||
", example='" + example + '\'' +
|
", defaultValue='" + defaultValue + '\'' +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@
|
|||||||
{
|
{
|
||||||
{{! use first element in vendorExtensions }}
|
{{! use first element in vendorExtensions }}
|
||||||
"key": "{{name}}",
|
"key": "{{name}}",
|
||||||
"value": "{{example}}",
|
"value": "{{defaultValue}}",
|
||||||
"type": "{{type}}"
|
"type": "{{type}}"
|
||||||
}{{^-last}},{{/-last}}{{/variables}}{{/-first}}{{/vendorExtensions}}{{/apis}}{{/apiInfo}}
|
}{{^-last}},{{/-last}}{{/variables}}{{/-first}}{{/vendorExtensions}}{{/apis}}{{/apiInfo}}
|
||||||
]
|
]
|
||||||
|
@ -138,13 +138,22 @@ public class PostmanCollectionCodegenTest {
|
|||||||
|
|
||||||
files.forEach(File::deleteOnExit);
|
files.forEach(File::deleteOnExit);
|
||||||
|
|
||||||
assertFileExists(Paths.get(output + "/postman.json"));
|
Path path = Paths.get(output + "/postman.json");
|
||||||
|
assertFileExists(path);
|
||||||
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
JsonNode jsonNode = objectMapper.readTree(new File(output + "/postman.json"));
|
JsonNode jsonNode = objectMapper.readTree(new File(output + "/postman.json"));
|
||||||
// verify json has variables
|
// verify json has variables
|
||||||
assertTrue(jsonNode.get("variable") instanceof ArrayNode);
|
assertTrue(jsonNode.get("variable") instanceof ArrayNode);
|
||||||
assertEquals(5, ((ArrayNode) jsonNode.get("variable")).size());
|
assertEquals(6, (jsonNode.get("variable")).size());
|
||||||
|
|
||||||
|
// verify param userId (without default value)
|
||||||
|
TestUtils.assertFileContains(path,
|
||||||
|
"key\": \"userId\", \"value\": \"\", \"type\": \"number\"");
|
||||||
|
// verify param groupId (with default value)
|
||||||
|
TestUtils.assertFileContains(path,
|
||||||
|
"key\": \"groupId\", \"value\": \"1\", \"type\": \"number\"");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -244,6 +244,31 @@ paths:
|
|||||||
description: Create a new user.
|
description: Create a new user.
|
||||||
tags:
|
tags:
|
||||||
- basic
|
- basic
|
||||||
|
'/groups/{groupId}':
|
||||||
|
get:
|
||||||
|
summary: Get group by ID
|
||||||
|
tags:
|
||||||
|
- advanced
|
||||||
|
parameters:
|
||||||
|
- description: group Id
|
||||||
|
name: groupId
|
||||||
|
in: path
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
default: 1
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: Group Found
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/Group'
|
||||||
|
'404':
|
||||||
|
description: Group Not Found
|
||||||
|
operationId: get-groups-groupId
|
||||||
|
description: Get group of users
|
||||||
|
|
||||||
components:
|
components:
|
||||||
securitySchemes:
|
securitySchemes:
|
||||||
BasicAuth:
|
BasicAuth:
|
||||||
@ -303,6 +328,20 @@ components:
|
|||||||
- lastName
|
- lastName
|
||||||
- email
|
- email
|
||||||
- emailVerified
|
- emailVerified
|
||||||
|
Group:
|
||||||
|
title: Group
|
||||||
|
type: object
|
||||||
|
description: ''
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
description: Unique identifier for the given group.
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
example: admin
|
||||||
|
required:
|
||||||
|
- id
|
||||||
|
- name
|
||||||
examples:
|
examples:
|
||||||
get-user-basic:
|
get-user-basic:
|
||||||
summary: Example request for Get User
|
summary: Example request for Get User
|
||||||
|
@ -77,6 +77,53 @@
|
|||||||
"name": "advanced",
|
"name": "advanced",
|
||||||
"item": [
|
"item": [
|
||||||
{
|
{
|
||||||
|
"name": "/groups/{{groupId}}",
|
||||||
|
"description": "Get group of users",
|
||||||
|
"item": [
|
||||||
|
{
|
||||||
|
"name": "Get group by ID",
|
||||||
|
"request": {
|
||||||
|
"method": "GET",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "Accept",
|
||||||
|
"value": "application/json"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"body": {
|
||||||
|
"mode": "raw",
|
||||||
|
"raw": "",
|
||||||
|
"options": {
|
||||||
|
"raw": {
|
||||||
|
"language": "json"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"url": {
|
||||||
|
"raw": "{{baseUrl}}/groups/{{groupId}}",
|
||||||
|
"host": [
|
||||||
|
"{{baseUrl}}"
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"groups",
|
||||||
|
"{{groupId}}"
|
||||||
|
],
|
||||||
|
"variable": [
|
||||||
|
{
|
||||||
|
"key": "groupId",
|
||||||
|
"value": "",
|
||||||
|
"description": "group Id"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"query": [
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"description": "Get group of users"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
"name": "/users/{{userId}}",
|
"name": "/users/{{userId}}",
|
||||||
"description": "Retrieve the information of the user with the matching user ID.",
|
"description": "Retrieve the information of the user with the matching user ID.",
|
||||||
"item": [
|
"item": [
|
||||||
@ -268,6 +315,11 @@
|
|||||||
"value": "v1",
|
"value": "v1",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"key": "groupId",
|
||||||
|
"value": "1",
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"key": "port",
|
"key": "port",
|
||||||
"value": "5000",
|
"value": "5000",
|
||||||
@ -275,7 +327,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "userId",
|
"key": "userId",
|
||||||
"value": "a",
|
"value": "",
|
||||||
"type": "number"
|
"type": "number"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user