How can i convert OpenAPI examples to Postman Collection examples?
In OpenAPI 3, we can define different named examples for parameters, request bodies and responses, for instance
"/test-resources/{TYPE}": {
"post": {
"tags": [
"TestResource"
],
"operationId": "create_test_resource",
"summary": "Creates a test resource of type",
"parameters": [
{
"name": "TYPE",
"in": "path",
"description": "Resource type",
"required": true,
"schema": {
"type": "string"
},
"examples": {
"Success": {
"value": "CorrectType"
},
"Incorrect": {
"value": "InvalidType"
}
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"element_one": {
"type": "string",
"nullable": false
},
"element_two": {
"type": "number",
"nullable": false
}
}
},
"examples": {
"Success": {
"value": {
"element_one": "yes",
"element_two": 20
}
},
"Incorrect": {
"value": {
"element_one": "yes"
}
}
}
}
}
},
"responses": {
"200": {
"description": "Successful",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"element_one": {
"type": "string",
"nullable": false
},
"element_two": {
"type": "number",
"nullable": false
},
"type": {
"type": "string",
"nullable": false
}
}
},
"examples": {
"Success": {
"value": {
"element_one": "yes",
"element_two": 20,
"type": "CorrectType"
}
}
}
}
}
},
"400": {
"description": "Input error",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"error_code": {
"type": "string",
"nullable": false
},
"error_message": {
"type": "string",
"nullable": false
}
}
},
"examples": {
"Incorrect": {
"value": {
"error_code": "400",
"error_message": "Invalid Request"
}
}
}
}
}
}
}
In this case, it looks like when I generate a definition, I will get two examples (“Success” and “Incorrect”), with the request and the response defined with that name, but no, I’m only getting the examples based on the response codes (named with the description of each response) and the values are the first example defined.
I want to know if it’s possible to define the postman examples from the openapi definition, it’ll be nice because the mock generation would be a lot faster working only on the oas definition.