Install dependencies using:
go install
To build the project run:
go build -o mgc
The mgc
executable produced by this command will not contain the OpenAPI files in it. Instead, it will read them from the directory stored at MGC_SDK_OPENAPI_DIR
environment variable. To produce a build with the OpenAPI files embedded in it, run:
go build -tags "embed" -ldflags "-s -w" -o mgc
NOTE: consider using
scripts/build_release.sh
to build with recommended flags for all supported platforms.
Run add_specs.sh:
scripts/add_specs.sh <API_NAME> <API_ENDPOINT_NAME> <API_URL> <CANONICAL_URL>
It will start a process that uses the following scripts:
This process uses a file called <API_NAME>.openapi.yaml
stored in $CUSTOM_DIR
(default openapi-customizations
) which is used to add interface-specific modifications that make CLI and TF usage cleaner.
In short, what it does is:
- Get the internal and external (the public one) OAD;
- See if there is a difference between the current external requestBody and the internal requestBody, if there is, update the external with the internal requestBody schema;
- Replace the Error object by simplifying the error response with an object containing
message
andslug
(The Magalu Kong gateway already does this for the external OAD but as the internal one does not go through Kong we have to make this replacement here too); - Remove
x-tenant-id
param from OAD actions; - Merge the OAD with the custom file mentioned above.
The result is a YAML file called <API_NAME>.openapi.yaml
stored in $OAPIDIR
(default mgc/cli/openapis
) which is ready to be used by the CLI.
NOTE: For the resulting yaml to actually be seen it needs to be indexed, this is easily done by running oapi_index_gen.py:
python3 ./scripts/oapi_index_gen.py "--embed=mgc/sdk/openapi/embed_loader.go" mgc/cli/openapis
Alternatively, use add_all_specs.sh by editing it (add a line executing add_specs.sh) and runing it.