compiler

package
v0.0.0-...-2ebdb1d Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2022 License: BSD-3-Clause Imports: 22 Imported by: 0

Documentation

Overview

Package oapigen provides automatically generates Go API client based on OpenAPI schema.

Index

Constants

View Source
const (
	SchemaNameSwagger = "swagger"
	SchemaNameOpenAPI = "openapi"
)
View Source
const Apache2 = License(`Copyright %d %s

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.`)
View Source
const BSD2Clause = License(`Copyright %d %s

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.`)
View Source
const BSD3Clause = License(`Copyright %d %s

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.`)
View Source
const GPL3 = License(`Copyright (C) %d  %s

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.`)

Variables

This section is empty.

Functions

func Depunct

func Depunct(ident string, needCap bool) string

Depunct removes '-', '.', '$', '/', '_' from identifers, making the following character uppercase. Multiple '_' are preserved.

func FixName

func FixName(name string) (should string)

FixName returns a fixed name based by Go naming idiom.

ported from golang.org/x/lint/lint.go

func IsDigit

func IsDigit(c byte) bool

IsDigit returns whether the r is digit.

func IsVowel

func IsVowel(r rune) bool

IsVowel returns whether the r is vowel letter.

func NormalizeParam

func NormalizeParam(param string) string

NormalizeParam normalizes param for hack for invalid spinnaker swagger schema.

func SortedMapKeys

func SortedMapKeys(v interface{}) []string

SortedMapKeys returns the keys of m, which must be a map[string]T, in sorted order.

Types

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator represents a Go source generator from OpenAPI.

func New

func New(schemaType, pkgName, filename string) (*Generator, error)

New parses path JSON file and returns the new Generator.

func (*Generator) Generate

func (g *Generator) Generate(dst string) (err error)

Generate generates the API from openapi3.T schema.

func (*Generator) GetMethods

func (g *Generator) GetMethods() map[*Service]PathItemsMap

GetMethods gets services method from the parses openapi3.Tags.

func (*Generator) GetService

func (g *Generator) GetService() Services

GetService gets sorted openapi3.Tags, sorted by openapi3.Tag.Name.

func (*Generator) WriteAPI

func (g *Generator) WriteAPI(tag *Service)

WriteAPI writes child API service structs and New(Service) function.

func (*Generator) WriteConstants

func (g *Generator) WriteConstants()

WriteConstants writes constants.

func (*Generator) WriteDoc

func (g *Generator) WriteDoc()

WriteDoc writes package top level synopsis.

func (*Generator) WriteHeader

func (g *Generator) WriteHeader()

WriteHeader writes license and any file headers.

func (*Generator) WriteImports

func (g *Generator) WriteImports()

WriteImports writes import section.

func (*Generator) WriteMethods

func (g *Generator) WriteMethods(svcName string, service *Service)

WriteMethods writes child Service methods.

func (*Generator) WriteModel

func (g *Generator) WriteModel(modelName string, component *openapi3.SchemaRef, schemas openapi3.Schemas)

WriteModel writes model definitions.

func (*Generator) WritePackage

func (g *Generator) WritePackage()

WritePackage writes package statement.

func (*Generator) WriteSchemaDescriptor

func (g *Generator) WriteSchemaDescriptor()

WriteSchemaDescriptor writes base64 encoded, gzipped compressed and JSON marshaled schema spec into generated file.

func (*Generator) WriteService

func (g *Generator) WriteService()

WriteService writes API Service struct and New function.

type License

type License string

type PathItemsMap

type PathItemsMap map[string][]*openapi3.PathItem

PathItemsMap is the map of PathItems.

key:   path
value: []*openapi3.PathItem

type Service

type Service struct {
	Name string
	// contains filtered or unexported fields
}

type Services

type Services []*Service

Jump to

Keyboard shortcuts

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