google / google/gnostic-models
`.proto` files are in directories that don’t match their package name
- Dominant language
- Go
- Stars
- 20
- Forks
- 11
- PR merge metrics
- No merged PRs in 30d
Description
I’d like to use `gnostic`’s models in another Protobuf schema as annotations.
As part of that process, the generated Python bindings for my service need a dependency on generated Python bindings for `gnostic` models, even if they’re only used as annotations and never referenced at runtime by application code.
The build process for my own Protobuf modules generates `_pb2.py` files at build time, and then installs both `.proto` and `_pb2.py` files into Python’s `site-packages` directory using [namespace packages](https://packaging.python.org/en/latest/guides/packaging-namespace-packages/), so the directory structure (as referenced by `.proto` `import`s) must match declared package names.
This lets you point `protoc` at Python’s `site-packages`, and everything that imports from such a `.proto` just works, ie:
```sh
protoc --proto-path lib/python3.X/site-packages/ --proto_path src/ src/my_package/example.proto
```
This layout is implemented by [the `googleapis-common-protos` package](https://pypi.org/project/googleapis-common-protos/) (and likely others), and supported by [`hatch-protobuf`](https://github.com/nanoporetech/hatch-protobuf)’s build process[^1].
Unfortunately, `gnostic-models` package names don’t match file paths at all, so they’re not amenable to this usage:
* `openapiv2/` should be `openapi/v2/`:
https://github.com/google/gnostic-models/blob/fbe822a4914c5e92b4274b64b7242317f1131510/openapiv2/OpenAPIv2.proto#L19
* `openapiv3/` should be `openapi/v3/`:
https://github.com/google/gnostic-models/blob/fbe822a4914c5e92b4274b64b7242317f1131510/openapiv3/annotations.proto#L17
https://github.com/google/gnostic-models/blob/fbe822a4914c5e92b4274b64b7242317f1131510/openapiv3/OpenAPIv3.proto#L19
* `extensions/` should be `gnostic/extension/v1/`:
https://github.com/google/gnostic-models/blob/fbe822a4914c5e92b4274b64b7242317f1131510/extensions/extension.proto#L17
To fix this, you’d need to rename all these directories so they match the declared package names, and then update any references to those old paths.
[^1]: In full disclosure, I added this feature to `hatch-protobuf`. However, when `googleapis-common-protos` broke this, [people other than me complained about it too](https://github.com/googleapis/google-cloud-python/issues/13545), so I don’t think I’m the first to do this. 😄
Contributor guide
Assessment
This issue has not been assessed yet.