Skip to content

Conversation

@nguerrera
Copy link
Contributor

@nguerrera nguerrera commented Apr 20, 2022

  • Correctly URI-encode OpenAPI refs when necessary. Delete broken code that attempted to address this with name mangling.

  • Remove all regexes from how we decide what to inline and what to ref, and how to name things. The reasoning is now done on the type objects, and not on their serialized names.

  • The current choices are preserved modulo obvious bugs, but I will open an issue to revisit some of them. It will be easier to change after this refactoring. (Edit: filed Review inlining and naming choices in OpenAPI #464)

  • Centralize the logic in the shared openapi lib for reuse by cadl-autorest.

  • Fix issues with the regex-based stripping of Cadl and service namespaces by replacing that with a namespace filter callback on Checker.getTypeName.

  • Defend against parameter key and type name collisions with diagnostics.

* Correctly URI-encode OpenAPI refs when necessary. Delete broken code that
attempted to address this with name mangling.

* Remove all regexes from how we decide what to inline and what to ref, and
how to name things. The reasoning is now done on the type objects, and not
on their serialized names.

* The current choices are preserved modulo obvious bugs, but I will open an
issue to revisit some of them. It will be easier to change after this
refactoring.

* Centralize the logic in the shared openapi lib for reuse by cadl-autorest.

* Fix issues with the regex-based stripping of Cadl and service namespaces
by replacing that with a namespace filter callback on Checker.getTypeName.

* Defend against parameter key and type name collisions with diagnostics.
@azure-pipelines
Copy link

You can try these changes at https://cadlplayground.z22.web.core.windows.net/prs/463/

@nguerrera
Copy link
Contributor Author

cc @xirzec

getLiteralType(node: LiteralNode): LiteralType;
getTypeName(type: Type): string;
getNamespaceString(type: NamespaceType | undefined): string;
getTypeName(type: Type, options?: TypeNameOptions): string;
Copy link
Member

Choose a reason for hiding this comment

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

Not really in the scope of this PR but couldn't getTypeName be moved out of the checker. Doesn't feel like they depend on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, I can look at doing that as part of some other work I'm doing nearby next.

getFriendlyName(program, type, options) ?? program.checker!.getTypeName(type, options);

if (existing && existing[name] !== undefined) {
reportDiagnostic(program, {
Copy link
Member

Choose a reason for hiding this comment

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

Should we report both instances conflicting. That's what we have for duplicate-symbol or duplicate routes.

Copy link
Contributor Author

@nguerrera nguerrera Apr 21, 2022

Choose a reason for hiding this comment

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

We should. It will take some more refactoring to do the bookkeeping. If you don't mind, I'd rather add this to the list to review on #464 because it will be easier to review more refactoring separately, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We weren't handling the collisions at all before so this is a strict improvement already.

Copy link
Contributor

@daviwil daviwil left a comment

Choose a reason for hiding this comment

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

Overall, I like it! It is a little weird to see Rest.Resource.Something instead of Cadl.Rest.Resource.Something in some places, but it's not a huge issue.

@nguerrera
Copy link
Contributor Author

It is a little weird to see Rest.Resource.Something instead of Cadl.Rest.Resource.Something in some places, but it's not a huge issue.

It should be the case that you don't see Cadl.Rest in the OpenAPI anymore anywhere. It used to be rather haphazard when we'd remove Cadl. Now we remove it thoroughly and some things look a little weird as a result. I do have a note on #464 to revisit this.

@nguerrera nguerrera merged commit dfb3936 into microsoft:main Apr 21, 2022
@nguerrera nguerrera deleted the url-encode-ref branch April 21, 2022 19:38
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.

3 participants