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()
|
||||
.addName(parameter.paramName)
|
||||
.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()
|
||||
.addName(serverVariableEntry.getKey())
|
||||
.addType("string")
|
||||
.addExample(serverVariableEntry.getValue().getDefault())));
|
||||
.addeDefaultValue(serverVariableEntry.getValue().getDefault())));
|
||||
}
|
||||
|
||||
return super.fromServerVariables(variables);
|
||||
@ -402,7 +402,7 @@ public class PostmanCollectionCodegen extends DefaultCodegen implements CodegenC
|
||||
variables.add(new PostmanVariable()
|
||||
.addName(var)
|
||||
.addType("string")
|
||||
.addExample(""));
|
||||
.addeDefaultValue(""));
|
||||
}
|
||||
}
|
||||
|
||||
@ -799,7 +799,7 @@ public class PostmanCollectionCodegen extends DefaultCodegen implements CodegenC
|
||||
|
||||
private String name;
|
||||
private String type;
|
||||
private String example;
|
||||
private String defaultValue;
|
||||
|
||||
public PostmanVariable addName(String name) {
|
||||
this.name = name;
|
||||
@ -811,8 +811,8 @@ public class PostmanCollectionCodegen extends DefaultCodegen implements CodegenC
|
||||
return this;
|
||||
}
|
||||
|
||||
public PostmanVariable addExample(String example) {
|
||||
this.example = example;
|
||||
public PostmanVariable addeDefaultValue(String defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -832,12 +832,12 @@ public class PostmanCollectionCodegen extends DefaultCodegen implements CodegenC
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getExample() {
|
||||
return example;
|
||||
public String getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public void setExample(String example) {
|
||||
this.example = example;
|
||||
public void setDefaultValue(String defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -858,7 +858,7 @@ public class PostmanCollectionCodegen extends DefaultCodegen implements CodegenC
|
||||
return "PostmanVariable{" +
|
||||
"name='" + name + '\'' +
|
||||
", type='" + type + '\'' +
|
||||
", example='" + example + '\'' +
|
||||
", defaultValue='" + defaultValue + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -66,7 +66,7 @@
|
||||
{
|
||||
{{! use first element in vendorExtensions }}
|
||||
"key": "{{name}}",
|
||||
"value": "{{example}}",
|
||||
"value": "{{defaultValue}}",
|
||||
"type": "{{type}}"
|
||||
}{{^-last}},{{/-last}}{{/variables}}{{/-first}}{{/vendorExtensions}}{{/apis}}{{/apiInfo}}
|
||||
]
|
||||
|
@ -138,13 +138,22 @@ public class PostmanCollectionCodegenTest {
|
||||
|
||||
files.forEach(File::deleteOnExit);
|
||||
|
||||
assertFileExists(Paths.get(output + "/postman.json"));
|
||||
Path path = Paths.get(output + "/postman.json");
|
||||
assertFileExists(path);
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
JsonNode jsonNode = objectMapper.readTree(new File(output + "/postman.json"));
|
||||
// verify json has variables
|
||||
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
|
||||
|
@ -244,6 +244,31 @@ paths:
|
||||
description: Create a new user.
|
||||
tags:
|
||||
- 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:
|
||||
securitySchemes:
|
||||
BasicAuth:
|
||||
@ -303,6 +328,20 @@ components:
|
||||
- lastName
|
||||
- email
|
||||
- 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:
|
||||
get-user-basic:
|
||||
summary: Example request for Get User
|
||||
|
@ -77,6 +77,53 @@
|
||||
"name": "advanced",
|
||||
"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}}",
|
||||
"description": "Retrieve the information of the user with the matching user ID.",
|
||||
"item": [
|
||||
@ -268,6 +315,11 @@
|
||||
"value": "v1",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"key": "groupId",
|
||||
"value": "1",
|
||||
"type": "number"
|
||||
},
|
||||
{
|
||||
"key": "port",
|
||||
"value": "5000",
|
||||
@ -275,7 +327,7 @@
|
||||
},
|
||||
{
|
||||
"key": "userId",
|
||||
"value": "a",
|
||||
"value": "",
|
||||
"type": "number"
|
||||
}
|
||||
]
|
||||
|
Loading…
x
Reference in New Issue
Block a user