|
| 1 | +# Public API |
| 2 | + |
| 3 | +Understand what constitutes the public API of gRPC Swift and the commitments |
| 4 | +made by the maintainers. |
| 5 | + |
| 6 | +## Overview |
| 7 | + |
| 8 | +The gRPC Swift project uses [Semantic Versioning 2.0.0][0] which requires |
| 9 | +projects to declare their public API. This document describes what is and isn't |
| 10 | +part of the public API; commitments the maintainers make relating to the API; |
| 11 | +and guidelines for users. |
| 12 | + |
| 13 | +For clarity the project is comprised of the following Swift packages: |
| 14 | + |
| 15 | +- [grpc/grpc-swift][1], |
| 16 | +- [grpc/grpc-swift-nio-transport][2], |
| 17 | +- [grpc/grpc-swift-protobuf][3], and |
| 18 | +- [grpc/grpc-swift-extras][4]. |
| 19 | + |
| 20 | +## What _is_ and _isn't_ public API |
| 21 | + |
| 22 | +### Library targets |
| 23 | + |
| 24 | +All library targets made available as package products as considered to be |
| 25 | +public API. Examples of these include `GRPCCore` and `GRPCProtobuf`. |
| 26 | + |
| 27 | +> Exceptions: |
| 28 | +> Targets with names starting with an underscore (`_`) aren't public API. |
| 29 | +
|
| 30 | +### Symbols |
| 31 | + |
| 32 | +All publicly exposed symbols (i.e. symbols which are declared as `public`) |
| 33 | +within public library targets or those which are re-exported from non-public |
| 34 | +targets are part of the public API. Examples include `Metadata`, |
| 35 | +`ServiceConfig`, and `GRPCServer`. |
| 36 | + |
| 37 | +> Exceptions: |
| 38 | +> - Symbols starting with an underscore (`_`), for example `_someFunction()` and |
| 39 | +> `_AnotherType` aren't public API. |
| 40 | +> - Initializers where the first character of the first parameter label is an |
| 41 | +> underscore, for example `init(_foo:)` aren't public API. |
| 42 | +
|
| 43 | +### Configuration and inputs |
| 44 | + |
| 45 | +Any configuration, input, and interfaces to executable products which have |
| 46 | +inputs (such as command line arguments, or configuration files) are considered |
| 47 | +to be public API. Examples of these include the configuration file passed to the |
| 48 | +Swift Package Manager build plugin for generating stubs provided by |
| 49 | +[grpc-swift-protobuf][3]. |
| 50 | + |
| 51 | +> Exceptions: |
| 52 | +> - Executable _targets_ which aren't exposed as executable _products_. |
| 53 | +
|
| 54 | +## Commitments made by the maintainers |
| 55 | + |
| 56 | +Without releasing a new major version, the gRPC Swift maintainers commit to not |
| 57 | +adding any new types to the global namespace without a "GRPC" prefix. |
| 58 | + |
| 59 | +To illustrate this, the maintainers may: |
| 60 | +1. Add a new type to an existing module called `GRPCPanCakes` but will not add a |
| 61 | + new type called `PanCakes` to an existing module. |
| 62 | +2. Add a new top-level function to an existing module called `grpcRun()` but |
| 63 | + won't add a new top-level function called `run()`. |
| 64 | +3. Add a new module called `GRPCFoo`. Any symbols added to the new module at the |
| 65 | + point the module becomes API aren't required to have a "GRPC" prefix; symbols |
| 66 | + added after that point will be prefixed as required by (1) and (2). |
| 67 | + |
| 68 | +This allows the project to follow Semantic versioning without breaking adopter |
| 69 | +code in minor and patch releases. |
| 70 | + |
| 71 | +## Guidelines for users |
| 72 | + |
| 73 | +In order to not have your code broken by a gRPC Swift update you should only use |
| 74 | +the public API as described above. There are a number of other guidelines you |
| 75 | +should follow as well: |
| 76 | + |
| 77 | +1. You _may_ conform your own types to protocols provided by gRPC Swift. |
| 78 | +2. You _may_ conform types provided by gRPC Swift to your own protocols. |
| 79 | +3. You _mustn't_ conform types provided by gRPC Swift to protocols that you |
| 80 | + don't own, and you mustn't conform types you don't own to protocols provided |
| 81 | + by gRPC Swift. |
| 82 | +4. You _may_ extend types provided by gRPC Swift at `package`, `internal`, |
| 83 | + `private` or `fileprivate` level. |
| 84 | +5. You _may_ extend types provided by gRPC Swift at `public` access level if |
| 85 | + doing so means that a symbol clash is impossible (such as including a type |
| 86 | + you own in the signature, or prefixing the method with the namespace of your |
| 87 | + package in much the same way that gRPC Swift will prefix new symbols). |
| 88 | + |
| 89 | +[0]: https://semver.org |
| 90 | +[1]: https://github.com/grpc/grpc-swift |
| 91 | +[2]: https://github.com/grpc/grpc-swift-nio-transport |
| 92 | +[3]: https://github.com/grpc/grpc-swift-protobuf |
| 93 | +[4]: https://github.com/grpc/grpc-swift-extras |
0 commit comments