-
Notifications
You must be signed in to change notification settings - Fork 230
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
Proposal for sidecar files #218
Comments
Does |
Yep, everything outlined here works already. This issue is more about, does this pattern seem good, should we bless it as a recommended pattern, should we work on establishing conventions/add tests/etc. |
|
Here is an example using yaml to represent doc and examples injections. Behind the scenes will still be processed by projection, but this is more compact without the projection artifacts. The files can even be separated into doc.yaml, example.yaml to provide a concentrated view of the additional data. This does not exclude using projections for more advanced or targeted projections.
|
This comment was marked as duplicate.
This comment was marked as duplicate.
I don't think we should do something with yaml. If we want less verbosity, more declarative or what not, then we should consider language features that we can tool, etc. For example, C# partial classes and methods have their attributes merged together, IIRC. My fear here is that doing it with YAML won't be any easier but will have a lot of consequences. Years ago, for example FxCop suppressions were carried in a sidecar XML file and the end-to-end experience was pretty brutal IMHO. |
Thing good about projection is this is part of the language. Doesn't feel like some "hack" or patching job build after the fact(autorest directives). Feel like there might be some simplification in the projection language we might want instead. |
I had some conversations with Allen offline but will share my feeling here. YAML is extremely complex and combining with cadl would have a combinatorial complexity effect that I really want to avoid. We should focus on goals and investigate native-cadl solutions to those. One example is making projections |
"The solution space is rich so I think once we get crisp on goals we can find a way to leverage our existing machinery in a way that reduces verbosity without increasing complexity, sacrificing toolability, etc." |
Here's the proposed Overlay spec for OpenAPI (it's actually defined more broadly, but motivated by the OpenAPI use cases): https://github.com/OAI/Overlay-Specification/blob/main/versions/1.0.0.md |
Action items:
Future considerations
Note on usage:projection model#typescript {
@doc(self.name, "My pet name")
@doc(self.age, "My pet age")
} will apply to all models. Similar selectors exist for:
|
|
In the last few months I think we've learned more about how folks want to use this sidecar story and there are a few undesirable aspects to the "just use projections" approach:
Thus, I propose a new approach: augment decorators (name is horrible please suggest better names) Syntax
For example, a sidecar file
Combined with Semantics Implementation Projections already exposes decorators where the first parameter is the target. The projection syntax should be changed to align (which will also enable the possibility of declaring decorated types inside a projection). This is technically a breaking change but we yell at you if you use projections so I feel this is morally justified. |
+1 I like this proposal. My only question is where are augment decorators allowed to occur. Wherever a statement can? Only at top level? I also like the name "augment decorator" fine. 🙂 |
I think it's just a statement yeah, updated proposal to reflect. I don't think we gain much by limiting it further than that, and it might be frustrating if it has to go only at top-level given when you want to have types in the sidecar file as well (and thus likely want to use a blockless namespace). |
Another update to the proposal: projections currently allows |
I like it as well, the |
Just thinking about alternative syntax. Not sure if it's better, but might as well write down an idea that occurs to me.
We add:
Possible advantages:
Could also make tooling easier since we wouldn't have to special case @@ vs @ in things like signature help. (EDIT: But I guess we will need to handle the leading argument difference in projections still.) |
IMO using the same syntax for augment and the projection is a good thing. In one case you augmenting all the time in the other with a specific projection. if decorator worked after that would also not look too bad
|
I was thinking along those lines as I was pondering how you might augment by adding or wrapping parts of the type, e.g. to augment a member to an array you could do something like:
would be equivalent to
This would enable adding multiple decorators inside a model without constantly repeating the same model name. But this is starting to look pretty complex! |
I feel like the change from |
Yeah, it's starting to look an awful lot like |
|
removing dpg imnpact, asn this is covered by the client design issues (which are labeled as DPG Impact) |
@markcowl if this has been decomposed to implementation issues, is there a reason this design issue is still open? |
This has been implemented, so closing this issue. |
Generating high-quality clients across multiple languages can require significant amounts of metadata. One approach to this problem is just to say hey, add all your metadata to the service definition itself. The drawback is, I fear if you're generating code across say a dozen languages, the core API specification will be buried under a sea of metadata. Additionally, it requires coordination between the service authors and the client generators to share metadata definitions which may not be possible or desirable (e.g. because the API definition is provided by company A and company B is generating clients for their own use).
I propose we handle this scenario using side-car files which are able to add metadata to existing API specifications. Consider the following sidecar using the experimental projections feature:
Using the
--include
command line option we can then include this transform. Then, our custom emitter can enable thetypescript
projection when emitting a typescript client.This approach has some nice benefits:
The nice part is I don't think this needs any new language support, although it might be nice to allow projections to omit the explicit
to { }
block if this becomes a common scenario./cc @allenjzhang
The text was updated successfully, but these errors were encountered: