-
-
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.
chore: improve OAS functions (#1362)
* chore: improve OAS functions * fix: check for presence of operationId
- Loading branch information
Showing
12 changed files
with
166 additions
and
144 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
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 oasOp2xxResponse: 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) < 300).length === 0) { | ||
results.push({ | ||
message: 'operations must define at least one 2xx response', | ||
}); | ||
for (const response of Object.keys(targetVal)) { | ||
if (Number(response) >= 200 && Number(response) < 300) { | ||
return; | ||
} | ||
} | ||
return results; | ||
|
||
return [ | ||
{ | ||
message: 'operations must define at least one 2xx or 3xx response', | ||
}, | ||
]; | ||
}; | ||
|
||
export default oasOp2xxResponse; |
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
Oops, something went wrong.