Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support limitng parameter values (enums) #713

Merged
merged 4 commits into from
Aug 24, 2023
Merged

Support limitng parameter values (enums) #713

merged 4 commits into from
Aug 24, 2023

Conversation

shalvah
Copy link
Contributor

@shalvah shalvah commented Aug 20, 2023

Adds support for limiting parameter values. Works with either a PHP 8.1 enum or an array of values.

#[BodyParam("status", enum: ['approved', 'pending', 'closed', 'new'])]
#[BodyParam("status", enum: ArticleStatus::class)]

Also supported in docblocks:

@bodyParam status string Enum: approved, pending, closed, new
@bodyParam status string Enum: approved, pending, closed, new. Example: new

This will:

  1. ensure the generated example is from one of these.
  2. add a line in the docs that says "Must be one of...", and add these values
  3. set the enum key in the OpenAPI spec

It does not currently restrict the values that can be entered in Try It Out, as there may still be some value in seeing how invalid values are responded to.

This may be a breaking change, as it replaces the earlier manual description setting (automatically generated for validation rules) with a structured field.

In the internal Scribe API, this adds a new enumValues field to the parameter types. This is an array of all valid values.

Closes #626

@shalvah shalvah merged commit 9b72f1a into master Aug 24, 2023
6 checks passed
@shalvah shalvah deleted the enum branch August 24, 2023 20:59
@rabol
Copy link

rabol commented Aug 25, 2023

This is a breaking change

After I updated to the latest version i get this error:

 TypeError 

  Cannot assign null to property Knuckles\Camel\Extraction\Parameter::$enumValues of type array

  at vendor/spatie/data-transfer-object/src/Reflection/DataTransferObjectProperty.php:48

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.

enum support as parameters
2 participants