-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Description / Steps to reproduce / Feature proposal
Unable to use local swagger-ui to upload files (Button missing).
Loopback requestBody does not accept "format: binary" used by openAPI to determine that the input field is for file upload.
Current Behavior
When using upload controller from example, the swagger-ui upload button does not appear and only shows a text box (no Upload button)
However if following openAPI spec, the button shows, but on submission of the file, errors occur unknown format "binary" is used in schema at path "#"
Expected Behavior
Either code should work or?
See Reporting Issues for more tips on writing good issues
From example - Button not showing
export class UploadController {
@post("/image", {
responses: {
200: {
content: {
"application/json": {
schema: {
type: "object"
},
},
},
description: "",
},
},
})
async image(
@requestBody({
description: 'multipart/form-data value.',
required: true,
content: {
"multipart/form-data": {
// Skip body parsing
"x-parser': 'stream",
schema: {
type: "object",
},
},
},
})
request: Request,
@inject(RestBindings.Http.RESPONSE) response: Response,
): Promise<object> {
//const storage = multer.memoryStorage();
const upload = multer({dest: "/"});
return new Promise<object>((resolve, reject) => {
upload.any()(request, response, (err: any) => {
if (err) {
reject(err);
} else {
resolve({
files: request.body.file,
fields: (request as any).fields,
});
}
});
});
}
}But change the request body to:
@requestBody({
description: 'multipart/form-data value.',
required: true,
content: {
'multipart/form-data': {
'x-parser': 'stream',
schema: {
type: 'object',
properties: {
file: {
type: 'string',
format: 'binary'
}
}
}
}
}
})the choose file button appears, but on submission I get the error...
Unhandled error in POST /image: 500 Error: unknown format "binary" is used in schema at path "#/properties/file"
A bit lost here... thanks!