Skip to content

fix: allow undefined runtime values#68

Open
kerwanp wants to merge 1 commit intoadonisjs:11.xfrom
kerwanp:11.x
Open

fix: allow undefined runtime values#68
kerwanp wants to merge 1 commit intoadonisjs:11.xfrom
kerwanp:11.x

Conversation

@kerwanp
Copy link

@kerwanp kerwanp commented Feb 8, 2026

❓ Type of change

  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

This pull-request allows providingundefined runtime values.

I am prototyping a "decorators" package for providing runtime values using decorators, for example by using @QueryParam you can inject and validate query parameter. Currently when a runtime value is undefined it tries to lookup for an injection and fails.

/**
 * Injects query parameter as a method parameter.
 * When a schema is provided the value is validated.
 *
 * @param name - parameter name defined in route pattern
 * @param schema - optional compatible StandardSchema or VineType
 *
 * @example
 * async handle(
 *   context: HttpContext,
 *   @QueryParam('version', vine.string().optional()) postId: string | undefined
 * ) {}
 */
export function QueryParam(name: string, schema?: StandardSchemaV1 | SchemaTypes) {
  return createParameterDecorator(async (ctx) => {
    if (schema) {
      const requestValidator = new RequestValidator(ctx)
      const validator = await normalizeSchema(schema)
      const result = await requestValidator.validateQueryParam(validator, name)
      return result
    }

    return ctx.request.qs()[name]
  })
}

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@thetutlage
Copy link
Member

This will alter the behavior of the container, which will result in a foundational breaking change.

Maybe, we should come up with an alternative way to provide runtime values in a way that skips container resolution. Maybe a branded value?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments