stackit-client-generator

module
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2023 License: Apache-2.0

README

OpenAPI Client and Server Code Generator

This repo is a fork of deepmap/oapi-codegen

Only the changes from the original repo are documented below

Non-config changes

  • NewRequest has been modified to NewRequestWithContext

Spec tidying

In cases where the OpenAPI spec isn't created by whomever generates the client, a "tidy" functionality is used to make the client more readable / styled as needed

In a configuration file, the following code can be added:

tidy:
  verbose: false
  functions:
  - replace: service_
    with: 
    prefix: true
  params:
  - replace: Id
    with: ID
    suffix: true
  schemas:
  - replace: Cpu
    with: CPU
    match: true

Splitting client code by tags

the config has been extended to support splitting the client code into multiple directories and files

Example:

output-options:
  split-by-tags:
    verbose: true
    enabled: true

theres also an options to add a list under split-by-tags of includes or excludes

Extend responses struct

For our use case we'd like to add an aggregated error if the response isn't 200

In order to do that the response struct can be extended with the following config

Example:

output-options:
  extend-response:
  - field: HasError
    type: error
    description: "Aggregated error"
    apply-to: ["*"]
    imports: ["errors"]

which generates:

type ListClustersResponse struct {
  Body         []byte
  HTTPResponse *http.Response
  // ...
  HasError     error // Aggregated error
}

Custom Doer interface

in order to load a Doer interface from another package, the following configuration can be added

output-options:
  custom-doer:
    enabled: true
    import: skeclient "github.com/do87/stackit-client-generator/examples/ske-client"
    name: "skeclient.HttpRequestDoer"

Copy supporting files

output-options:
  copy:
  - from: wait/cluster/wait.go
    to: cluster/wait.go
    tidy: 
    - replace: "cluster."
      with:
      all: true

Extend WithResponse Structs

output-options:
  extend-response:
  - field: HasError
    type: error
    description: "Aggregated error"
    apply-to: ["*"]
    set: "nil"

Will result in:

type CreateOrUpdateClusterResponse struct {
  Body         []byte
  HTTPResponse *http.Response
  // ...
  HasError     error // Aggregated error
}

This is just one of the response structs. because the matching is "*" it'll be added to all of them.

And because 'set' has a value, the corresponding Parse method will be modified to:

// ParseCreateOrUpdateClusterResponse parses an HTTP response from a CreateOrUpdateClusterWithResponse call
func (c *ClientWithResponses) ParseCreateOrUpdateClusterResponse(rsp *http.Response) (*CreateOrUpdateClusterResponse, error) {
  // ...

  response := &CreateOrUpdateClusterResponse{
    Body:         bodyBytes,
    HTTPResponse: rsp,
  }
  response.HasError = nil

Directories

Path Synopsis
cmd
examples
authenticated-api/echo/api
Package api provides primitives to interact with the openapi HTTP API.
Package api provides primitives to interact with the openapi HTTP API.
custom-client-type
Package customclienttype provides primitives to interact with the openapi HTTP API.
Package customclienttype provides primitives to interact with the openapi HTTP API.
petstore-expanded
Package petstore provides primitives to interact with the openapi HTTP API.
Package petstore provides primitives to interact with the openapi HTTP API.
petstore-expanded/chi/api
Package api provides primitives to interact with the openapi HTTP API.
Package api provides primitives to interact with the openapi HTTP API.
petstore-expanded/echo
This is an example of implementing the Pet Store from the OpenAPI documentation found at: https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v3.0/petstore.yaml
This is an example of implementing the Pet Store from the OpenAPI documentation found at: https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v3.0/petstore.yaml
petstore-expanded/echo/api
Package api provides primitives to interact with the openapi HTTP API.
Package api provides primitives to interact with the openapi HTTP API.
petstore-expanded/echo/api/models
Package models provides primitives to interact with the openapi HTTP API.
Package models provides primitives to interact with the openapi HTTP API.
petstore-expanded/gin/api
Package api provides primitives to interact with the openapi HTTP API.
Package api provides primitives to interact with the openapi HTTP API.
petstore-expanded/gorilla/api
Package api provides primitives to interact with the openapi HTTP API.
Package api provides primitives to interact with the openapi HTTP API.
petstore-expanded/strict/api
Package api provides primitives to interact with the openapi HTTP API.
Package api provides primitives to interact with the openapi HTTP API.
ske-client/generated
Package ske provides primitives to interact with the openapi HTTP API.
Package ske provides primitives to interact with the openapi HTTP API.
ske-client/generated/cluster
Package cluster provides primitives to interact with the openapi HTTP API.
Package cluster provides primitives to interact with the openapi HTTP API.
ske-client/generated/credentials
Package credentials provides primitives to interact with the openapi HTTP API.
Package credentials provides primitives to interact with the openapi HTTP API.
ske-client/generated/operation
Package operation provides primitives to interact with the openapi HTTP API.
Package operation provides primitives to interact with the openapi HTTP API.
ske-client/generated/project
Package project provides primitives to interact with the openapi HTTP API.
Package project provides primitives to interact with the openapi HTTP API.
ske-client/generated/provider-options
Package provideroptions provides primitives to interact with the openapi HTTP API.
Package provideroptions provides primitives to interact with the openapi HTTP API.
internal
test/all_of/v1
Package v1 provides primitives to interact with the openapi HTTP API.
Package v1 provides primitives to interact with the openapi HTTP API.
test/all_of/v2
Package v2 provides primitives to interact with the openapi HTTP API.
Package v2 provides primitives to interact with the openapi HTTP API.
test/any_of/param
Package param provides primitives to interact with the openapi HTTP API.
Package param provides primitives to interact with the openapi HTTP API.
test/client
Package client provides primitives to interact with the openapi HTTP API.
Package client provides primitives to interact with the openapi HTTP API.
test/components
Package components provides primitives to interact with the openapi HTTP API.
Package components provides primitives to interact with the openapi HTTP API.
test/externalref
Package externalref provides primitives to interact with the openapi HTTP API.
Package externalref provides primitives to interact with the openapi HTTP API.
test/externalref/packageA
Package packagea provides primitives to interact with the openapi HTTP API.
Package packagea provides primitives to interact with the openapi HTTP API.
test/externalref/packageB
Package packageb provides primitives to interact with the openapi HTTP API.
Package packageb provides primitives to interact with the openapi HTTP API.
test/issues/issue-312
Package issue312 provides primitives to interact with the openapi HTTP API.
Package issue312 provides primitives to interact with the openapi HTTP API.
test/issues/issue-52
Package issue52 provides primitives to interact with the openapi HTTP API.
Package issue52 provides primitives to interact with the openapi HTTP API.
test/issues/issue-579
Package issue579 provides primitives to interact with the openapi HTTP API.
Package issue579 provides primitives to interact with the openapi HTTP API.
test/issues/issue-832
Package issue_832 provides primitives to interact with the openapi HTTP API.
Package issue_832 provides primitives to interact with the openapi HTTP API.
test/issues/issue-grab_import_names
Package grabimportnames provides primitives to interact with the openapi HTTP API.
Package grabimportnames provides primitives to interact with the openapi HTTP API.
test/issues/issue-head-digit-of-httpheader
Package headdigitofhttpheader provides primitives to interact with the openapi HTTP API.
Package headdigitofhttpheader provides primitives to interact with the openapi HTTP API.
test/issues/issue-head-digit-of-operation-id
Package head_digit_of_operation_id provides primitives to interact with the openapi HTTP API.
Package head_digit_of_operation_id provides primitives to interact with the openapi HTTP API.
test/issues/issue-illegal_enum_names
Package illegalenumnames provides primitives to interact with the openapi HTTP API.
Package illegalenumnames provides primitives to interact with the openapi HTTP API.
test/issues/issue-removed-external-ref/gen/spec_base
Package spec_base provides primitives to interact with the openapi HTTP API.
Package spec_base provides primitives to interact with the openapi HTTP API.
test/issues/issue-removed-external-ref/gen/spec_ext
Package spec_ext provides primitives to interact with the openapi HTTP API.
Package spec_ext provides primitives to interact with the openapi HTTP API.
test/parameters
Package parameters provides primitives to interact with the openapi HTTP API.
Package parameters provides primitives to interact with the openapi HTTP API.
test/schemas
Package schemas provides primitives to interact with the openapi HTTP API.
Package schemas provides primitives to interact with the openapi HTTP API.
test/server
Package server provides primitives to interact with the openapi HTTP API.
Package server provides primitives to interact with the openapi HTTP API.
test/strict-server/chi
Package api provides primitives to interact with the openapi HTTP API.
Package api provides primitives to interact with the openapi HTTP API.
test/strict-server/client
Package api provides primitives to interact with the openapi HTTP API.
Package api provides primitives to interact with the openapi HTTP API.
test/strict-server/echo
Package api provides primitives to interact with the openapi HTTP API.
Package api provides primitives to interact with the openapi HTTP API.
test/strict-server/gin
Package api provides primitives to interact with the openapi HTTP API.
Package api provides primitives to interact with the openapi HTTP API.
pkg
chi-middleware
Package middleware implements middleware function for go-chi or net/http, which validates incoming HTTP requests to make sure that they conform to the given OAPI 3.0 specification.
Package middleware implements middleware function for go-chi or net/http, which validates incoming HTTP requests to make sure that they conform to the given OAPI 3.0 specification.
securityprovider
Package securityprovider contains some default securityprovider implementations, which can be used as a RequestEditorFn of a client.
Package securityprovider contains some default securityprovider implementations, which can be used as a RequestEditorFn of a client.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL