parser

package
v0.0.0-...-f6830bd Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2014 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContentTypeJson  = "application/json"
	ContentTypeXml   = "application/xml"
	ContentTypePlain = "text/plain"
	ContentTypeHtml  = "text/html"
)
View Source
const SwaggerVersion = "1.2"

Variables

View Source
var CommentIsEmptyError = errors.New("Comment is empty")

Functions

func IsBasicType

func IsBasicType(typeName string) bool

func IsIgnoredPackage

func IsIgnoredPackage(packageName string) bool

func ParserFileFilter

func ParserFileFilter(info os.FileInfo) bool

Types

type Api

type Api struct {
	Path        string       `json:"path"` // relative or absolute, must start with /
	Description string       `json:"description"`
	Operations  []*Operation `json:"operations,omitempty"`
}

func NewApi

func NewApi() *Api

type ApiDeclaration

type ApiDeclaration struct {
	ApiVersion     string            `json:"apiVersion"`
	SwaggerVersion string            `json:"swaggerVersion"`
	BasePath       string            `json:"basePath"`
	ResourcePath   string            `json:"resourcePath"` // must start with /
	Consumes       []string          `json:"-"`
	Produces       []string          `json:"produces,omitempty"`
	Apis           []*Api            `json:"apis,omitempty"`
	Models         map[string]*Model `json:"models,omitempty"`
}

https://github.com/wordnik/swagger-core/blob/scala_2.10-1.3-RC3/schemas/api-declaration-schema.json

func NewApiDeclaration

func NewApiDeclaration() *ApiDeclaration

func (*ApiDeclaration) AddConsumedTypes

func (api *ApiDeclaration) AddConsumedTypes(op *Operation)

func (*ApiDeclaration) AddModels

func (api *ApiDeclaration) AddModels(op *Operation)

func (*ApiDeclaration) AddOperation

func (api *ApiDeclaration) AddOperation(op *Operation)

func (*ApiDeclaration) AddProducesTypes

func (api *ApiDeclaration) AddProducesTypes(op *Operation)

func (*ApiDeclaration) AddSubApi

func (api *ApiDeclaration) AddSubApi(op *Operation)

type ApiKey

type ApiKey struct {
	Type   string `json:"type"`   // e.g. apiKey
	PassAs string `json:"passAs"` // e.g. header
}

https://github.com/wordnik/swagger-core/wiki/authorizations

type ApiRef

type ApiRef struct {
	Path        string `json:"path"` // relative or absolute, must start with /
	Description string `json:"description"`
}

type Authorization

type Authorization struct {
	LocalOAuth OAuth  `json:"local-oauth"`
	ApiKey     ApiKey `json:"apiKey"`
}

https://github.com/wordnik/swagger-core/wiki/authorizations

type Endpoint

type Endpoint struct {
	Url              string `json:"url"`
	ClientIdName     string `json:"clientIdName"`
	ClientSecretName string `json:"clientSecretName"`
	TokenName        string `json:"tokenName"`
}

https://github.com/wordnik/swagger-core/wiki/authorizations

type ErrorResponse

type ErrorResponse struct {
	Code   int    `json:"code"`
	Reason string `json:"reason"`
}

type GrantType

type GrantType struct {
	LoginEndpoint        Endpoint `json:"loginEndpoint"`
	TokenName            string   `json:"tokenName"` // e.g. access_code
	TokenRequestEndpoint Endpoint `json:"tokenRequestEndpoint"`
	TokenEndpoint        Endpoint `json:"tokenEndpoint"`
}

https://github.com/wordnik/swagger-core/wiki/authorizations

type Infomation

type Infomation struct {
	Title             string `json:"title,omitempty"`
	Description       string `json:"description,omitempty"`
	Contact           string `json:"contact,omitempty"`
	TermsOfServiceUrl string `json:"termsOfServiceUrl,omitempty"`
	License           string `json:"license,omitempty"`
	LicenseUrl        string `json:"licenseUrl,omitempty"`
}

type Model

type Model struct {
	Id         string                    `json:"id"`
	Required   []string                  `json:"required,omitempty"`
	Properties map[string]*ModelProperty `json:"properties"`
	// contains filtered or unexported fields
}

func NewModel

func NewModel(p *Parser) *Model

func (*Model) ParseFieldList

func (m *Model) ParseFieldList(fieldList []*ast.Field, modelPackage string)

func (*Model) ParseModel

func (m *Model) ParseModel(modelName string, currentPackage string, knownModelNames map[string]bool) (error, []*Model)

modelName is something like package.subpackage.SomeModel or just "subpackage.SomeModel"

func (*Model) ParseModelProperty

func (m *Model) ParseModelProperty(field *ast.Field, modelPackage string)

type ModelProperty

type ModelProperty struct {
	Type        string             `json:"type"`
	Description string             `json:"description"`
	Items       ModelPropertyItems `json:"items,omitempty"`
	Format      string             `json:"format"`
}

func NewModelProperty

func NewModelProperty() *ModelProperty

func (*ModelProperty) GetTypeAsString

func (p *ModelProperty) GetTypeAsString(fieldType interface{}) string

func (*ModelProperty) SetItemType

func (p *ModelProperty) SetItemType(itemType string)

type ModelPropertyItems

type ModelPropertyItems struct {
	Ref  string `json:"$ref,omitempty"`
	Type string `json:"type,omitempty"`
}

type OAuth

type OAuth struct {
	Type       string               `json:"type"`   // e.g. oauth2
	Scopes     []string             `json:"scopes"` // e.g. PUBLIC
	GrantTypes map[string]GrantType `json:"grantTypes"`
}

https://github.com/wordnik/swagger-core/wiki/authorizations

type Operation

type Operation struct {
	HttpMethod       string            `json:"httpMethod"`
	Nickname         string            `json:"nickname"`
	Type             string            `json:"type"`
	Items            OperationItems    `json:"items,omitempty"`
	Summary          string            `json:"summary,omitempty"`
	Notes            string            `json:"notes,omitempty"`
	Parameters       []Parameter       `json:"parameters,omitempty"`
	ResponseMessages []ResponseMessage `json:"responseMessages,omitempty"`
	Consumes         []string          `json:"-"`
	Produces         []string          `json:"produces,omitempty"`
	Authorizations   []Authorization   `json:"authorizations,omitempty"`
	Protocols        []Protocol        `json:"protocols,omitempty"`
	Path             string            `json:"-"`
	ForceResource    string            `json:"-"`

	Models []*Model `json:"-"`
	// contains filtered or unexported fields
}

func NewOperation

func NewOperation(p *Parser, packageName string) *Operation

func (*Operation) ParseAcceptComment

func (operation *Operation) ParseAcceptComment(commentLine string) error

@Accept json

func (*Operation) ParseComment

func (operation *Operation) ParseComment(comment string) error

func (*Operation) ParseParamComment

func (operation *Operation) ParseParamComment(commentLine string) error

Parse params return []string of param properties @Param queryText form string true "The email for login"

[param name]    [param type] [data type]  [is mandatory?]   [Comment]

func (*Operation) ParseResponseComment

func (operation *Operation) ParseResponseComment(commentLine string) error

@Success 200 {object} model.OrderRow "Error message, if code != 200"

func (*Operation) ParseRouterComment

func (operation *Operation) ParseRouterComment(commentLine string) error

@Router /customer/get-wishlist/{wishlist_id} [get]

func (*Operation) SetItemsType

func (operation *Operation) SetItemsType(itemsType string)

type OperationItems

type OperationItems struct {
	Ref  string `json:"$ref,omitempty"`
	Type string `json:"type,omitempty"`
}

type Parameter

type Parameter struct {
	ParamType     string `json:"paramType"` // path,query,body,header,form
	Name          string `json:"name"`
	Description   string `json:"description"`
	DataType      string `json:"dataType"` // 1.2 needed?
	Type          string `json:"type"`     // integer
	Format        string `json:"format"`   // int64
	AllowMultiple bool   `json:"allowMultiple"`
	Required      bool   `json:"required"`
	Minimum       int    `json:"minimum"`
	Maximum       int    `json:"maximum"`
}

type Parser

type Parser struct {
	Listing                           *ResourceListing
	TopLevelApis                      map[string]*ApiDeclaration
	PackagesCache                     map[string]map[string]*ast.Package
	CurrentPackage                    string
	TypeDefinitions                   map[string]map[string]*ast.TypeSpec
	PackagePathCache                  map[string]string
	PackageImports                    map[string]map[string][]string
	BasePath                          string
	IsController                      func(*ast.FuncDecl) bool
	TypesImplementingMarshalInterface map[string]string
}

func NewParser

func NewParser() *Parser

func (*Parser) AddOperation

func (parser *Parser) AddOperation(op *Operation)

func (*Parser) CheckRealPackagePath

func (parser *Parser) CheckRealPackagePath(packagePath string) string

func (*Parser) FindModelDefinition

func (parser *Parser) FindModelDefinition(modelName string, currentPackage string) (*ast.TypeSpec, string)

func (*Parser) GetApiDescriptionJson

func (parser *Parser) GetApiDescriptionJson() []byte

func (*Parser) GetModelDefinition

func (parser *Parser) GetModelDefinition(model string, packageName string) *ast.TypeSpec

func (*Parser) GetPackageAst

func (parser *Parser) GetPackageAst(packagePath string) map[string]*ast.Package

func (*Parser) GetRealPackagePath

func (parser *Parser) GetRealPackagePath(packagePath string) string

func (*Parser) GetResourceListingJson

func (parser *Parser) GetResourceListingJson() []byte

func (*Parser) IsImplementMarshalInterface

func (parser *Parser) IsImplementMarshalInterface(typeName string) bool

func (*Parser) ParseApi

func (parser *Parser) ParseApi(packageNames string)

func (*Parser) ParseApiDescription

func (parser *Parser) ParseApiDescription(packageName string)

func (*Parser) ParseGeneralApiInfo

func (parser *Parser) ParseGeneralApiInfo(mainApiFile string)

Read web/main.go to get General info

func (*Parser) ParseImportStatements

func (parser *Parser) ParseImportStatements(packageName string) map[string]bool

func (*Parser) ParseSubApiDescription

func (parser *Parser) ParseSubApiDescription(commentLine string)

Parse sub api declaration @SubApi Very fancy API [/fancy-api]

func (*Parser) ParseTypeDefinitions

func (parser *Parser) ParseTypeDefinitions(packageName string)

func (*Parser) ScanPackages

func (parser *Parser) ScanPackages(packages []string) []string

type Protocol

type Protocol struct {
}

type ResourceListing

type ResourceListing struct {
	ApiVersion     string `json:"apiVersion"`
	SwaggerVersion string `json:"swaggerVersion"`
	//	BasePath       string     `json:"basePath"`
	Apis  []*ApiRef  `json:"apis"`
	Infos Infomation `json:"info"`
}

type ResponseMessage

type ResponseMessage struct {
	Code          int    `json:"code"`
	Message       string `json:"message"`
	ResponseModel string `json:"responseModel"`
}

Jump to

Keyboard shortcuts

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