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

Validate provisioning state only if azure resource #434

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ rules.push({
const allResources = utils.getAllResourceNames()
for (const resource of allResources) {
const model = utils.getResourceByName(resource)
const azureResource = swaggerUtil?.getProperty(model!, "x-ms-azure-resource")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is right to read "x-ms-azure-resource" as property here. So an existing test is failing. I'll need some help on figuring this part out so that we can run this provisioningState validation only if it is an ARM resource.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a strategy to detect if a model indicates an arm resource, see https://github.com/Azure/azure-openapi-validator/blob/main/docs/resources/resource-model-validation.md, so we don't need to check the 'x-ms-azure-resource' again here, if you encounter any false alert, please comment and I will take a look

const properties = swaggerUtil?.getProperty(model!, "properties")
const isAzureResource = azureResource && azureResource.value
let hasProvisioningState = false
if (properties && (!properties.value.type || properties.value.type === "object")) {
if (isAzureResource && properties && (!properties.value.type || properties.value.type === "object")) {
if (swaggerUtil?.getProperty(properties, "provisioningState")) {
hasProvisioningState = true
}
}
if (!hasProvisioningState) {
if (isAzureResource && !hasProvisioningState) {
yield { message: msg.replace("{0}", resource), location: ["$", "definitions", resource] as JsonPath }
}
}
Expand Down