Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [2.4.1-beta-1] - 2026-06-26

### Fixed
- Fix schema validation crash on 204 No Content endpoints when `validate_schema: true`.


## [2.4.0] - 2026-05-07

### Added
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "openapi2postman",
"version": "2.4.0",
"version": "2.4.1-beta-1",
"description": "openapi2postman",
"bin": {
"o2p": "index.js"
Expand Down
43 changes: 43 additions & 0 deletions seeds/generatorTestBody204Initial.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "/pets/{id}-204",
"aux": {
"status": "204",
"body": false,
"consumes": false,
"bodyResponse": {
"500": {
"type": "object",
"required": ["code", "message"],
"properties": {
"code": { "type": "integer", "format": "int32" },
"message": { "type": "string" }
}
}
}
},
"response": [],
"request": {
"method": "DELETE",
"header": [],
"body": { "mode": "raw", "raw": "" },
"url": {
"raw": "{{host}}{{port}}{{basePath}}/pets/{{id}}",
"host": ["{{host}}{{port}}{{basePath}}"],
"path": ["/pets/{{id}}"]
}
},
"event": [
{
"listen": "test",
"script": {
"id": "test-204-uuid",
"type": "text/javascript",
"exec": [
"pm.test(\"Status code is 204\", function () {",
" pm.response.to.have.status(204);",
"});"
]
}
}
]
}
43 changes: 43 additions & 0 deletions seeds/generatorTestBody204Result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "/pets/{id}-204",
"aux": {
"status": "204",
"body": false,
"consumes": false,
"bodyResponse": {
"500": {
"type": "object",
"required": ["code", "message"],
"properties": {
"code": { "type": "integer", "format": "int32" },
"message": { "type": "string" }
}
}
}
},
"response": [],
"request": {
"method": "DELETE",
"header": [],
"body": { "mode": "raw", "raw": "" },
"url": {
"raw": "{{host}}{{port}}{{basePath}}/pets/{{id}}",
"host": ["{{host}}{{port}}{{basePath}}"],
"path": ["/pets/{{id}}"]
}
},
"event": [
{
"listen": "test",
"script": {
"id": "test-204-uuid",
"type": "text/javascript",
"exec": [
"pm.test(\"Status code is 204\", function () {",
" pm.response.to.have.status(204);",
"});"
]
}
}
]
}
1 change: 1 addition & 0 deletions src/generator/environmentVariablesNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ module.exports = function() {
}
function extractVariablesFromTest(aux, execCode, numerateItem, items){
if (global.configurationFile.schema_is_inline === false) {
if (!aux.bodyResponse?.[aux.status]) return;
const key = numerateItem + 'schemaTest';
for (let i in execCode){
if (execCode[i] === 'var schema = pm.environment.get("schemaTest");'){
Expand Down
13 changes: 8 additions & 5 deletions src/generator/testBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ module.exports = function() {

return function get(postmanRequest, configurationFile) {

if ((!postmanRequest.aux.bodyResponse || !postmanRequest.aux.bodyResponse[postmanRequest.aux.status]) && postmanRequest.aux.status === 200) {
console.warn(
'\x1b[33m%s\x1b[0m',
`Test: ${postmanRequest.request.method} ${postmanRequest.name} (${postmanRequest.aux.suffix === undefined ? 'main test' : postmanRequest.aux.suffix.trim()}) without schema validation test because it has a different response than 'application/json'`
if (!postmanRequest.aux.bodyResponse || !postmanRequest.aux.bodyResponse[postmanRequest.aux.status]) {
const noBodyStatuses = ['204', '205', '304'];
if (!noBodyStatuses.includes(String(postmanRequest.aux.status))) {
console.warn(
'\x1b[33m%s\x1b[0m',
`Test: ${postmanRequest.request.method} ${postmanRequest.name} (${postmanRequest.aux.suffix === undefined ? 'main test' : postmanRequest.aux.suffix.trim()}) without schema validation test because it has a different response than 'application/json'`
);
}
return postmanRequest;
}
}
let schemaJSON;

if (configurationFile.schema_is_inline === false) {
Expand Down
84 changes: 84 additions & 0 deletions test/generator-envVariables.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/** Part of APIAddicts. See LICENSE fileor full copyright and licensing details. Supported by Madrid Digital and CloudAPPi **/

const assert = require('node:assert');

describe('generator-envVariables', () => {

let savedConfig;
let savedEnvVars;

beforeEach(() => {
savedConfig = globalThis.configurationFile;
savedEnvVars = globalThis.environmentVariables;
globalThis.environmentVariables = {};
});

afterEach(() => {
globalThis.configurationFile = savedConfig;
globalThis.environmentVariables = savedEnvVars;
});

it('204 no body schema is inline false', () => {
globalThis.configurationFile = { schema_is_inline: false, schema_pretty_print: false, is_inline: false };

const collection = [
{
name: 'pets',
item: [
{
name: 'pets',
item: [
{
name: '/pets/{id}-204',
aux: {
numerateItem: '1',
status: '204',
bodyResponse: {
'500': {
type: 'object',
required: ['code', 'message'],
properties: {
code: { type: 'integer', format: 'int32' },
message: { type: 'string' }
}
}
},
queryParams: []
},
request: {
method: 'DELETE',
header: [],
body: { mode: 'raw', raw: '' },
url: {
raw: '{{host}}{{port}}{{basePath}}/pets/1',
host: ['{{host}}{{port}}{{basePath}}'],
path: ['/pets/1']
}
},
event: [
{
listen: 'test',
script: {
id: 'test-204-uuid',
type: 'text/javascript',
exec: [
'pm.test("Status code is 204", function () {',
' pm.response.to.have.status(204);',
'});'
]
}
}
]
}
]
}
]
}
];

const items = require('../src/generator/environmentVariablesNames.js')(collection);
const schemaTestItem = items.find(item => item.key?.includes('schemaTest'));
assert.strictEqual(schemaTestItem, undefined, 'No schemaTest env variable should be created for 204 No Content');
});

});
9 changes: 9 additions & 0 deletions test/generator-testBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,13 @@ describe('generator-testBody', () => {
assert.deepStrictEqual(definition, definitionResult);
});

it('204 no body', () => {

const definitionInitial = require('../seeds/generatorTestBody204Initial.json');
const definitionResult = require('../seeds/generatorTestBody204Result.json');

const definition = require('../src/generator/testBody.js')(definitionInitial, {schema_pretty_print: false});
assert.deepStrictEqual(definition, definitionResult);
});

});