Skip to content

Commit

Permalink
introduced additionalQueryParamSchema
Browse files Browse the repository at this point in the history
this is to add other query params schema, other than the one present in NpmBase.
  • Loading branch information
MohanKumarAmbati committed Oct 28, 2024
1 parent 4842112 commit 96ced45
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
10 changes: 7 additions & 3 deletions services/npm/npm-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,22 @@ export default class NpmBase extends BaseJsonService {
serviceKey: 'npm',
}

static buildRoute(base, { withTag, queryParams } = {}) {
static buildRoute(base, { withTag, additionalQueryParamSchema } = {}) {
if (withTag) {
return {
base,
pattern: ':scope(@[^/]+)?/:packageName/:tag*',
queryParamSchema: queryParams || queryParamSchema,
queryParamSchema: additionalQueryParamSchema
? queryParamSchema.append(additionalQueryParamSchema)
: queryParamSchema,
}
} else {
return {
base,
pattern: ':scope(@[^/]+)?/:packageName',
queryParamSchema: queryParams || queryParamSchema,
queryParamSchema: additionalQueryParamSchema
? queryParamSchema.append(additionalQueryParamSchema)
: queryParamSchema,
}
}
}
Expand Down
12 changes: 5 additions & 7 deletions services/npm/npm-last-update.service.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import Joi from 'joi'
import dayjs from 'dayjs'
import { optionalUrl } from '../validators.js'
import { InvalidParameter, pathParam, queryParam } from '../index.js'
import { formatDate } from '../text-formatters.js'
import { age as ageColor } from '../color-formatters.js'
import NpmBase, { packageNameDescription } from './npm-base.js'

const queryParamSchema = Joi.object({
registry_uri: optionalUrl,
version: Joi.string(),
}).required()

const updateResponseSchema = Joi.object({
time: Joi.object({
modified: Joi.string().required(),
Expand All @@ -19,12 +13,16 @@ const updateResponseSchema = Joi.object({
.required(),
}).required()

const additionalQueryParamSchema = {
version: Joi.string(),
}

export class NpmLastUpdate extends NpmBase {
static category = 'activity'

static route = this.buildRoute('npm/last-update', {
withTag: false,
queryParams: queryParamSchema,
additionalQueryParamSchema,
})

static openApi = {
Expand Down

0 comments on commit 96ced45

Please sign in to comment.