Fix options being dropped when a parameter description is multi-line#9
Open
enricodelazzari wants to merge 1 commit into
Open
Conversation
Command signatures are a single-line mini-language in which `{`, `}` and
newlines are significant. OpenAPI parameter descriptions are free-form
Markdown and may legitimately span multiple lines, so embedding them raw
into the signature caused Laravel's signature parser (whose token regex
has no `s` modifier) to silently skip the whole `{--option= : ...}` block.
The option was therefore never registered, yet it remained in the
path/query option map, so building the request URL called
`$this->option($name)` on an undefined option and threw
`The "<name>" option does not exist.` at runtime.
Sanitize descriptions (collapse whitespace, strip braces) before placing
them in the signature.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When an OpenAPI parameter has a multi-line
description(free-form Markdown, which is perfectly valid per the spec), the generated command throws at runtime as soon as it's executed:Root cause
EndpointCommand::buildSignature()interpolates the raw description into Laravel's signature DSL:Laravel's signature parser extracts tokens with
preg_match_all('/\{\s*(.*?)\s*\}/', ...)— nosmodifier, so.doesn't match newlines. A{--order= : line1\n\nline2}block is therefore never matched, and the option is silently dropped (it doesn't even show up in--help).But
buildSignature()still records the parameter in$queryParamOptionMap/$pathParamOptionMap. At runtimebuildRequestUrl()iterates that map and calls$this->option($name)on the option that was never registered →InvalidOptionException.This breaks every endpoint whose parameters have multi-line descriptions (
{/}in a description hit the same problem).Minimal reproduction
Fix
Sanitize the description before embedding it in the signature: collapse whitespace runs (including newlines) into single spaces and strip
{/}.Tests
Added a regression test in
QueryParametersTestthat registers a query parameter with a multi-line description and asserts the command runs and sends the parameter. It fails onmainwith the exactThe "--order" option does not exist.error and passes with the fix.Full suite (348 tests) green; Pint passes. (The 2 pre-existing PHPStan errors at
EndpointCommand.php:49are unrelated to this change.)🤖 Generated with Claude Code