Skip to content
This repository has been archived by the owner on Jun 6, 2023. It is now read-only.

Commit

Permalink
comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Arinono committed Mar 20, 2023
1 parent 2f3c614 commit d41c394
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/routes/chart/get-panels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ type KindsHashIds = typeof kindsHashIds[number];
const kindsResources = ['pinGroups', 'pins'] as const;
type KindsResources = typeof kindsResources[number];

// We make eveything Partial because having everything required but allowing an empty array does not
// work. The reason is that coming from the consummer, having empty array(s) is valid, then the
// query goes through axios, which strips the empty query arrays. Later, when the platform receives
// the query and validated the requests, the requests does not validates against the schema anymore.
// One alternative would be to add a paramSerializer to axios to force to produce a query param for
// empty arrays. But doing so would annoys Joi because `array[0]` cannot be an empty string.
// So the next best thing we can do is this, allowing empty queries, and anserwing with empty
// responses
type Request = {
query: Partial<Record<KindsHashIds, Array<HashId>>>;
}
Expand Down Expand Up @@ -41,8 +49,8 @@ const controllerGeneratorOptions: ControllerGeneratorOptionsWithClient = {
method: 'get',
path: '/panels',
query: Joi.object().keys({
pinGroupHashIds: Joi.array().items(Joi.string()).max(30),
pinHashIds: Joi.array().items(Joi.string()).max(30),
pinGroupHashIds: Joi.array().items(Joi.string().example('dao97')).max(30),
pinHashIds: Joi.array().items(Joi.string().example('e13d57')).max(30),
}).required(),
right: { environment: 'READ' },
response: (apiVersion: number): Joi.ObjectSchema => Joi.object().keys({
Expand Down

0 comments on commit d41c394

Please sign in to comment.