This file provides general guidance for anyone contributing to IBM Cloud Go SDK projects produced by the IBM OpenAPI SDK Generator.
- Questions
- Coding Style
- Commit Messages
- Pull Requests
- Adding a new service
- Running tests
- Developer's Certificate of Origin 1.1
- Additional Resources
If you are having problems using the APIs or have a question about IBM Cloud services, please ask a question at Stack Overflow.
The SDK follows the Go coding conventions documented here. You can run the linter with the following command:
golangci-lint run
Commit messages should follow the Angular Commit Message Guidelines. This is because our release tool - semantic-release - uses this format for determining release versions and generating changelogs. Tools such as commitizen or commitlint can be used to help contributors and enforce commit messages. Here are some examples of acceptable commit messages, along with the release type that would be done based on the commit message:
Commit message | Release type |
---|---|
fix(resource controller): fix integration test to use correct credentials |
Patch Release |
feat(global catalog): add global-catalog service to project |
|
feat(global search): re-gen service code with new v3 API definition BREAKING CHANGE: The global-search service has been updated to reflect version 3 of the API. |
If you want to contribute to the repository, follow these steps:
- Fork the repository
- Develop and test your code changes:
- To build/test:go test ./...
- Please add one or more tests to validate your changes.
- Make sure everything builds/tests cleanly
- Commit your changes
- Push to your fork and submit a pull request to the main branch
This section will guide you through the steps to generate the Go code for a service and add the generated code to your SDK project.
- Validate the API definition - before trying to process the API definition with the SDK generator, we strongly recommend that you validate the API definition with the IBM OpenAPI Validator . Example:
lint-openapi -s example-service.yaml
This command will display a list of errors and warnings found in the API definition as well as a summary at the end. It's not required that you fix all errors and warnings before trying to use the SDK generator, but this step should identify any critical errors that will need to be fixed prior to the generation step.
- Recommended: Modify your API definition to configure the
apiPackage
property. The value of this property should be the module import path for your SDK project (e.g.github.com/IBM/platform-services-go-sdk
). Here's an example:
info:
x-codegen-config:
go:
apiPackage: 'github.com/IBM/platform-services-go-sdk'
By adding this configuration property to your API definition, you can avoid using the --api-package
command line option when running the SDK generator.
More details about SDK generator configuration properties can be found here.
- Next, run the SDK generator to process your API definition and generate the service and unit test code for the service.
You'll find instructions on how to install and run the SDK generator on the generator repository wiki.
Set the output location for the generated files to be the root directory of the project.
If you did not configure the apiPackage
configuration property in your API definition file(s), then
be sure to use the --api-package <module-import-path>
command line option when running the SDK generator to
ensure that source files are generated correctly for your project.
Here is an example of how to generate the Go code for an API definition.
Suppose your API definition file is named my-service.json
and contains the definition of the "My Service"
service.
To generate the code into your project, run these commands:
cd <project-root>
openapi-sdkgen.sh generate -g ibm-go -i my-service.json -o . --api-package <module-import-path>
The generated service and unit test code will be written to a package directory under your
project root directory that reflects the Go package name associated with the service.
For the example above, the package directory would be named myservicev1
. You should have a service
package directory for each of the services contained in your project, plus the common
directory for
the "common" package.
Hint: you can generate an initial integration test for your service by including the --genITs
option
when running the SDK generator. This will generate an integration test along with the service and
unit test code within the package directory for the service. It is expected that the generated integration
test is a starting point which will need manual editing to form an effective integration test for the service.
-
Update the service table in the
README.md
file to add an entry for the new service. -
Repeat the steps in this section for each service to be included in your project.
The tests within the SDK consist of both unit tests and integration tests.
Unit tests exercise the SDK function with local "mock" service endpoints.
To run all the unit tests contained in the project:
go test ./...
To run a unit test for a specific package within the SDK project:
cd <package-dir>
(e.g.cd globalsearchv2
)go test
Integration tests use actual service endpoints deployed in IBM Cloud, and therefore require the appropriate credentials.
To run all integration tests contained in the project:
- Make sure you have provided the appropriate credentials for all the services
go test ./... -tags=integration
To run the integration test for a single service:
- Make sure you have provided the appropriate credentials for the service being tested
cd <package-dir>
(e.g.cd globalsearchv2
)go test -tags=integration
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or
(b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or
(c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it.
(d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved.