Documentation ¶
Index ¶
- Variables
- func CleanupServiceFileStructure(servicePath string) error
- func CopyDirectory(src, dest string) error
- func CopyFile(srcPath, destPath string) error
- func ExtractZip(zipReader *zip.Reader, targetDir string, onlyPrefixes []string) error
- func GenerateContentArray(schema *openapi.Schema, valueReplacer replacers.ValueReplacer, ...) any
- func GenerateContentFromFileProperties(filePath, contentType string, valueReplacer replacers.ValueReplacer) []byte
- func GenerateContentFromSchema(schema *openapi.Schema, valueReplacer replacers.ValueReplacer, ...) any
- func GenerateContentObject(schema *openapi.Schema, valueReplacer replacers.ValueReplacer, ...) any
- func GenerateQuery(valueReplacer replacers.ValueReplacer, params openapi.Parameters) string
- func GenerateRequestHeaders(parameters openapi.Parameters, valueReplacer replacers.ValueReplacer) map[string]any
- func GenerateResponseHeaders(headers openapi.Headers, valueReplacer replacers.ValueReplacer) http.Header
- func GenerateURLFromSchemaParameters(path string, valueResolver replacers.ValueReplacer, params openapi.Parameters) string
- func GetFileContentsFromURL(client *http.Client, url string) ([]byte, string, error)
- func GetFileHash(file io.Reader) string
- func IsEmptyDir(path string) bool
- func IsJsonType(content []byte) bool
- func IsYamlType(content []byte) bool
- func NewCacheOperationAdapter(service string, operation openapi.Operation, storage CacheStorage) openapi.Operation
- func NewDocumentFromFileFactory(provider config.SchemaProvider) func(filePath string) (openapi.Document, error)
- func NewOpenAPIValidator(doc openapi.Document) openapi.Validator
- func NewRequestFromFixedResource(path, method, contentType string, valueReplacer replacers.ValueReplacer) *openapi.GeneratedRequest
- func NewRequestFromOperation(pathPrefix, path, method string, operation openapi.Operation, ...) *openapi.GeneratedRequest
- func NewResponseFromFixedResource(filePath, contentType string, valueReplacer replacers.ValueReplacer) *openapi.GeneratedResponse
- func NewResponseFromOperation(req *http.Request, operation openapi.Operation, ...) *openapi.GeneratedResponse
- func SaveFile(filePath string, data []byte) error
- type CacheOperationAdapter
- func (a *CacheOperationAdapter) GetParameters() openapi.Parameters
- func (a *CacheOperationAdapter) GetRequestBody() (*openapi.Schema, string)
- func (a *CacheOperationAdapter) GetResponse() *openapi.Response
- func (a *CacheOperationAdapter) ID() string
- func (a *CacheOperationAdapter) WithParseConfig(parseConfig *config.ParseConfig) openapi.Operation
- type CacheStorage
- type FileProperties
- type MemoryStorage
- type SchemaWithContentType
- type UploadedFile
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func CleanupServiceFileStructure ¶
CleanupServiceFileStructure removes empty directories from the service directory.
func CopyDirectory ¶
CopyDirectory copies a directory recursively.
func CopyFile ¶
CopyFile copies a file from srcPath to destPath. If the destination directory doesn't exist, it will be created.
func ExtractZip ¶
ExtractZip extracts a zip archive to a target directory. onlyPrefixes is a list of prefixes that are allowed to be extracted.
func GenerateContentArray ¶
func GenerateContentArray(schema *openapi.Schema, valueReplacer replacers.ValueReplacer, state *replacers.ReplaceState) any
GenerateContentArray generates content from the given schema with type `array`.
func GenerateContentFromFileProperties ¶ added in v0.1.19
func GenerateContentFromFileProperties(filePath, contentType string, valueReplacer replacers.ValueReplacer) []byte
func GenerateContentFromSchema ¶
func GenerateContentFromSchema(schema *openapi.Schema, valueReplacer replacers.ValueReplacer, state *replacers.ReplaceState) any
GenerateContentFromSchema generates content from the given schema.
func GenerateContentObject ¶
func GenerateContentObject(schema *openapi.Schema, valueReplacer replacers.ValueReplacer, state *replacers.ReplaceState) any
GenerateContentObject generates content from the given schema with type `object`.
func GenerateQuery ¶
func GenerateQuery(valueReplacer replacers.ValueReplacer, params openapi.Parameters) string
GenerateQuery generates query string from the given parameters.
func GenerateRequestHeaders ¶
func GenerateRequestHeaders(parameters openapi.Parameters, valueReplacer replacers.ValueReplacer) map[string]any
GenerateRequestHeaders generates GeneratedRequest headers from the given parameters.
func GenerateResponseHeaders ¶
func GenerateResponseHeaders(headers openapi.Headers, valueReplacer replacers.ValueReplacer) http.Header
GenerateResponseHeaders generates response headers from the given headers.
func GenerateURLFromSchemaParameters ¶
func GenerateURLFromSchemaParameters(path string, valueResolver replacers.ValueReplacer, params openapi.Parameters) string
GenerateURLFromSchemaParameters generates URL from the given path and parameters.
func GetFileContentsFromURL ¶ added in v0.1.5
func GetFileHash ¶
GetFileHash gets the SHA256 hash of a file.
func IsJsonType ¶
IsJsonType checks if the content is a valid JSON document.
func IsYamlType ¶
IsYamlType checks if the content is a valid YAML document.
func NewCacheOperationAdapter ¶
func NewCacheOperationAdapter(service string, operation openapi.Operation, storage CacheStorage) openapi.Operation
NewCacheOperationAdapter creates a new CacheOperationAdapter instance.
func NewDocumentFromFileFactory ¶
func NewDocumentFromFileFactory(provider config.SchemaProvider) func(filePath string) (openapi.Document, error)
NewDocumentFromFileFactory returns a function that creates a new Document from a file.
func NewOpenAPIValidator ¶ added in v0.1.18
NewOpenAPIValidator returns a new Validator based on the Document provider.
func NewRequestFromFixedResource ¶ added in v0.1.19
func NewRequestFromFixedResource(path, method, contentType string, valueReplacer replacers.ValueReplacer) *openapi.GeneratedRequest
func NewRequestFromOperation ¶
func NewRequestFromOperation(pathPrefix, path, method string, operation openapi.Operation, valueReplacer replacers.ValueReplacer) *openapi.GeneratedRequest
NewRequestFromOperation creates a new GeneratedRequest from an Operation. It used to pre-generate payloads from the UI or provide service to generate such. It's not part of OpenAPI endpoint handler.
func NewResponseFromFixedResource ¶ added in v0.1.19
func NewResponseFromFixedResource(filePath, contentType string, valueReplacer replacers.ValueReplacer) *openapi.GeneratedResponse
func NewResponseFromOperation ¶
func NewResponseFromOperation(req *http.Request, operation openapi.Operation, valueReplacer replacers.ValueReplacer) *openapi.GeneratedResponse
NewResponseFromOperation creates a new response from an Operation. It used to pre-generate payloads from the UI or provide service to generate such.
Types ¶
type CacheOperationAdapter ¶
type CacheOperationAdapter struct {
// contains filtered or unexported fields
}
CacheOperationAdapter is an adapter that caches the result of the wrapped Operation. Implements Operation interface.
func (*CacheOperationAdapter) GetParameters ¶
func (a *CacheOperationAdapter) GetParameters() openapi.Parameters
GetParameters returns the parameters for the Operation.
func (*CacheOperationAdapter) GetRequestBody ¶
func (a *CacheOperationAdapter) GetRequestBody() (*openapi.Schema, string)
GetRequestBody returns the GeneratedRequest body for the Operation.
func (*CacheOperationAdapter) GetResponse ¶
func (a *CacheOperationAdapter) GetResponse() *openapi.Response
GetResponse returns the response for the Operation.
func (*CacheOperationAdapter) ID ¶
func (a *CacheOperationAdapter) ID() string
ID returns the ID of the Operation.
func (*CacheOperationAdapter) WithParseConfig ¶
func (a *CacheOperationAdapter) WithParseConfig(parseConfig *config.ParseConfig) openapi.Operation
WithParseConfig sets the ParseConfig for the Operation.
type CacheStorage ¶
CacheStorage is an interface that describes a cache storage.
type FileProperties ¶
type FileProperties struct { // ServiceName is the name of the service that the file belongs to. // It represents the first directory in the file path. ServiceName string // IsOpenAPI indicates whether the file is an OpenAPI specification. IsOpenAPI bool // Method is the HTTP method of the resource, which this file describes. Method string // Prefix is the path prefix of the resource, which this file describes. // This is service name with a leading slash. Prefix string // Resource is the path of the resource, which this file describes without prefix. Resource string // FilePath is the full path to the file. FilePath string // FileName is the name of the file with the extension. FileName string // Extension is the extension of the file, with the leading dot. Extension string // ContentType is the MIME type of the file. ContentType string // Spec is the OpenAPI specification of the file if the file iis an OpenAPI specification. Spec openapi.Document `json:"-"` }
FileProperties contains inferred properties of a file that is being loaded from service directory.
func GetPropertiesFromFilePath ¶
func GetPropertiesFromFilePath(filePath string, appCfg *config.AppConfig) (*FileProperties, error)
GetPropertiesFromFilePath gets properties of a file from its path.
func (*FileProperties) IsEqual ¶
func (f *FileProperties) IsEqual(other *FileProperties) bool
IsEqual compares two FileProperties structs. Spec is not compared.
type MemoryStorage ¶
type MemoryStorage struct {
// contains filtered or unexported fields
}
MemoryStorage is a cache storage that stores data in memory.
func NewMemoryStorage ¶
func NewMemoryStorage() *MemoryStorage
NewMemoryStorage creates a new MemoryStorage instance.
type SchemaWithContentType ¶
SchemaWithContentType is a schema with a content type. It is used to cache the result of GetRequestBody and wrap 2 values together.
type UploadedFile ¶
type UploadedFile struct { // Content is the content of the file. Content []byte // Filename is the name of the file. Filename string // Extension is the extension of the file with the leading dot. Extension string // Size is the size of the file in bytes. Size int64 }
UploadedFile represents an uploaded file.
func GetRequestFile ¶
func GetRequestFile(r *http.Request, fieldName string) (*UploadedFile, error)
GetRequestFile gets an uploaded file from a GeneratedRequest.