-
-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
148 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,24 @@ | ||
import type { IFunction, IFunctionResult } from '../../../types'; | ||
import type { IFunction } from '../../../types'; | ||
|
||
const validConsumeValue = /(application\/x-www-form-urlencoded|multipart\/form-data)/; | ||
|
||
export const oasOpFormDataConsumeCheck: IFunction = targetVal => { | ||
const results: IFunctionResult[] = []; | ||
const parameters: unknown = targetVal.parameters; | ||
const consumes: unknown = targetVal.consumes; | ||
|
||
const parameters = targetVal.parameters; | ||
const consumes = targetVal.consumes || []; | ||
if (!Array.isArray(parameters) || !Array.isArray(consumes)) { | ||
return; | ||
} | ||
|
||
if (parameters?.find((p: any) => p.in === 'formData')) { | ||
if (!consumes.join(',').match(/(application\/x-www-form-urlencoded|multipart\/form-data)/)) { | ||
results.push({ | ||
message: 'consumes must include urlencoded, multipart, or formdata media type when using formData parameter', | ||
}); | ||
} | ||
if (parameters.some(p => p?.in === 'formData') && !validConsumeValue.test(consumes?.join(','))) { | ||
return [ | ||
{ | ||
message: 'Consumes must include urlencoded, multipart, or form-data media type when using formData parameter.', | ||
}, | ||
]; | ||
} | ||
|
||
return results; | ||
return; | ||
}; | ||
|
||
export default oasOpFormDataConsumeCheck; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,22 @@ | ||
import type { IFunction, IFunctionResult } from '../../../types'; | ||
import type { IFunction } from '../../../types'; | ||
import { isObject } from './utils/isObject'; | ||
|
||
export const oasOpSuccessResponse: IFunction = targetVal => { | ||
if (!targetVal) { | ||
if (!isObject(targetVal)) { | ||
return; | ||
} | ||
|
||
const results: IFunctionResult[] = []; | ||
const responses = Object.keys(targetVal); | ||
if (responses.filter(response => Number(response) >= 200 && Number(response) < 400).length === 0) { | ||
results.push({ | ||
message: 'operations must define at least one 2xx or 3xx response', | ||
}); | ||
for (const response of Object.keys(targetVal)) { | ||
if (Number(response) >= 200 && Number(response) < 400) { | ||
return; | ||
} | ||
} | ||
return results; | ||
|
||
return [ | ||
{ | ||
message: 'operations must define at least one 2xx or 3xx response', | ||
}, | ||
]; | ||
}; | ||
|
||
export default oasOpSuccessResponse; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { isObject } from './isObject'; | ||
|
||
const validOperationKeys = ['get', 'head', 'post', 'put', 'patch', 'delete', 'options', 'trace']; | ||
|
||
export function* getAllOperations(paths: unknown): IterableIterator<{ path: string; operation: string }> { | ||
if (!isObject(paths)) { | ||
return; | ||
} | ||
|
||
const item = { | ||
path: '', | ||
operation: '', | ||
}; | ||
|
||
for (const path of Object.keys(paths)) { | ||
const operations = paths[path]; | ||
if (!isObject(operations)) { | ||
continue; | ||
} | ||
|
||
item.path = path; | ||
|
||
for (const operation of Object.keys(operations)) { | ||
if (!isObject(operations[operation]) || !validOperationKeys.includes(operation)) { | ||
continue; | ||
} | ||
|
||
item.operation = operation; | ||
|
||
yield item; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type { Dictionary } from '@stoplight/types'; | ||
|
||
export function isObject(value: unknown): value is Dictionary<unknown> { | ||
return value !== null && typeof value === 'object'; | ||
} |