Skip to content

Conversation

@daviwil
Copy link
Contributor

@daviwil daviwil commented Aug 29, 2023

This change fixes Azure/typespec-azure#3333 by adding a validation step in the @typespec/http library which checks whether any referenced operation lives inside of an interface or namespace with a @route prefix defined.

This check is intended to help a spec author avoid the case where an operation loses the prefix of its referenced operation because it is used outside of the original container. The issue was originally raised in issue #1466.

@github-actions
Copy link
Contributor

Changes in this PR will be published to the following url to try(check status of TypeSpec Pull Request Try It pipeline for publish status):
Playground: https://cadlplayground.z22.web.core.windows.net/prs/2337/

Website: https://cadlwebsite.z1.web.core.windows.net/prs/2337/

@daviwil daviwil requested a review from tjprescott August 29, 2023 13:46
import { getRoutePath, isSharedRoute } from "./route.js";
import { OperationContainer } from "./types.js";

function checkOperationReferenceContainerRoutes(program: Program) {
Copy link
Member

Choose a reason for hiding this comment

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

I believe this should be a linter rule warning. $onValidate is typically reserved for errors.

Copy link
Member

Choose a reason for hiding this comment

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

@catalinaperalta can you confirm?

Copy link
Member

Choose a reason for hiding this comment

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

That's correct. With the new linter rule system only errors should be in onValidate. This does look like it should be a linter rule warning.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, I'll work on that. There wasn't any existing linter rule infra in this package yet so I took the easy route.

Copy link
Contributor Author

@daviwil daviwil Aug 31, 2023

Choose a reason for hiding this comment

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

OK, I've looked at @catalinaperalta's changes to migrate the rules in typespec-azure and it makes sense, but I wonder if we start exposing linter rules from @typespec/http if we have to add an extends for it in typespec-azure-core. What do you think @catalinaperalta?

EDIT: By that same logic, we might need to pre-emptively add the ruleset of @typespec/rest too because there's a direct relationship through those libraries to Azure.Core.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the design to use the new linting framework instead. @timotheeguerin, how does it look? Also, can you answer the question I asked above?

Copy link
Member

@catalinaperalta catalinaperalta Sep 5, 2023

Choose a reason for hiding this comment

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

@daviwil Yes we'd need to extend this in typespec-azure-core to keep checking for the warnings coming from @typespec/http.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks!

@@ -0,0 +1,28 @@
// FIXME - This is a workaround for the circular dependency issue when loading
Copy link
Member

Choose a reason for hiding this comment

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

:( showing up everywhere now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it took me a while to figure out what was going on there. I happened to catch the workaround from the ARM library

import { OperationContainer } from "../types.js";

export const operationReferenceContainerRouteRule = createRule({
name: "operation-reference-container-route",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
name: "operation-reference-container-route",
name: "op-reference-container-route",

nit: would be a little nicer to use the short name for those?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's a bit long

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed the rule

Copy link
Member

@timotheeguerin timotheeguerin left a comment

Choose a reason for hiding this comment

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

Looks great I think we probably want this to be added to the azure core and arm rulesets too.

@daviwil daviwil requested a review from tjprescott September 5, 2023 17:10
@daviwil daviwil dismissed tjprescott’s stale review September 6, 2023 09:54

Feedback has been addressed.

ruleSets: {
all: {
enable: {
[`@typespec/http/${operationReferenceContainerRouteRule.name}`]: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like we need to add this rule to the azure-core ruleset in a separate PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sent PR Azure/typespec-azure#3546 to add this

@daviwil daviwil enabled auto-merge (squash) September 11, 2023 14:29
@daviwil daviwil merged commit 4b0eb8e into microsoft:main Sep 11, 2023
@daviwil daviwil deleted the no-route-containers branch September 11, 2023 14:41
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.

5 participants