Documentation ¶
Overview ¶
Package oapigen provides automatically generates Go API client based on OpenAPI schema.
Index ¶
- Constants
- func Depunct(ident string, needCap bool) string
- func FixName(name string) (should string)
- func IsDigit(c byte) bool
- func IsVowel(r rune) bool
- func NormalizeParam(param string) string
- func SortedMapKeys(v interface{}) []string
- type Generator
- func (g *Generator) Generate(dst string) (err error)
- func (g *Generator) GetMethods() map[*Service]PathItemsMap
- func (g *Generator) GetService() Services
- func (g *Generator) WriteAPI(tag *Service)
- func (g *Generator) WriteConstants()
- func (g *Generator) WriteDoc()
- func (g *Generator) WriteHeader()
- func (g *Generator) WriteImports()
- func (g *Generator) WriteMethods(svcName string, service *Service)
- func (g *Generator) WriteModel(modelName string, component *openapi3.SchemaRef, schemas openapi3.Schemas)
- func (g *Generator) WritePackage()
- func (g *Generator) WriteSchemaDescriptor()
- func (g *Generator) WriteService()
- type License
- type PathItemsMap
- type Service
- type Services
Constants ¶
const ( SchemaNameSwagger = "swagger" SchemaNameOpenAPI = "openapi" )
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.`)
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.`)
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.`)
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 ¶
Depunct removes '-', '.', '$', '/', '_' from identifers, making the following character uppercase. Multiple '_' are preserved.
func FixName ¶
FixName returns a fixed name based by Go naming idiom.
ported from golang.org/x/lint/lint.go
func NormalizeParam ¶
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 (*Generator) GetMethods ¶
func (g *Generator) GetMethods() map[*Service]PathItemsMap
GetMethods gets services method from the parses openapi3.Tags.
func (*Generator) GetService ¶
GetService gets sorted openapi3.Tags, sorted by openapi3.Tag.Name.
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 ¶
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.