Azure / azure-openapi-validator

Azure Open API Validator
MIT License
47 stars 46 forks source link

[TypeSpec False Positives] EvenSegmentedPathForPutOperation and XmsPageableForListCalls with @singleton #646

Open mikeharder opened 8 months ago

mikeharder commented 8 months ago

The regex used by EvenSegmentedPathForPutOperation requires the last path segment to be wrapped in curly braces:

https://github.com/Azure/azure-openapi-validator/blob/2873e674ce169c7c459a1a8028d75e058ff0f873/packages/rulesets/src/spectral/az-arm.ts#L556

This fails to match the OpenAPI generated by TypeSpec @singletons:

@singleton
model Employee is TrackedResource<EmployeeProperties>

.../providers/Microsoft.ContosoProviderHub/employees/default

But it does match the OpenAPI generated by TypeSpec when not using @singleton:

model Employee is TrackedResource<EmployeeProperties> {

.../providers/Microsoft.ContosoProviderHub/employees/{employeeName}

Should EvenSegmentedPathForPutOperation be adjusted to make optional the curly braces around the last path segment? Or even allow only the string default for TypeSpec singletons?

Rule XmsPageableForListCalls has a similar bug but in the opposite direction. It assumes if a path does not end with }, it must specify x-ms-pageable, which I believe should not apply to the default path generated from TypeSpec @singleton.

https://github.com/Azure/azure-openapi-validator/blob/2873e674ce169c7c459a1a8028d75e058ff0f873/packages/rulesets/src/spectral/az-arm.ts#L385

gary-x-li commented 2 weeks ago

Here's another example. Perhaps consider allowing the word current as singleton as well: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridCompute/machines/{machineName}/providers/Microsoft.HybridCompute/networkConfigurations/current