request.query.settings should be object
See original GitHub issueHello,
Is serialized objects not supported or am I doing something wrong? I have an endpoint defined like that ( I deliberately simplified this ) :
/api/someGet:
get:
summary: "Retrieve something"
parameters:
- in: query
style: form
name: settings
explode: true
schema:
allOf:
- type: object
properties:
onlyValidated:
type: boolean
default: true
onlySelected:
type: array
default: []
uniqueItems: true
items:
type: integer
minimum: 0
example: 42
responses:
'200':
description: "An array of items"
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/someItem"
uniqueItems: true
I tested two approaches that have failed with Postman ( that imported the api definition ) :
{{baseUrl}}/api/someGet?settings={“onlyValidated”:true}
{
"message": "request.query.settings should be object",
"errors": [
{
"path": ".query.settings",
"message": "should be object",
"errorCode": "type.openapi.validation"
}
]
}
{{baseUrl}}/api/someGet?onlyValidated=true
{
"message": "Unknown query parameter onlyValidated",
"errors": [
{
"path": ".query.onlyValidated",
"message": "Unknown query parameter onlyValidated"
}
]
}
FYI, here is my express server implementation :
const express = require('express');
const path = require('path');
const logger = require('morgan');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const routes = require('./routes/index');
// miscellaneous passport things
const passport = require('passport');
// OpenAPI V3 validation middleware
const OpenApiValidator = require('express-openapi-validator').OpenApiValidator;
const spec = path.join(__dirname, 'api.yml');
// Initialize passport ( Passport is a singleton )
require('./config/passport');
const app = express();
// middleware
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
// API validation before routes and password.js
// Install the OpenApiValidator on your express app
new OpenApiValidator({
apiSpec: spec,
validateRequests: true,
validateResponses: false,
// securityHandlers: {
// ApiKeyAuth: (req, scopes, schema) => true,
// },
}).install(app);
// Passport Js must have that
app.use(passport.initialize());
// routes
app.use('/', routes);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
let err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handler
// no stacktraces leaked to user unless in development environment
app.use(function(err, req, res, next) {
// if error thrown by validation, give everything else depending of the environment
res.status(err.status || 500).json({
message: err.message,
errors: err.hasOwnProperty("errors")
? err.errors
: (app.get('env') === 'development') ? [err] : []
});
});
module.exports = app;
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Describing Parameters - Swagger
Query parameters can be primitive values, arrays and objects. ... OpenAPI lets you define custom request headers as in: header parameters.
Read more >Query parameters versus request object
By default, PingFederate sends all request parameters through multiple query parameters, unsigned.
Read more >OpenAPI JSON Objects as Query Parameters - Baeldung
Learn how to specify JSON objects as query parameters using the OpenAPI specification.
Read more >REST API Design Best Practices for Parameter and Query ...
Where to put the parameters for APIs? Best practices for parameter and query string usage in REST APIs.
Read more >Query options overview - OData | Microsoft Learn
A query option is basically requesting that a service perform a set of transformations such as filtering, sorting, etc. to its data before ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It works like a charm : I can access object properties as expected (
req.query.settings
)@jy95 please give
v3.0.2
a try. it should improve the query param serialization handling. please let me know how it goes