Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 12 additions & 5 deletions libV2/schemaUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2147,10 +2147,12 @@ let QUERYPARAM = 'query',
const { schema } = param;

// Handle union types (OpenAPI 3.1.x supports arrays of types like ["string", "integer"])
// Pick the first type if it's a union of types
const resolvedType = Array.isArray(schema.type) ? schema.type[0] : schema.type;
// Pick the first type if it's a union of types, but only if array is not empty
const resolvedType = Array.isArray(schema.type) ?
(schema.type.length > 0 ? schema.type[0] : undefined) :
schema.type;

return {
const properties = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason to change this ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, had changed it when trying something out. Let me revert

description: schema.description,
title: schema.title,
type: resolvedType,
Expand All @@ -2166,6 +2168,8 @@ let QUERYPARAM = 'query',
pattern: schema.pattern,
example: schema.example
};

return properties;
},

resolveQueryParamsForPostmanRequest = (context, operationItem, method) => {
Expand Down Expand Up @@ -2496,8 +2500,10 @@ let QUERYPARAM = 'query',
}

// Handle union types (OpenAPI 3.1.x supports arrays of types like ["string", "integer"])
// Pick the first type if it's a union of types
const resolvedType = Array.isArray(schema.type) ? schema.type[0] : schema.type;
// Pick the first type if it's a union of types, but only if array is not empty
const resolvedType = Array.isArray(schema.type) ?
(schema.type.length > 0 ? schema.type[0] : undefined) :
schema.type;

properties = {
type: resolvedType,
Expand All @@ -2515,6 +2521,7 @@ let QUERYPARAM = 'query',
pattern: schema.pattern,
example: schema.example
};

headerTypeInfo = { keyName: headerData.name, properties };
headerTypes.push(headerTypeInfo);
}
Expand Down
14 changes: 13 additions & 1 deletion test/unit/convertV2WithTypes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,14 @@ describe('convertV2WithTypes', function() {
type: 'string', // Single type - should remain 'string'
description: 'Simple string parameter'
}
},
{
name: 'emptyUnionParam',
in: 'query',
schema: {
type: [], // Empty union type - should not have type property
description: 'Empty union type parameter'
}
}
],
responses: {
Expand Down Expand Up @@ -1267,7 +1275,7 @@ describe('convertV2WithTypes', function() {

// Check query parameters
const queryParams = JSON.parse(requestTypes.request.queryParam);
expect(queryParams).to.be.an('array').with.length(2);
expect(queryParams).to.be.an('array').with.length(3);

const formatParam = queryParams.find((p) => { return p.keyName === 'format'; });
expect(formatParam).to.be.an('object');
Expand All @@ -1277,6 +1285,10 @@ describe('convertV2WithTypes', function() {
expect(singleTypeParam).to.be.an('object');
expect(singleTypeParam.properties.type).to.equal('string'); // Single type should remain unchanged

const emptyUnionParam = queryParams.find((p) => { return p.keyName === 'emptyUnionParam'; });
expect(emptyUnionParam).to.be.an('object');
expect(emptyUnionParam.properties).to.not.have.property('type'); // Empty union should not have type property

// Check request header parameters
const headerParams = JSON.parse(requestTypes.request.headers);
expect(headerParams).to.be.an('array').with.length(1);
Expand Down
Loading