Skip to content

Commit

Permalink
🎨 Fixed golint issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
kaynetik committed Feb 4, 2021
1 parent 0d8acce commit 1bce9dc
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

![GolangCI](https://github.com/go-oas/docs/workflows/golangci/badge.svg?branch=main)
![Build](https://github.com/go-oas/docs/workflows/Build/badge.svg?branch=main)
[![Version](https://img.shields.io/badge/version-v1.0.3-success.svg)](https://github.com/go-oas/docs/releases)
[![Version](https://img.shields.io/badge/version-v1.0.4-success.svg)](https://github.com/go-oas/docs/releases)
[![Go Report Card](https://goreportcard.com/badge/github.com/go-oas/docs)](https://goreportcard.com/report/github.com/go-oas/docs)
[![Coverage Status](https://coveralls.io/repos/github/go-oas/docs/badge.svg?branch=main)](https://coveralls.io/github/go-oas/docs?branch=main)
[![codebeat badge](https://codebeat.co/badges/32b86556-84e3-4db9-9f11-923d12994f90)](https://codebeat.co/projects/github-com-go-oas-docs-main)
Expand Down
2 changes: 1 addition & 1 deletion annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (o *OAS) mapDocAnnotations(path string) error {
}

func mapIfLineContainsOASTag(lineText string, o *OAS) {
if strings.Contains(lineText, OASAnnotationInit) {
if strings.Contains(lineText, oasAnnotationInit) {
annotations := oasAnnotations(strings.Fields(lineText))

var newRoute Path
Expand Down
1 change: 1 addition & 0 deletions caller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
// routePostfix will get exported by v1.3.
const routePostfix = "Route"

// Call is used init registered functions that already exist in the *OAS, and return results if there are any.
func (o *OAS) Call(name string, params ...interface{}) (result []reflect.Value) {
f := reflect.ValueOf(o.RegisteredRoutes[name])

Expand Down
53 changes: 49 additions & 4 deletions models.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package docs

// WARNING:
// Most structures in here are an representation of what is defined in default
// Open API Specification documentation, v3.0.3.
//
// [More about it can be found on this link](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md)

// New returns a new instance of OAS structure.
func New() OAS {
initRoutes := RegRoutes{}

Expand All @@ -9,7 +16,7 @@ func New() OAS {
}

const (
OASAnnotationInit = "// @OAS "
oasAnnotationInit = "// @OAS "
)

// OAS - represents Open API Specification structure, in its approximated Go form.
Expand All @@ -24,13 +31,18 @@ type OAS struct {
RegisteredRoutes RegRoutes `yaml:"-"`
}

// Version is represented in SemVer format.
type (
Version string
URL string
// Version represents a SemVer version.
Version string

// URL represents and URL which is casted from string.
URL string

// OASVersion represents the OpenAPISpecification version which will be used.
OASVersion Version
)

// Info represents OAS info object.
type Info struct {
Title string `yaml:"title"`
Description string `yaml:"description"`
Expand All @@ -40,36 +52,47 @@ type Info struct {
Version Version `yaml:"version"`
}

// Contact represents OAS contact object, used by Info.
type Contact struct {
Email string `yaml:"email"`
}

// License represents OAS license object, used by Info.
type License struct {
Name string `yaml:"name"`
URL URL `yaml:"url"`
}

// ExternalDocs represents OAS externalDocs object.
//
// Aside from base OAS structure, this is also used by Tag object.
type ExternalDocs struct {
Description string `yaml:"description"`
URL URL `yaml:"url"`
}

// Servers is a slice of Server objects.
type Servers []Server

// Server represents OAS server object.
type Server struct {
URL URL `yaml:"url"`
}

// Tags is a slice of Tag objects.
type Tags []Tag

// Tag represents OAS tag object.
type Tag struct {
Name string `yaml:"name"`
Description string `yaml:"description"`
ExternalDocs ExternalDocs `yaml:"externalDocs"`
}

// Paths is a slice of Path objects.
type Paths []Path

// Path represents OAS path object.
type Path struct {
Route string `yaml:"route"`
HTTPMethod string `yaml:"httpMethod"`
Expand All @@ -82,43 +105,54 @@ type Path struct {
HandlerFuncName string `yaml:"-"`
}

// RequestBody represents OAS requestBody object, used by Path.
type RequestBody struct {
Description string `yaml:"description"`
Content ContentTypes `yaml:"content"`
Required bool `yaml:"required"`
}

// ContentTypes is a slice of ContentType objects.
type ContentTypes []ContentType

// ContentType represents OAS content type object, used by RequestBody and Response.
type ContentType struct {
Name string `yaml:"ct-name"` // e.g. application/json
Schema string `yaml:"ct-schema"` // e.g. $ref: '#/components/schemas/Pet'
}

// Responses is a slice of Response objects.
type Responses []Response

// Response represents OAS response object, used by Path.
type Response struct {
Code uint `yaml:"code"`
Description string `yaml:"description"`
Content ContentTypes `yaml:"content"`
}

// SecurityEntities is a slice of Security objects.
type SecurityEntities []Security

// Security represents OAS security object.
type Security struct {
AuthName string
PermTypes []string // write:pets , read:pets etc.
}

// Components is a slice of Component objects.
type Components []Component

// Component represents OAS component object.
type Component struct {
Schemas Schemas `yaml:"schemas"`
SecuritySchemes SecuritySchemes `yaml:"securitySchemes"`
}

// Schemas is a slice of Schema objects.
type Schemas []Schema

// Schema represents OAS schema object, used by Component.
type Schema struct {
Name string
Type string
Expand All @@ -127,11 +161,15 @@ type Schema struct {
Ref string // $ref: '#/components/schemas/Pet' // TODO: Should this be omitted if empty?
}

// XMLEntry represents name of XML entry in Schema object.
type XMLEntry struct {
Name string
}

// SchemaProperties is a slice of SchemaProperty objects.
type SchemaProperties []SchemaProperty

// SchemaProperty represents OAS schema object, used by Schema.
type SchemaProperty struct {
Name string `yaml:"-"`
Type string // OAS3.0 data types - e.g. integer, boolean, string
Expand All @@ -141,30 +179,37 @@ type SchemaProperty struct {
Default interface{} `yaml:"default,omitempty"`
}

// SecuritySchemes is a slice of SecuritySchemes objects.
type SecuritySchemes []SecurityScheme

// SecurityScheme represents OAS security object, used by Component.
type SecurityScheme struct {
Name string `yaml:"name,omitempty"`
Type string `yaml:"type,omitempty"`
In string `yaml:"in,omitempty"`
Flows SecurityFlows `yaml:"flows,omitempty"`
}

// SecurityFlows is a slice of SecurityFlow objects.
type SecurityFlows []SecurityFlow

// SecurityFlow represents OAS Flows object, used by SecurityScheme.
type SecurityFlow struct {
Type string `yaml:"type,omitempty"`
AuthURL URL `yaml:"authorizationUrl,omitempty"`
Scopes SecurityScopes `yaml:"scopes,omitempty"`
}

// SecurityScopes is a slice of SecurityScope objects.
type SecurityScopes []SecurityScope

// SecurityScope represents OAS SecurityScope object, used by SecurityFlow.
type SecurityScope struct {
Name string `yaml:"name,omitempty"`
Description string `yaml:"description,omitempty"`
}

// isEmpty checks if *ExternalDocs struct is empty.
func (ed *ExternalDocs) isEmpty() bool {
if ed == nil {
return true
Expand Down
5 changes: 5 additions & 0 deletions routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ type (
RegRoutes map[string]RouteFn
)

// AttachRoutes if used for attaching pre-defined API documentation routes.
//
// fns param is a slice of functions that satisfy RouteFn signature.
func (o *OAS) AttachRoutes(fns []RouteFn) {
for _, fn := range fns {
fnDeclaration := runtime.FuncForPC(reflect.ValueOf(fn).Pointer()).Name()
Expand All @@ -26,10 +29,12 @@ func (o *OAS) AttachRoutes(fns []RouteFn) {
}
}

// GetRegisteredRoutes returns a map of registered RouteFn functions - in layman terms "routes".
func (o *OAS) GetRegisteredRoutes() RegRoutes {
return o.RegisteredRoutes
}

// GetPathByIndex returns ptr to Path structure, by its index in the parent struct of OAS.
func (o *OAS) GetPathByIndex(index int) *Path {
return &o.Paths[index]
}
2 changes: 2 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const (
sigContSleeperMilliseconds = 20
)

// ConfigSwaggerUI represents a structure which will be used to pass required configuration params to
// the ServeSwaggerUI func.
type ConfigSwaggerUI struct {
Route string
Port string
Expand Down
2 changes: 2 additions & 0 deletions setters.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func (i *Info) SetLicense(licType, url string) {
}
}

// SetTag is used to define a new tag based on input params, and append it to the slice of tags its being called from.
func (tt *Tags) SetTag(name, tagDescription string, extDocs ExternalDocs) {
var tag Tag

Expand All @@ -41,6 +42,7 @@ func (tt *Tags) SetTag(name, tagDescription string, extDocs ExternalDocs) {
tt.AppendTag(&tag)
}

// AppendTag is used to append an Tag to the slice of Tags its being called from.
func (tt *Tags) AppendTag(tag *Tag) {
*tt = append(*tt, *tag)
}

0 comments on commit 1bce9dc

Please sign in to comment.