Skip to content

Commit db511f9

Browse files
authored
Added shared library guideline (#22162)
* Added shared library guidline * Use sample project in example
1 parent fe6e157 commit db511f9

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

documentation/cadl-structure-guidelines.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,26 +105,22 @@ To distinguish between folders which define a service, an SDK, or both, one can
105105

106106
The service family library concept allows a family of services to share common models, linter rules, templates, etc.
107107

108-
Service libraries can include unpublished service _family_ libraries via source dependency annotations in `package.json`:
108+
Service libraries can reference unpublished service _family_ libraries via relative path import in `*.cadl`:
109109

110-
```json
111-
"peerDependencies": {
112-
"@azure-tools/cadl-azure-core": "~x.x.x",
113-
"@cadl-api-spec/azure-communication-common": "file: ../Communication.Shared"
114-
},
110+
```cadl
111+
import "../Contoso.WidgetManager.Shared";
115112
```
116113

117114
While this would permit services from importing any service library described in the specs repo, as a matter of policy we should probably avoid that and have tooling to detect this scenario. Service family libraries **should** use versioning decorators and spec packages should reference them as versioned dependencies. Tooling would need to ensure that changes to service family libraries does not result in unexpected changes to any service version. One way to do this would be to diff the projection of the service versions on the `main` branch against the projection of the service versions that result from the change.
118115

119-
We treat the shared library as a sibling with other packages within the service family. This is similar to what we currently do for services that have a "Shared" package and would allow an arbitrary number of shared packages.
116+
We treat the shared library as a sibling with other packages within the service family. This is similar to what we currently do for services that have a "Shared" package and would allow an arbitrary number of shared packages. A shared library folder should not contain `cadl-project.yaml` and `package.json` as it's not requried to be released. See [Sample Project](#sample-project) for reference.
120117

121118
```
122119
-> specification
123-
-> communication
124-
-> Communication.Chat (data-plane)
125-
-> Communication.Calling (data-plane)
126-
-> Communication.Management (management)
127-
-> Communication.Shared (shared)
120+
-> contosowidgetmanager
121+
-> Contoso.WidgetManager (data-plane)
122+
-> Contoso.WidgetManager.Management (management)
123+
-> Contoso.WidgetManager.Shared (shared)
128124
```
129125

130126
Here's an example of how Cognitive Services might use multiple shared libraries:

0 commit comments

Comments
 (0)