Documentation
¶
Index ¶
- Variables
- func CompareSchemaValues(a, b *openapi3.Schema) (string, bool)
- func GetOpenApiComponentSchema(ref string) (*openapi3.SchemaRef, error)
- func GetOpenApiComponents() (*openapi3.Components, error)
- func GetOpenApiResource(resourcePath string) (*openapi3.PathItem, error)
- func GetOperationSummary(httpMethod, resourcePath string) (string, error)
- func GetQueryParameters(httpMethod, resourcePath string) ([]*openapi3.Parameter, error)
- func GetRequestBodySchema(httpMethod, resourcePath string) (*openapi3.SchemaRef, error)
- func GetResponseModelSchema(httpMethod, resourcePath string) (*openapi3.SchemaRef, error)
- func GetResponseModelSchemaUnresolved(httpMethod, resourcePath string) (*openapi3.SchemaRef, error)
- func GetSchemaFromComponent(componentName string) (*openapi3.SchemaRef, error)
- func GetSchemaType(s *openapi3.Schema) string
- func GetSchema_FromComponents(resourcePath string) (*openapi3.SchemaRef, error)
- func GetSchema_GET_QueryParams(resourcePath string) (*openapi3.SchemaRef, error)
- func IsAmbiguousObject(prop *openapi3.Schema) bool
- func IsDirectComponentReference(schemaRef *openapi3.SchemaRef) string
- func IsEmptySchema(ref *openapi3.SchemaRef) bool
- func IsObject(prop *openapi3.Schema) bool
- func IsPrimitive(prop *openapi3.Schema) bool
- func IsStringOrInteger(prop *openapi3.Schema) bool
- func ResolveAllRefs(ref *openapi3.SchemaRef) *openapi3.Schema
- func ResolveComposedSchema(schema *openapi3.Schema) *openapi3.Schema
- func Returns204NoContent(httpMethod, resourcePath string) (bool, error)
- func ReturnsTextPlain(httpMethod, resourcePath string) (bool, error)
- func SearchableQueryParams(resourcePath string) ([]string, error)
- func ValidateOperationExists(httpMethod, resourcePath string) error
- type ComponentSchema
- type DeleteParams
Constants ¶
This section is empty.
Variables ¶
var ( //go:embed api.tar.gz FS embed.FS )
Functions ¶
func CompareSchemaValues ¶ added in v0.104.0
CompareSchemaValues compares two OpenAPI schemas and returns a description of any differences. Returns an empty string and true if schemas match, or an error message and false if they differ.
func GetOpenApiComponents ¶
func GetOpenApiComponents() (*openapi3.Components, error)
func GetOperationSummary ¶
func GetQueryParameters ¶ added in v0.118.0
GetQueryParameters extracts all query parameters from the specified HTTP method operation of a given OpenAPI path item. It returns a slice of openapi3.Parameter objects whose "in" field is "query". These typically represent optional or required query string inputs accepted by the endpoint.
Parameters:
- httpMethod: HTTP method (GET, POST, PATCH, PUT, DELETE, etc.)
- resourcePath: an OpenAPI path (e.g., "/users/")
Returns:
- []*openapi3.Parameter: a slice of query parameter definitions.
- error: if the resource cannot be retrieved.
func GetRequestBodySchema ¶
GetRequestBodySchema extracts the request body schema for a given HTTP method and resource path. It supports POST, PATCH, PUT, and DELETE methods.
Parameters:
- httpMethod: HTTP method (e.g., "POST", "PATCH", "PUT", "DELETE")
- resourcePath: The API resource path (e.g., "apitokens")
Returns:
- *openapi3.SchemaRef: The request body schema, or an empty schema if not found
- error: If the resource cannot be loaded or the method is not supported
Example:
schema, err := GetRequestBodySchema("POST", "apitokens")
func GetResponseModelSchema ¶
GetResponseModelSchema extracts the response model schema for a given HTTP method and resource path. It checks for successful status codes (200, 201, 202, 204) and returns the schema from the response body.
Parameters:
- httpMethod: HTTP method (e.g., "GET", "POST", "PATCH", "PUT", "DELETE")
- resourcePath: The API resource path (e.g., "apitokens")
Returns:
- *openapi3.SchemaRef: The response model schema (empty schema for 204 No Content responses)
- error: If the resource cannot be loaded, the method is not supported, or no valid schema is found
Example:
schema, err := GetResponseModelSchema("GET", "apitokens")
Notes:
- For GET requests, it automatically handles paginated responses, arrays, and single objects
- For other methods, it checks status codes 200, 201, 202 for content, and 204 for No Content
- 204 No Content responses return an empty schema since there's no response body
func GetResponseModelSchemaUnresolved ¶
GetResponseModelSchemaUnresolved extracts the RAW response model schema (BEFORE resolving $refs) This is useful for detecting if the schema is a direct component reference
func GetSchemaFromComponent ¶
GetSchemaFromComponent retrieves a schema by component name (e.g., "ActiveDirectory") Returns the RESOLVED schema (after resolving refs and compositions)
func GetSchemaType ¶ added in v0.104.0
GetSchemaType returns the type string of the given OpenAPI schema
func GetSchema_FromComponents ¶
GetSchema_FromComponents retrieves a schema from the OpenAPI components section based on the provided resource path. It extracts the last part of the path as the component
func GetSchema_GET_QueryParams ¶
GetSchema_GET_QueryParams converts query parameters from a GET operation into a SchemaRef. It creates an object schema where each query parameter becomes a property. The schema includes parameter names, types, descriptions, and required status.
Parameters:
- resourcePath: the OpenAPI path to extract query parameters from.
Returns:
- *openapi3.SchemaRef: a schema representing all query parameters as an object.
- error: if the resource cannot be found or parameters cannot be processed.
func IsAmbiguousObject ¶ added in v0.104.0
IsAmbiguousObject returns true if the schema is an object with no properties and no additionalProperties. Objects with additionalProperties (like maps) are valid and should not be considered ambiguous.
func IsDirectComponentReference ¶
IsDirectComponentReference checks if a SchemaRef is a direct $ref to a component (not inline, not composed with allOf/oneOf/anyOf) Returns the component name if it's a direct reference, empty string otherwise
func IsEmptySchema ¶ added in v0.104.0
IsEmptySchema returns true if the schema reference is nil or represents an empty schema
func IsObject ¶ added in v0.104.0
IsObject returns true if the given OpenAPI schema represents an object type
func IsPrimitive ¶ added in v0.104.0
IsPrimitive returns true if the given OpenAPI schema represents a primitive type (string, integer, number, or boolean).
func IsStringOrInteger ¶ added in v0.104.0
IsStringOrInteger returns true if the given OpenAPI schema represents string or integer
func ResolveAllRefs ¶ added in v0.104.0
ResolveAllRefs resolves all $ref references in an OpenAPI schema
func ResolveComposedSchema ¶ added in v0.104.0
ResolveComposedSchema resolves allOf/oneOf/anyOf compositions in an OpenAPI schema
func Returns204NoContent ¶
Returns204NoContent checks if an operation returns HTTP 204 No Content status
Parameters:
- httpMethod: HTTP method (GET, POST, PUT, PATCH, DELETE, etc.)
- resourcePath: API path (e.g., "/users/{id}/access_keys/")
Returns:
- bool: true if the operation returns 204 No Content, false otherwise
- error: if the OpenAPI document cannot be loaded or path/operation is not found
func ReturnsTextPlain ¶
ReturnsTextPlain checks if an operation returns text/plain content type
Parameters:
- httpMethod: HTTP method (GET, POST, PUT, PATCH, DELETE, etc.)
- resourcePath: API path (e.g., "/prometheusmetrics/")
Returns:
- bool: true if the operation returns text/plain, false otherwise
- error: if the OpenAPI document cannot be loaded or path/operation is not found
func SearchableQueryParams ¶
SearchableQueryParams returns only query parameters that are primitive types (string, integer) from the GET operation of the given resource path.
func ValidateOperationExists ¶
ValidateOperationExists checks if a specific HTTP method exists for a given path in the OpenAPI spec Returns an error if the path or method doesn't exist
Types ¶
type ComponentSchema ¶
type ComponentSchema struct {
Name string // e.g., "ActiveDirectory"
Reference string // e.g., "#/components/schemas/ActiveDirectory"
Schema *openapi3.Schema
}
ComponentSchema represents a component schema with its name and reference
func GetAllComponentSchemas ¶
func GetAllComponentSchemas() ([]ComponentSchema, error)
GetAllComponentSchemas retrieves all schemas from the OpenAPI components section
type DeleteParams ¶
type DeleteParams struct {
QueryParams []*openapi3.ParameterRef // Query parameters (excluding id in path)
BodySchema *openapi3.SchemaRef // Body schema if present
IdDescription string // Description of the id path parameter
}
GetOperationSummary returns the summary description for a specific HTTP method and resource path from the OpenAPI specification.
Parameters:
- httpMethod: HTTP method (GET, POST, PUT, PATCH, DELETE, etc.)
- resourcePath: API path (e.g., "/users/{id}/access_keys/")
Returns:
- string: The operation summary, or empty string if not found
- error: if the OpenAPI document cannot be loaded or path is not found
DeleteParams holds the DELETE operation parameters
func GetDeleteParams ¶
func GetDeleteParams(resourcePath string) (*DeleteParams, error)
GetDeleteParams extracts DELETE operation parameters (query params and body schema)