Add allowedValues annotations for remaining static enum parameters - #13783
Add allowedValues annotations for remaining static enum parameters#13783dheeraj12347 wants to merge 6 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Adds allowedValues metadata to API parameter discovery so fixed-value parameters can be surfaced in API discovery tooling (e.g., CloudMonkey autocompletion) without changing runtime behavior.
Changes:
- Extends
@Parameterwith a newallowedValues()attribute and annotates multiple commands’ enum-like parameters. - Propagates
allowedValuesinto API discovery responses viaApiDiscoveryServiceImplandApiParameterResponse. - Updates discovery test setup to account for the new annotation attribute.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| plugins/api/discovery/src/test/java/org/apache/cloudstack/discovery/ApiDiscoveryServiceImplTest.java | Stubs allowedValues() on mocked @Parameter to keep tests passing after annotation change. |
| plugins/api/discovery/src/main/java/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java | Reads allowedValues from @Parameter and exposes it in discovery response parameters. |
| plugins/api/discovery/src/main/java/org/apache/cloudstack/api/response/ApiParameterResponse.java | Adds allowedvalues field (and getter/setter) to discovery parameter response model. |
| api/src/main/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java | Adds allowedValues metadata for format and arch. |
| api/src/main/java/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java | Adds allowedValues metadata for template filter and arch. |
| api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/ListSnapshotsCmd.java | Adds allowedValues metadata for interval/snapshot/location types. |
| api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotPolicyCmd.java | Adds allowedValues metadata for snapshot policy interval type. |
| api/src/main/java/org/apache/cloudstack/api/command/user/nat/CreateIpForwardingRuleCmd.java | Adds allowedValues metadata for protocol. |
| api/src/main/java/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java | Adds allowedValues metadata for ISO filter and arch. |
| api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/CreateIpv6FirewallRuleCmd.java | Adds allowedValues metadata for IPv6 firewall traffic type. |
| api/src/main/java/org/apache/cloudstack/api/command/user/firewall/CreateFirewallRuleCmd.java | Adds allowedValues metadata for firewall protocol. |
| api/src/main/java/org/apache/cloudstack/api/command/user/backup/CreateBackupScheduleCmd.java | Adds allowedValues metadata for backup schedule interval type. |
| api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateConditionCmd.java | Adds allowedValues metadata for relational operator. |
| api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateConditionCmd.java | Adds allowedValues metadata for relational operator. |
| api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmd.java | Adds allowedValues metadata for internet protocol and network mode. |
| api/src/main/java/org/apache/cloudstack/api/command/admin/user/ListUsersCmd.java | Adds allowedValues metadata for user authentication source. |
| api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java | Adds allowedValues metadata for provisioning type. |
| api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateDiskOfferingCmd.java | Adds allowedValues metadata for provisioning type. |
| api/src/main/java/org/apache/cloudstack/api/Parameter.java | Adds allowedValues() to @Parameter annotation definition. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| String[] allowedValues = parameterAnnotation.allowedValues(); | ||
| if (allowedValues.length > 0) { | ||
| paramResponse.setAllowedValues( | ||
| Collections.unmodifiableList(Arrays.asList(allowedValues)) | ||
| ); | ||
| } |
| Mockito.when(parameterMock.name()).thenReturn("paramName"); | ||
| Mockito.when(parameterMock.since()).thenReturn(""); | ||
| Mockito.when(parameterMock.entityType()).thenReturn(new Class[]{Object.class}); | ||
| Mockito.when(parameterMock.allowedValues()).thenReturn(new String[]{}); |
| description = "The traffic type for the Ipv6 firewall rule, can be ingress or egress, defaulted to ingress if not specified", | ||
| allowedValues = { | ||
| "Ingress", | ||
| "Egress" | ||
| }) |
| description = "The internet protocol of the offering. Options are IPv4 and dualstack. Default is IPv4. dualstack will create an offering that supports both IPv4 and IPv6", | ||
| since = "4.17.0", | ||
| allowedValues = { | ||
| "IPv4", | ||
| "DualStack" | ||
| }) |
| paramResponse.setAllowedValues( | ||
| Collections.unmodifiableList(Arrays.asList(allowedValues)) | ||
| ); |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #13783 +/- ##
============================================
+ Coverage 18.08% 19.65% +1.56%
- Complexity 16721 19791 +3070
============================================
Files 6037 6368 +331
Lines 542580 574891 +32311
Branches 66428 70352 +3924
============================================
+ Hits 98149 112968 +14819
- Misses 433409 449650 +16241
- Partials 11022 12273 +1251
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Description
This PR adds missing
allowedValuesannotations for API parameters that expose a fixed set of valid values.The updated commands are:
CreateDiskOfferingCmd(provisioningType)CreateServiceOfferingCmd(provisioningType)CreateConditionCmd(relationalOperator)UpdateConditionCmd(relationalOperator)ListUsersCmd(userSource)These parameters already documented their valid values in the API description. This change makes the same information available through API discovery metadata, improving downstream tooling such as CloudMonkey autocompletion while preserving existing runtime behavior.
Testing