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
16 changes: 15 additions & 1 deletion packages/ruleset/src/functions/collection-array-property.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ function collectionArrayProperty(schema, path, apidef) {

// If this is a collection "list"-type operation, then check to make sure
// that "schema" defines an array property named after the last path segment.
if (isListOperation(operation, pathString, apidef)) {
if (
isListOperation(operation, pathString, apidef) &&
!isBinarySchema(schema)
) {
logger.debug('Detected list-type operation');
const pathSegments = pathString.split('/');
const propertyName = pathSegments[pathSegments.length - 1];
Expand Down Expand Up @@ -112,6 +115,17 @@ function isListOperation(operation, path, apidef) {
return !!siblingPath;
}

/**
* Returns true iff "schema" represents binary file content.
* @param {*} schema the schema to check
* @returns boolean true if the schema is a binary string schema
*/
function isBinarySchema(schema) {
return (
isObject(schema) && schema.type === 'string' && schema.format === 'binary'
);
}

/**
* Returns true iff "schema" defines an array property named "name".
* The property could be defined directly in "schema" or as part of
Expand Down
28 changes: 28 additions & 0 deletions packages/ruleset/test/rules/collection-array-property.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,34 @@ describe(`Spectral rule: ${ruleId}`, () => {
expect(results).toHaveLength(0);
});

it('does not require an array property for binary file responses', async () => {
const testDocument = makeCopy(rootDocument);

testDocument.paths['/v1/gateway_letters'] = {
get: {
operationId: 'list_gateway_letter_of_authorization',
responses: {
200: {
description: 'Letter of Authorization retrieved successfully.',
content: {
'application/pdf': {
schema: {
description: 'Letter of Authorization',
type: 'string',
format: 'binary',
},
},
},
},
},
},
};

const results = await testRule(ruleId, rule, testDocument);

expect(results).toHaveLength(0);
});

it('would normally warn but path contains quote character, which throws off spectral', async () => {
const testDocument = makeCopy(rootDocument);

Expand Down