kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
pull/715/head
rodzic
924330c759
commit
9c3b930f34
|
@ -180,25 +180,34 @@ export const fixtureSuites: E2ETestFixtureSuite[] = [
|
|||
response: {
|
||||
status: 400
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'dev/test-basic-openapi/getPost',
|
||||
request: {
|
||||
method: 'POST',
|
||||
json: {
|
||||
postId: 1,
|
||||
// additional json body params should throw an error
|
||||
foo: 'bar'
|
||||
}
|
||||
},
|
||||
response: {
|
||||
status: 400
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'dev/test-basic-openapi/getPost',
|
||||
request: {
|
||||
searchParams: {
|
||||
postId: 1,
|
||||
// additional search params should throw an error
|
||||
foo: 'bar'
|
||||
}
|
||||
},
|
||||
response: {
|
||||
status: 400
|
||||
}
|
||||
}
|
||||
// TODO: This should throw an error, but `cfValidateJsonSchemaObject`
|
||||
// currently does not validate additional properties.
|
||||
// TODO: also add a similar test for extra searchParams.
|
||||
// {
|
||||
// path: 'dev/test-basic-openapi/getPost',
|
||||
// only: true,
|
||||
// request: {
|
||||
// method: 'POST',
|
||||
// json: {
|
||||
// postId: 1,
|
||||
// // additional properties should throw an error
|
||||
// foo: 'bar'
|
||||
// }
|
||||
// },
|
||||
// response: {
|
||||
// status: 400
|
||||
// }
|
||||
// }
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
@ -35,7 +35,20 @@ export function cfValidateJsonSchemaObject<
|
|||
if (missingRequiredFields.length > 0) {
|
||||
throw new HttpError({
|
||||
statusCode: 400,
|
||||
message: `${errorMessage ? errorMessage + ': ' : ''}Missing required ${plur('field', missingRequiredFields.length)}: ${missingRequiredFields.map((field) => `"${field}"`).join(', ')}`
|
||||
message: `${errorMessage ? errorMessage + ': ' : ''}Missing required ${plur('parameter', missingRequiredFields.length)}: ${missingRequiredFields.map((field) => `"${field}"`).join(', ')}`
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (schema.properties && !schema.additionalProperties) {
|
||||
const extraProperties = Object.keys(data).filter(
|
||||
(key) => !schema.properties[key]
|
||||
)
|
||||
|
||||
if (extraProperties.length > 0) {
|
||||
throw new HttpError({
|
||||
statusCode: 400,
|
||||
message: `${errorMessage ? errorMessage + ': ' : ''}Unexpected additional ${plur('parameter', extraProperties.length)}: ${extraProperties.map((property) => `"${property}"`).join(', ')}`
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue