forked from loafle/openapi-generator-original
[POSTMAN] Include response examples (#21073)
* Extract response examples * Add response examples to spec * Generate Postman samples * Test samples
This commit is contained in:
parent
ca1f02500f
commit
c22d790249
@ -24,6 +24,7 @@ import org.slf4j.LoggerFactory;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* OpenAPI generator for Postman Collection format v2.1
|
||||
@ -389,12 +390,14 @@ public class PostmanCollectionCodegen extends DefaultCodegen implements CodegenC
|
||||
String exampleRef = entry.getValue().get$ref();
|
||||
Example example = this.openAPI.getComponents().getExamples().get(extractExampleByName(exampleRef));
|
||||
String exampleAsString = getJsonFromExample(example);
|
||||
String exampleName = entry.getKey();
|
||||
|
||||
items.add(new PostmanRequestItem(example.getSummary(), exampleAsString));
|
||||
items.add(new PostmanRequestItem(exampleName, example.getSummary(), exampleAsString));
|
||||
} else if (entry.getValue().getValue() != null && entry.getValue().getValue() instanceof ObjectNode) {
|
||||
// find inline
|
||||
String exampleAsString = convertToJson((ObjectNode) entry.getValue().getValue());
|
||||
items.add(new PostmanRequestItem(entry.getKey(), exampleAsString));
|
||||
String exampleName = entry.getKey();
|
||||
items.add(new PostmanRequestItem(exampleName, entry.getKey(), exampleAsString));
|
||||
}
|
||||
}
|
||||
} else if (codegenOperation.bodyParam.example != null) {
|
||||
@ -416,6 +419,24 @@ public class PostmanCollectionCodegen extends DefaultCodegen implements CodegenC
|
||||
items.add(new PostmanRequestItem(codegenOperation.summary, ""));
|
||||
}
|
||||
|
||||
// Grabbing responses
|
||||
List<CodegenResponse> responses = codegenOperation.responses;
|
||||
List<PostmanResponse> allPostmanResponses = new ArrayList<>();
|
||||
for (CodegenResponse response : responses) {
|
||||
List<PostmanResponse> postmanResponses = getResponseExamples(response, response.message);
|
||||
allPostmanResponses.addAll(postmanResponses);
|
||||
}
|
||||
|
||||
// Adding responses to corresponding requests
|
||||
for(PostmanRequestItem item: items){
|
||||
List<PostmanResponse> postmanResponses = allPostmanResponses.stream().filter( r -> Objects.equals(r.getId(), item.getId())).collect(Collectors.toList());
|
||||
if(!postmanResponses.isEmpty()){
|
||||
postmanResponses.forEach(r -> r.setOriginalRequest(item));
|
||||
item.addResponses(postmanResponses);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
@ -454,6 +475,37 @@ public class PostmanCollectionCodegen extends DefaultCodegen implements CodegenC
|
||||
return postmanRequests;
|
||||
}
|
||||
|
||||
List<PostmanResponse> getResponseExamples(CodegenResponse codegenResponse, String message) {
|
||||
List<PostmanResponse> postmanResponses = new ArrayList<>();
|
||||
|
||||
if (codegenResponse.getContent() != null && codegenResponse.getContent().get("application/json") != null &&
|
||||
codegenResponse.getContent().get("application/json").getExamples() != null) {
|
||||
|
||||
var examples = codegenResponse.getContent().get("application/json").getExamples();
|
||||
for (Map.Entry<String, Example> entry : examples.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
String ref = entry.getValue().get$ref();
|
||||
|
||||
String response;
|
||||
if (ref != null) {
|
||||
// get example by $ref
|
||||
Example example = this.openAPI.getComponents().getExamples().get(extractExampleByName(ref));
|
||||
response = getJsonFromExample(example);
|
||||
} else {
|
||||
// get inline example
|
||||
response = getJsonFromExample(entry.getValue());
|
||||
}
|
||||
postmanResponses.add(new PostmanResponse(key, codegenResponse, message, response));
|
||||
}
|
||||
|
||||
} else if (codegenResponse.getContent() != null) {
|
||||
// TODO : Implement
|
||||
}
|
||||
|
||||
return postmanResponses;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns human-friendly help for the generator. Provide the consumer with help
|
||||
* tips, parameters here
|
||||
@ -836,17 +888,65 @@ public class PostmanCollectionCodegen extends DefaultCodegen implements CodegenC
|
||||
@Setter
|
||||
public class PostmanRequestItem {
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
private String body;
|
||||
private List<PostmanResponse> responses;
|
||||
|
||||
private PostmanRequestItem originalRequest;
|
||||
|
||||
public PostmanRequestItem() {
|
||||
}
|
||||
|
||||
public PostmanRequestItem(String id, String name, String body) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
public PostmanRequestItem(String name, String body) {
|
||||
this.name = name;
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
public void addResponses(List<PostmanResponse> responses) {
|
||||
if(this.responses == null) { this.responses = new ArrayList<>(); }
|
||||
|
||||
this.responses.addAll(responses);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class PostmanResponse {
|
||||
|
||||
private String id;
|
||||
private String code;
|
||||
private String status;
|
||||
private String name;
|
||||
private String body;
|
||||
private PostmanRequestItem originalRequest;
|
||||
|
||||
public PostmanResponse(String id, CodegenResponse response, String name, String body) {
|
||||
this.id = id;
|
||||
this.code = response.code;
|
||||
this.status = PostmanCollectionCodegen.this.getStatus(response);
|
||||
this.name = name;
|
||||
this.body = body;
|
||||
this.originalRequest = null; // Setting this here explicitly for clarity
|
||||
}
|
||||
|
||||
|
||||
public PostmanRequestItem getOriginalRequest() {
|
||||
return originalRequest;
|
||||
}
|
||||
|
||||
public void setOriginalRequest(PostmanRequestItem originalRequest) {
|
||||
this.originalRequest = originalRequest;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Getter
|
||||
|
@ -5,59 +5,23 @@
|
||||
{{#vendorExtensions.postmanRequests}}
|
||||
{
|
||||
"name": "{{{name}}}",
|
||||
"request": {
|
||||
"method": "{{httpMethod}}",
|
||||
"header": [
|
||||
{{#headerParams}}
|
||||
{
|
||||
"key": "{{baseName}}",
|
||||
"value": "{{schema.defaultValue}}",
|
||||
"description": "{{{description}}}",
|
||||
"disabled": {{#schema.defaultValue}}false{{/schema.defaultValue}}{{^schema.defaultValue}}true{{/schema.defaultValue}}
|
||||
}{{^-last}},{{/-last}}
|
||||
{{/headerParams}}
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{{{body}}}",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{=<% %>=}}{{baseUrl}}<%={{ }}=%>{{{path}}}",
|
||||
"host": [
|
||||
"{{=<% %>=}}{{baseUrl}}<%={{ }}=%>"
|
||||
],
|
||||
"path": [
|
||||
{{#vendorExtensions.pathSegments}}
|
||||
"{{.}}"{{^-last}},{{/-last}}
|
||||
{{/vendorExtensions.pathSegments}}
|
||||
],
|
||||
"variable": [
|
||||
{{#pathParams}}
|
||||
{
|
||||
"key": "{{paramName}}",
|
||||
"value": "{{defaultValue}}",
|
||||
"description": "{{{description}}}"
|
||||
}{{^-last}},{{/-last}}
|
||||
{{/pathParams}}
|
||||
],
|
||||
"query": [
|
||||
{{#queryParams}}
|
||||
{
|
||||
"key": "{{paramName}}",
|
||||
"value": "{{example}}",
|
||||
"description": "{{{description}}}",
|
||||
"disabled": {{#required}}false{{/required}}{{^required}}true{{/required}}
|
||||
}{{^-last}},{{/-last}}
|
||||
{{/queryParams}}
|
||||
]
|
||||
},
|
||||
"description": "{{{notes}}}"
|
||||
}
|
||||
"request": {{>request}}
|
||||
,"response": [
|
||||
{{#responses}}
|
||||
{"name": "{{name}}",
|
||||
"code": {{code}},
|
||||
"status": "{{status}}",
|
||||
"header": [{
|
||||
"key": "Content-Type",
|
||||
"value": "application/json"}
|
||||
],
|
||||
"_postman_previewlanguage": "json",
|
||||
"cookie": [],
|
||||
"body" : "{{{body}}}",
|
||||
"originalRequest": {{#originalRequest}}{{>request}}{{/originalRequest}}
|
||||
}{{^-last}},{{/-last}}
|
||||
{{/responses}}
|
||||
]
|
||||
}{{^-last}},{{/-last}}
|
||||
{{/vendorExtensions.postmanRequests}}
|
||||
]
|
||||
|
53
modules/openapi-generator/src/main/resources/postman-collection/request.mustache
vendored
Normal file
53
modules/openapi-generator/src/main/resources/postman-collection/request.mustache
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
{
|
||||
"method": "{{httpMethod}}",
|
||||
"header": [
|
||||
{{#headerParams}}
|
||||
{
|
||||
"key": "{{baseName}}",
|
||||
"value": "{{schema.defaultValue}}",
|
||||
"description": "{{{description}}}",
|
||||
"disabled": {{#schema.defaultValue}}false{{/schema.defaultValue}}{{^schema.defaultValue}}true{{/schema.defaultValue}}
|
||||
}{{^-last}},{{/-last}}
|
||||
{{/headerParams}}
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{{{body}}}",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{=<% %>=}}{{baseUrl}}<%={{ }}=%>{{path}}",
|
||||
"host": [
|
||||
"{{=<% %>=}}{{baseUrl}}<%={{ }}=%>"
|
||||
],
|
||||
"path": [
|
||||
{{#vendorExtensions.pathSegments}}
|
||||
"{{.}}"{{^-last}},{{/-last}}
|
||||
{{/vendorExtensions.pathSegments}}
|
||||
],
|
||||
"variable": [
|
||||
{{#pathParams}}
|
||||
{
|
||||
"key": "{{paramName}}",
|
||||
"value": "{{defaultValue}}",
|
||||
"description": "{{{description}}}"
|
||||
}{{^-last}},{{/-last}}
|
||||
{{/pathParams}}
|
||||
],
|
||||
"query": [
|
||||
{{#queryParams}}
|
||||
{
|
||||
"key": "{{paramName}}",
|
||||
"value": "{{example}}",
|
||||
"description": "{{{description}}}",
|
||||
"disabled": {{#required}}false{{/required}}{{^required}}true{{/required}}
|
||||
}{{^-last}},{{/-last}}
|
||||
{{/queryParams}}
|
||||
]
|
||||
},
|
||||
"description": "{{{notes}}}"
|
||||
}
|
@ -740,4 +740,50 @@ public class PostmanCollectionCodegenTest {
|
||||
assertEquals(true, postmanV2Generator.codegenOperationsByTag.containsKey("default"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResponses() throws IOException {
|
||||
|
||||
File output = Files.createTempDirectory("postmantest_").toFile();
|
||||
output.deleteOnExit();
|
||||
|
||||
final CodegenConfigurator configurator = new CodegenConfigurator()
|
||||
.setGeneratorName("postman-collection")
|
||||
.setInputSpec("src/test/resources/3_0/postman-collection/SampleProject.yaml")
|
||||
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));
|
||||
|
||||
DefaultGenerator generator = new DefaultGenerator();
|
||||
List<File> files = generator.opts(configurator.toClientOptInput()).generate();
|
||||
|
||||
System.out.println(files);
|
||||
//files.forEach(File::deleteOnExit);
|
||||
|
||||
Path path = Paths.get(output + "/postman.json");
|
||||
TestUtils.assertFileExists(path);
|
||||
|
||||
TestUtils.assertFileContains(path, "\"response\": [\n" +
|
||||
" {\"name\": \"User Updated\",\n" +
|
||||
" \"code\": 200,\n" +
|
||||
" \"status\": \"OK\",\n" +
|
||||
" \"header\": [{\n" +
|
||||
" \"key\": \"Content-Type\",\n" +
|
||||
" \"value\": \"application/json\"}\n" +
|
||||
" ],\n" +
|
||||
" \"_postman_previewlanguage\": \"json\",\n" +
|
||||
" \"cookie\": [],\n" +
|
||||
" \"body\" : \"{\\n \\\"id\\\" : 1,\\n");
|
||||
|
||||
TestUtils.assertFileContains(path, "\"response\": [\n" +
|
||||
" {\"name\": \"User Updated\",\n" +
|
||||
" \"code\": 200,\n" +
|
||||
" \"status\": \"OK\",\n" +
|
||||
" \"header\": [{\n" +
|
||||
" \"key\": \"Content-Type\",\n" +
|
||||
" \"value\": \"application/json\"}\n" +
|
||||
" ],\n" +
|
||||
" \"_postman_previewlanguage\": \"json\",\n" +
|
||||
" \"cookie\": [],\n" +
|
||||
" \"body\" : \"{\\n \\\"id\\\" : 2,\\n");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -156,15 +156,10 @@ paths:
|
||||
schema:
|
||||
$ref: '#/components/schemas/User'
|
||||
examples:
|
||||
Updated User Rebecca Baker:
|
||||
value:
|
||||
id: 13
|
||||
firstName: Rebecca
|
||||
lastName: Baker
|
||||
email: rebecca@gmail.com
|
||||
dateOfBirth: '1985-10-02'
|
||||
emailVerified: false
|
||||
createDate: '2019-08-24'
|
||||
success:
|
||||
$ref: '#/components/examples/response-success'
|
||||
anotherSuccess:
|
||||
$ref: '#/components/examples/another-response-success'
|
||||
'404':
|
||||
description: User Not Found
|
||||
'409':
|
||||
@ -188,17 +183,10 @@ paths:
|
||||
dateOfBirth:
|
||||
type: string
|
||||
examples:
|
||||
Update First Name:
|
||||
value:
|
||||
firstName: Rebecca
|
||||
Update Email:
|
||||
value:
|
||||
email: rebecca@gmail.com
|
||||
verified: true
|
||||
Update Last Name & Date of Birth:
|
||||
value:
|
||||
lastName: Baker
|
||||
dateOfBirth: '1985-10-02'
|
||||
success:
|
||||
$ref: '#/components/examples/patch-user'
|
||||
anotherSuccess:
|
||||
$ref: '#/components/examples/patch-user-2'
|
||||
description: Patch user properties to update.
|
||||
/user:
|
||||
post:
|
||||
@ -363,6 +351,40 @@ components:
|
||||
- user
|
||||
- admin
|
||||
- guest
|
||||
patch-user:
|
||||
summary: Example patch user
|
||||
value:
|
||||
firstName: John
|
||||
tags:
|
||||
- user
|
||||
patch-user-2:
|
||||
summary: Example patch another user
|
||||
value:
|
||||
firstName: Bill
|
||||
tags:
|
||||
- admin
|
||||
response-success:
|
||||
summary: Response 200
|
||||
value:
|
||||
id: 001
|
||||
firstName: Ron
|
||||
lastName: Edwardz
|
||||
email: ron.edwardz@example.com
|
||||
dateOfBirth: '1980-10-31'
|
||||
emailVerified: true
|
||||
tags:
|
||||
- admin
|
||||
another-response-success:
|
||||
summary: Another Response 200
|
||||
value:
|
||||
id: 002
|
||||
firstName: Rik
|
||||
lastName: Tom
|
||||
email: rik.tom@example.com
|
||||
dateOfBirth: '1981-10-11'
|
||||
emailVerified: true
|
||||
tags:
|
||||
- guest
|
||||
tags:
|
||||
- name: basic
|
||||
description: Basic tag
|
||||
|
@ -17,187 +17,268 @@
|
||||
"description": "Update the information of an existing user.",
|
||||
"item": [
|
||||
{
|
||||
"name": "Update First Name",
|
||||
"name": "Example patch user",
|
||||
"request": {
|
||||
"method": "PATCH",
|
||||
"header": [
|
||||
{
|
||||
"key": "Content-Type",
|
||||
"value": "application/json",
|
||||
"description": "",
|
||||
"disabled": false
|
||||
},
|
||||
{
|
||||
"key": "Accept",
|
||||
"value": "application/json",
|
||||
"description": "",
|
||||
"disabled": false
|
||||
},
|
||||
{
|
||||
"key": "strCode",
|
||||
"value": "code_one",
|
||||
"description": "Code as header",
|
||||
"disabled": false
|
||||
},
|
||||
{
|
||||
"key": "strCode2",
|
||||
"value": "",
|
||||
"description": "Code as header2",
|
||||
"disabled": true
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\n \"firstName\" : \"Rebecca\"\n}",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{baseUrl}}/users/:userId",
|
||||
"host": [
|
||||
"{{baseUrl}}"
|
||||
],
|
||||
"path": [
|
||||
"users",
|
||||
":userId"
|
||||
],
|
||||
"variable": [
|
||||
{
|
||||
"key": "userId",
|
||||
"value": "",
|
||||
"description": "Id of an existing user."
|
||||
}
|
||||
],
|
||||
"query": [
|
||||
]
|
||||
},
|
||||
"description": "Update the information of an existing user."
|
||||
"method": "PATCH",
|
||||
"header": [
|
||||
{
|
||||
"key": "Content-Type",
|
||||
"value": "application/json",
|
||||
"description": "",
|
||||
"disabled": false
|
||||
},
|
||||
{
|
||||
"key": "Accept",
|
||||
"value": "application/json",
|
||||
"description": "",
|
||||
"disabled": false
|
||||
},
|
||||
{
|
||||
"key": "strCode",
|
||||
"value": "code_one",
|
||||
"description": "Code as header",
|
||||
"disabled": false
|
||||
},
|
||||
{
|
||||
"key": "strCode2",
|
||||
"value": "",
|
||||
"description": "Code as header2",
|
||||
"disabled": true
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\n \"firstName\" : \"John\",\n \"tags\" : [ \"user\" ]\n}",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{baseUrl}}/users/:userId",
|
||||
"host": [
|
||||
"{{baseUrl}}"
|
||||
],
|
||||
"path": [
|
||||
"users",
|
||||
":userId"
|
||||
],
|
||||
"variable": [
|
||||
{
|
||||
"key": "userId",
|
||||
"value": "",
|
||||
"description": "Id of an existing user."
|
||||
}
|
||||
],
|
||||
"query": [
|
||||
]
|
||||
},
|
||||
"description": "Update the information of an existing user."
|
||||
}
|
||||
,"response": [
|
||||
{"name": "User Updated",
|
||||
"code": 200,
|
||||
"status": "OK",
|
||||
"header": [{
|
||||
"key": "Content-Type",
|
||||
"value": "application/json"}
|
||||
],
|
||||
"_postman_previewlanguage": "json",
|
||||
"cookie": [],
|
||||
"body" : "{\n \"id\" : 1,\n \"firstName\" : \"Ron\",\n \"lastName\" : \"Edwardz\",\n \"email\" : \"ron.edwardz@example.com\",\n \"dateOfBirth\" : \"1980-10-31\",\n \"emailVerified\" : true,\n \"tags\" : [ \"admin\" ]\n}",
|
||||
"originalRequest": {
|
||||
"method": "PATCH",
|
||||
"header": [
|
||||
{
|
||||
"key": "Content-Type",
|
||||
"value": "application/json",
|
||||
"description": "",
|
||||
"disabled": false
|
||||
},
|
||||
{
|
||||
"key": "Accept",
|
||||
"value": "application/json",
|
||||
"description": "",
|
||||
"disabled": false
|
||||
},
|
||||
{
|
||||
"key": "strCode",
|
||||
"value": "code_one",
|
||||
"description": "Code as header",
|
||||
"disabled": false
|
||||
},
|
||||
{
|
||||
"key": "strCode2",
|
||||
"value": "",
|
||||
"description": "Code as header2",
|
||||
"disabled": true
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\n \"firstName\" : \"John\",\n \"tags\" : [ \"user\" ]\n}",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{baseUrl}}/users/:userId",
|
||||
"host": [
|
||||
"{{baseUrl}}"
|
||||
],
|
||||
"path": [
|
||||
"users",
|
||||
":userId"
|
||||
],
|
||||
"variable": [
|
||||
{
|
||||
"key": "userId",
|
||||
"value": "",
|
||||
"description": "Id of an existing user."
|
||||
}
|
||||
],
|
||||
"query": [
|
||||
]
|
||||
},
|
||||
"description": "Update the information of an existing user."
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Update Email",
|
||||
"name": "Example patch another user",
|
||||
"request": {
|
||||
"method": "PATCH",
|
||||
"header": [
|
||||
{
|
||||
"key": "Content-Type",
|
||||
"value": "application/json",
|
||||
"description": "",
|
||||
"disabled": false
|
||||
},
|
||||
{
|
||||
"key": "Accept",
|
||||
"value": "application/json",
|
||||
"description": "",
|
||||
"disabled": false
|
||||
},
|
||||
{
|
||||
"key": "strCode",
|
||||
"value": "code_one",
|
||||
"description": "Code as header",
|
||||
"disabled": false
|
||||
},
|
||||
{
|
||||
"key": "strCode2",
|
||||
"value": "",
|
||||
"description": "Code as header2",
|
||||
"disabled": true
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\n \"email\" : \"rebecca@gmail.com\",\n \"verified\" : true\n}",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{baseUrl}}/users/:userId",
|
||||
"host": [
|
||||
"{{baseUrl}}"
|
||||
],
|
||||
"path": [
|
||||
"users",
|
||||
":userId"
|
||||
],
|
||||
"variable": [
|
||||
{
|
||||
"key": "userId",
|
||||
"value": "",
|
||||
"description": "Id of an existing user."
|
||||
}
|
||||
],
|
||||
"query": [
|
||||
]
|
||||
},
|
||||
"description": "Update the information of an existing user."
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Update Last Name & Date of Birth",
|
||||
"request": {
|
||||
"method": "PATCH",
|
||||
"header": [
|
||||
{
|
||||
"key": "Content-Type",
|
||||
"value": "application/json",
|
||||
"description": "",
|
||||
"disabled": false
|
||||
},
|
||||
{
|
||||
"key": "Accept",
|
||||
"value": "application/json",
|
||||
"description": "",
|
||||
"disabled": false
|
||||
},
|
||||
{
|
||||
"key": "strCode",
|
||||
"value": "code_one",
|
||||
"description": "Code as header",
|
||||
"disabled": false
|
||||
},
|
||||
{
|
||||
"key": "strCode2",
|
||||
"value": "",
|
||||
"description": "Code as header2",
|
||||
"disabled": true
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\n \"lastName\" : \"Baker\",\n \"dateOfBirth\" : \"1985-10-02\"\n}",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{baseUrl}}/users/:userId",
|
||||
"host": [
|
||||
"{{baseUrl}}"
|
||||
],
|
||||
"path": [
|
||||
"users",
|
||||
":userId"
|
||||
],
|
||||
"variable": [
|
||||
{
|
||||
"key": "userId",
|
||||
"value": "",
|
||||
"description": "Id of an existing user."
|
||||
}
|
||||
],
|
||||
"query": [
|
||||
]
|
||||
},
|
||||
"description": "Update the information of an existing user."
|
||||
"method": "PATCH",
|
||||
"header": [
|
||||
{
|
||||
"key": "Content-Type",
|
||||
"value": "application/json",
|
||||
"description": "",
|
||||
"disabled": false
|
||||
},
|
||||
{
|
||||
"key": "Accept",
|
||||
"value": "application/json",
|
||||
"description": "",
|
||||
"disabled": false
|
||||
},
|
||||
{
|
||||
"key": "strCode",
|
||||
"value": "code_one",
|
||||
"description": "Code as header",
|
||||
"disabled": false
|
||||
},
|
||||
{
|
||||
"key": "strCode2",
|
||||
"value": "",
|
||||
"description": "Code as header2",
|
||||
"disabled": true
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\n \"firstName\" : \"Bill\",\n \"tags\" : [ \"admin\" ]\n}",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{baseUrl}}/users/:userId",
|
||||
"host": [
|
||||
"{{baseUrl}}"
|
||||
],
|
||||
"path": [
|
||||
"users",
|
||||
":userId"
|
||||
],
|
||||
"variable": [
|
||||
{
|
||||
"key": "userId",
|
||||
"value": "",
|
||||
"description": "Id of an existing user."
|
||||
}
|
||||
],
|
||||
"query": [
|
||||
]
|
||||
},
|
||||
"description": "Update the information of an existing user."
|
||||
}
|
||||
,"response": [
|
||||
{"name": "User Updated",
|
||||
"code": 200,
|
||||
"status": "OK",
|
||||
"header": [{
|
||||
"key": "Content-Type",
|
||||
"value": "application/json"}
|
||||
],
|
||||
"_postman_previewlanguage": "json",
|
||||
"cookie": [],
|
||||
"body" : "{\n \"id\" : 2,\n \"firstName\" : \"Rik\",\n \"lastName\" : \"Tom\",\n \"email\" : \"rik.tom@example.com\",\n \"dateOfBirth\" : \"1981-10-11\",\n \"emailVerified\" : true,\n \"tags\" : [ \"guest\" ]\n}",
|
||||
"originalRequest": {
|
||||
"method": "PATCH",
|
||||
"header": [
|
||||
{
|
||||
"key": "Content-Type",
|
||||
"value": "application/json",
|
||||
"description": "",
|
||||
"disabled": false
|
||||
},
|
||||
{
|
||||
"key": "Accept",
|
||||
"value": "application/json",
|
||||
"description": "",
|
||||
"disabled": false
|
||||
},
|
||||
{
|
||||
"key": "strCode",
|
||||
"value": "code_one",
|
||||
"description": "Code as header",
|
||||
"disabled": false
|
||||
},
|
||||
{
|
||||
"key": "strCode2",
|
||||
"value": "",
|
||||
"description": "Code as header2",
|
||||
"disabled": true
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\n \"firstName\" : \"Bill\",\n \"tags\" : [ \"admin\" ]\n}",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{baseUrl}}/users/:userId",
|
||||
"host": [
|
||||
"{{baseUrl}}"
|
||||
],
|
||||
"path": [
|
||||
"users",
|
||||
":userId"
|
||||
],
|
||||
"variable": [
|
||||
{
|
||||
"key": "userId",
|
||||
"value": "",
|
||||
"description": "Id of an existing user."
|
||||
}
|
||||
],
|
||||
"query": [
|
||||
]
|
||||
},
|
||||
"description": "Update the information of an existing user."
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -213,45 +294,47 @@
|
||||
{
|
||||
"name": "Get group by ID",
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"header": [
|
||||
{
|
||||
"key": "Accept",
|
||||
"value": "application/json",
|
||||
"description": "",
|
||||
"disabled": false
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{baseUrl}}/groups/:groupId",
|
||||
"host": [
|
||||
"{{baseUrl}}"
|
||||
],
|
||||
"path": [
|
||||
"groups",
|
||||
":groupId"
|
||||
],
|
||||
"variable": [
|
||||
{
|
||||
"key": "groupId",
|
||||
"value": "1",
|
||||
"description": "group Id"
|
||||
}
|
||||
],
|
||||
"query": [
|
||||
]
|
||||
},
|
||||
"description": "Get group of users"
|
||||
}
|
||||
"method": "GET",
|
||||
"header": [
|
||||
{
|
||||
"key": "Accept",
|
||||
"value": "application/json",
|
||||
"description": "",
|
||||
"disabled": false
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{baseUrl}}/groups/:groupId",
|
||||
"host": [
|
||||
"{{baseUrl}}"
|
||||
],
|
||||
"path": [
|
||||
"groups",
|
||||
":groupId"
|
||||
],
|
||||
"variable": [
|
||||
{
|
||||
"key": "groupId",
|
||||
"value": "1",
|
||||
"description": "group Id"
|
||||
}
|
||||
],
|
||||
"query": [
|
||||
]
|
||||
},
|
||||
"description": "Get group of users"
|
||||
}
|
||||
,"response": [
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -262,57 +345,59 @@
|
||||
{
|
||||
"name": "Get User Info by User ID",
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"header": [
|
||||
{
|
||||
"key": "Accept",
|
||||
"value": "application/json",
|
||||
"description": "",
|
||||
"disabled": false
|
||||
},
|
||||
{
|
||||
"key": "strCode",
|
||||
"value": "code_one",
|
||||
"description": "Code as header",
|
||||
"disabled": false
|
||||
},
|
||||
{
|
||||
"key": "strCode2",
|
||||
"value": "",
|
||||
"description": "Code as header2",
|
||||
"disabled": true
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{baseUrl}}/users/:userId",
|
||||
"host": [
|
||||
"{{baseUrl}}"
|
||||
],
|
||||
"path": [
|
||||
"users",
|
||||
":userId"
|
||||
],
|
||||
"variable": [
|
||||
{
|
||||
"key": "userId",
|
||||
"value": "",
|
||||
"description": "Id of an existing user."
|
||||
}
|
||||
],
|
||||
"query": [
|
||||
]
|
||||
},
|
||||
"description": "Retrieve the information of the user with the matching user ID."
|
||||
}
|
||||
"method": "GET",
|
||||
"header": [
|
||||
{
|
||||
"key": "Accept",
|
||||
"value": "application/json",
|
||||
"description": "",
|
||||
"disabled": false
|
||||
},
|
||||
{
|
||||
"key": "strCode",
|
||||
"value": "code_one",
|
||||
"description": "Code as header",
|
||||
"disabled": false
|
||||
},
|
||||
{
|
||||
"key": "strCode2",
|
||||
"value": "",
|
||||
"description": "Code as header2",
|
||||
"disabled": true
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{baseUrl}}/users/:userId",
|
||||
"host": [
|
||||
"{{baseUrl}}"
|
||||
],
|
||||
"path": [
|
||||
"users",
|
||||
":userId"
|
||||
],
|
||||
"variable": [
|
||||
{
|
||||
"key": "userId",
|
||||
"value": "",
|
||||
"description": "Id of an existing user."
|
||||
}
|
||||
],
|
||||
"query": [
|
||||
]
|
||||
},
|
||||
"description": "Retrieve the information of the user with the matching user ID."
|
||||
}
|
||||
,"response": [
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -328,45 +413,98 @@
|
||||
{
|
||||
"name": "Example request for Get User",
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"header": [
|
||||
{
|
||||
"key": "Content-Type",
|
||||
"value": "application/json",
|
||||
"description": "",
|
||||
"disabled": false
|
||||
},
|
||||
{
|
||||
"key": "Accept",
|
||||
"value": "application/json",
|
||||
"description": "",
|
||||
"disabled": false
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\n \"id\" : 777,\n \"firstName\" : \"Alotta\",\n \"lastName\" : \"Rotta\",\n \"email\" : \"alotta.rotta@gmail.com\",\n \"dateOfBirth\" : \"1997-10-31\",\n \"emailVerified\" : true,\n \"createDate\" : \"2019-08-24\",\n \"tags\" : [ \"user\", \"admin\", \"guest\" ]\n}",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{baseUrl}}/user",
|
||||
"host": [
|
||||
"{{baseUrl}}"
|
||||
],
|
||||
"path": [
|
||||
"user"
|
||||
],
|
||||
"variable": [
|
||||
],
|
||||
"query": [
|
||||
]
|
||||
},
|
||||
"description": "Create a new user."
|
||||
"method": "POST",
|
||||
"header": [
|
||||
{
|
||||
"key": "Content-Type",
|
||||
"value": "application/json",
|
||||
"description": "",
|
||||
"disabled": false
|
||||
},
|
||||
{
|
||||
"key": "Accept",
|
||||
"value": "application/json",
|
||||
"description": "",
|
||||
"disabled": false
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\n \"id\" : 777,\n \"firstName\" : \"Alotta\",\n \"lastName\" : \"Rotta\",\n \"email\" : \"alotta.rotta@gmail.com\",\n \"dateOfBirth\" : \"1997-10-31\",\n \"emailVerified\" : true,\n \"createDate\" : \"2019-08-24\",\n \"tags\" : [ \"user\", \"admin\", \"guest\" ]\n}",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{baseUrl}}/user",
|
||||
"host": [
|
||||
"{{baseUrl}}"
|
||||
],
|
||||
"path": [
|
||||
"user"
|
||||
],
|
||||
"variable": [
|
||||
],
|
||||
"query": [
|
||||
]
|
||||
},
|
||||
"description": "Create a new user."
|
||||
}
|
||||
,"response": [
|
||||
{"name": "User Created",
|
||||
"code": 200,
|
||||
"status": "OK",
|
||||
"header": [{
|
||||
"key": "Content-Type",
|
||||
"value": "application/json"}
|
||||
],
|
||||
"_postman_previewlanguage": "json",
|
||||
"cookie": [],
|
||||
"body" : "{\n \"id\" : 777,\n \"firstName\" : \"Alotta\",\n \"lastName\" : \"Rotta\",\n \"email\" : \"alotta.rotta@gmail.com\",\n \"dateOfBirth\" : \"1997-10-31\",\n \"emailVerified\" : true,\n \"createDate\" : \"2019-08-24\",\n \"tags\" : [ \"user\", \"admin\", \"guest\" ]\n}",
|
||||
"originalRequest": {
|
||||
"method": "POST",
|
||||
"header": [
|
||||
{
|
||||
"key": "Content-Type",
|
||||
"value": "application/json",
|
||||
"description": "",
|
||||
"disabled": false
|
||||
},
|
||||
{
|
||||
"key": "Accept",
|
||||
"value": "application/json",
|
||||
"description": "",
|
||||
"disabled": false
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\n \"id\" : 777,\n \"firstName\" : \"Alotta\",\n \"lastName\" : \"Rotta\",\n \"email\" : \"alotta.rotta@gmail.com\",\n \"dateOfBirth\" : \"1997-10-31\",\n \"emailVerified\" : true,\n \"createDate\" : \"2019-08-24\",\n \"tags\" : [ \"user\", \"admin\", \"guest\" ]\n}",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{baseUrl}}/user",
|
||||
"host": [
|
||||
"{{baseUrl}}"
|
||||
],
|
||||
"path": [
|
||||
"user"
|
||||
],
|
||||
"variable": [
|
||||
],
|
||||
"query": [
|
||||
]
|
||||
},
|
||||
"description": "Create a new user."
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -377,57 +515,59 @@
|
||||
{
|
||||
"name": "Get User Info by Query Param",
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"header": [
|
||||
{
|
||||
"key": "Accept",
|
||||
"value": "application/json",
|
||||
"description": "",
|
||||
"disabled": false
|
||||
},
|
||||
{
|
||||
"key": "Custom-Header",
|
||||
"value": "",
|
||||
"description": "Custom HTTP header",
|
||||
"disabled": true
|
||||
},
|
||||
{
|
||||
"key": "Another-Custom-Header",
|
||||
"value": "abc",
|
||||
"description": "Custom HTTP header with default",
|
||||
"disabled": false
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{baseUrl}}/users/",
|
||||
"host": [
|
||||
"{{baseUrl}}"
|
||||
],
|
||||
"path": [
|
||||
"users"
|
||||
],
|
||||
"variable": [
|
||||
],
|
||||
"query": [
|
||||
{
|
||||
"key": "pUserId",
|
||||
"value": "888",
|
||||
"description": "Query Id.",
|
||||
"disabled": false
|
||||
}
|
||||
]
|
||||
},
|
||||
"description": "Retrieve the information of the user with the matching user ID."
|
||||
}
|
||||
"method": "GET",
|
||||
"header": [
|
||||
{
|
||||
"key": "Accept",
|
||||
"value": "application/json",
|
||||
"description": "",
|
||||
"disabled": false
|
||||
},
|
||||
{
|
||||
"key": "Custom-Header",
|
||||
"value": "",
|
||||
"description": "Custom HTTP header",
|
||||
"disabled": true
|
||||
},
|
||||
{
|
||||
"key": "Another-Custom-Header",
|
||||
"value": "abc",
|
||||
"description": "Custom HTTP header with default",
|
||||
"disabled": false
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{baseUrl}}/users/",
|
||||
"host": [
|
||||
"{{baseUrl}}"
|
||||
],
|
||||
"path": [
|
||||
"users"
|
||||
],
|
||||
"variable": [
|
||||
],
|
||||
"query": [
|
||||
{
|
||||
"key": "pUserId",
|
||||
"value": "888",
|
||||
"description": "Query Id.",
|
||||
"disabled": false
|
||||
}
|
||||
]
|
||||
},
|
||||
"description": "Retrieve the information of the user with the matching user ID."
|
||||
}
|
||||
,"response": [
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -25,9 +25,9 @@ class TestParameters(unittest.TestCase):
|
||||
def test_request_from_inline_examples(self):
|
||||
# item
|
||||
item = self.json_data['item'][0]['item'][0]['item'][0]
|
||||
self.assertEqual(item['name'], 'Update First Name')
|
||||
self.assertEqual(item['name'], 'Example patch user')
|
||||
self.assertEqual(item['request']["method"], 'PATCH')
|
||||
self.assertEqual(item['request']["body"]["raw"], '{\n "firstName" : "Rebecca"\n}')
|
||||
self.assertEqual(item['request']["body"]["raw"], '{\n "firstName" : "John",\n "tags" : [ "user" ]\n}')
|
||||
|
||||
def test_request_with_array_strings(self):
|
||||
# item
|
||||
@ -42,9 +42,9 @@ class TestParameters(unittest.TestCase):
|
||||
def test_request_boolean_field(self):
|
||||
# item
|
||||
item = self.json_data['item'][0]['item'][0]['item'][1]
|
||||
self.assertEqual(item['name'], 'Update Email')
|
||||
self.assertEqual(item['name'], 'Example patch another user')
|
||||
self.assertEqual(item['request']["method"], 'PATCH')
|
||||
self.assertEqual(item['request']["body"]["raw"], '{\n "email" : "rebecca@gmail.com",\n "verified" : true\n}')
|
||||
self.assertEqual(item['request']["body"]["raw"], '{\n "firstName" : "Bill",\n "tags" : [ "admin" ]\n}')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
x
Reference in New Issue
Block a user