Get working when AdditionalProperties is empty object
SzHeJason opened this issue · 1 comments
SzHeJason commented
Bug Report
To Reproduce
const Controller: FastifyPluginCallback = (server, options, next) => {
server.post(
'/:moduleName/:action',
{
schema: {
response: {
'2xx': {
type: 'object',
properties: {
code: { type: 'number' },
subcode: { type: 'number' },
message: { type: 'string' },
data: { type: 'object', additionalProperties: {} },
},
required: ['code', 'subcode', 'message', 'data'],
},
},
},
},
async (request, reply) => {
reply.send({
code: 0,
subcode: 0,
message: 'ok',
data: {
a: '123',
},
})
}
)
next()
}
Expected behavior
response data should can compile safely by docs
If additionalProperties is an object, that object is a schema that will be used to validate
any additional properties not listed in properties.
For example, one can allow additional properties, but only if they are each a string:
{
"type": "object",
"properties": {
"number": { "type": "number" },
"street_name": { "type": "string" },
"street_type": { "type": "string",
"enum": ["Street", "Avenue", "Boulevard"]
}
},
"additionalProperties": { "type": "string" }
}
Your Environment
- node version: 12
- fastify version:3.13.0
- os: Mac