Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Scripting to generate the CloudOps Software Golang SDK using OpenAPI

NotificationsYou must be signed in to change notification settings

cloudops/cloudops_golang_sdk_generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The includedMakefile is a convenience tool for generating the CloudOps Software Golang SDKs via the OpenAPI specification. It also integrates aninline schema lifter to fix compatibility issues with Go SDK generation.

Initial Setup

First, install theopenapi-generator. For thisMakefile to work, you will need to install it with Homebrew:

brew install openapi-generator

Next, set up the variables and folder structure:

cp variables.env.sample variables.envmake setup

Make sure to configure the variables invariables.env to match your environment.

This will create the following folders:

  • ./api_specs → stores downloaded OpenAPI specs
  • ./logs → stores generation logs
  • ./sdk_out → stores generated SDKs

The Inline Schema Lifter

Many OpenAPI specs containinline schemas that cause problems with Golang SDK generation (invalid names, regex errors, or missing references). To solve this, we use theinline lifter script before passing the specs intoopenapi-generator.

How it Works

  1. The lifter takes an input spec (JSON/YAML) and traverses it.
  2. Inline schemas arelifted into#/components/schemas with auto-generated, sanitized names.
  3. Invalid schema names are cleaned to meet Go’s naming restrictions.
  4. Content wrapper issues are fixed so thatapplication/json blocks always contain properschema references.
  5. The transformed spec is saved with the suffix_openapi_lifted.json.

This ensures that the final specs are compatible with Golang SDK generation.

Example

make generate_core

This will:

  • Download thecore_openapi.json spec
  • Run theinline lifter to producecore_openapi_lifted.json
  • Generate thecmc_core SDK into./sdk_out/cmc_core

Logs will be available in./logs/core_output.log.

Go Generator Config (go-generator-config.json)

This file contains additional configuration passed to theOpenAPI Generator when producing the Go SDKs.It controls aspects of code layout, naming conventions, and how models and APIs are organized.

Current settings:

{"enumClassPrefix":true,"withSeparateModelsAndApi":true,"modelPackage":"models","apiPackage":"apis","generateInterfaces":true}

Explanation of fields:

  • enumClassPrefix: Ensures that generated enums are prefixed with their class name, reducing naming conflicts.
  • withSeparateModelsAndApi: Places models and API clients in separate packages for cleaner project organization.
  • modelPackage: Directory/package name where generated models are placed (models).
  • apiPackage: Directory/package name where generated API clients are placed (apis).
  • generateInterfaces: Generates interfaces for the APIs, which makes mocking and testing easier in Go.

How it’s used

Eachgenerate_* target in theMakefile passes the config file using:

-c ./go-generator-config.json

This means that all generated SDKs (core, aws, azure, vcd, acs) will follow the same structure and conventions defined here.If you need different configurations for different SDKs, you can create multiple config files and adjust the Makefile accordingly.

Generating the SDK

To fetch all specs:

make curl

To generate all SDKs:

make generate

You can also target specific clouds:

  • make generate_core
  • make generate_aws
  • make generate_azure
  • make generate_vcd
  • make generate_acs

The SDKs will be available in./sdk_out/<cloud> and the logs in./logs.

Backup Folders

Before regenerating specs/SDKs, you may want to back up your current environment:

make backup

This moves./api_specs and./sdk_out into timestamped backup directories.

Reset Folders

To clean up logs and SDKs:

make reset

To clean up the API specs:

make reset_spec

Warning: These commands delete data. Usemake backup if you need a rollback point.

Using the SDK

Since the SDK is not yet tracked as an official release, you must reference it manually in your Go project.

For example, to use thecmc_core SDK locally:

In yourgo.mod file:

require (github.com/cloudops/cmc_corev0.0.0)replacegithub.com/cloudops/cmc_core=>/path/to/sdk_out/cmc_core

This establishes the import path (github.com/cloudops/cmc_core) and redirects it to your local build.

To use a different GitHub handle, update theGITHUB_HANDLE invariables.env accordingly.

About

Scripting to generate the CloudOps Software Golang SDK using OpenAPI

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp