openapi_schema

package
v0.138.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//go:embed api.tar.gz
	FS embed.FS
)

Functions

func CompareSchemaValues added in v0.104.0

func CompareSchemaValues(a, b *openapi3.Schema) (string, bool)

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 GetOpenApiComponentSchema

func GetOpenApiComponentSchema(ref string) (*openapi3.SchemaRef, error)

func GetOpenApiComponents

func GetOpenApiComponents() (*openapi3.Components, error)

func GetOpenApiResource

func GetOpenApiResource(resourcePath string) (*openapi3.PathItem, error)

func GetOperationSummary

func GetOperationSummary(httpMethod, resourcePath string) (string, error)

func GetQueryParameters added in v0.118.0

func GetQueryParameters(httpMethod, resourcePath string) ([]*openapi3.Parameter, error)

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

func GetRequestBodySchema(httpMethod, resourcePath string) (*openapi3.SchemaRef, error)

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

func GetResponseModelSchema(httpMethod, resourcePath string) (*openapi3.SchemaRef, error)

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

func GetResponseModelSchemaUnresolved(httpMethod, resourcePath string) (*openapi3.SchemaRef, error)

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

func GetSchemaFromComponent(componentName string) (*openapi3.SchemaRef, error)

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

func GetSchemaType(s *openapi3.Schema) string

GetSchemaType returns the type string of the given OpenAPI schema

func GetSchema_FromComponents

func GetSchema_FromComponents(resourcePath string) (*openapi3.SchemaRef, error)

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

func GetSchema_GET_QueryParams(resourcePath string) (*openapi3.SchemaRef, error)

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

func IsAmbiguousObject(prop *openapi3.Schema) bool

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

func IsDirectComponentReference(schemaRef *openapi3.SchemaRef) string

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

func IsEmptySchema(ref *openapi3.SchemaRef) bool

IsEmptySchema returns true if the schema reference is nil or represents an empty schema

func IsObject added in v0.104.0

func IsObject(prop *openapi3.Schema) bool

IsObject returns true if the given OpenAPI schema represents an object type

func IsPrimitive added in v0.104.0

func IsPrimitive(prop *openapi3.Schema) bool

IsPrimitive returns true if the given OpenAPI schema represents a primitive type (string, integer, number, or boolean).

func IsStringOrInteger added in v0.104.0

func IsStringOrInteger(prop *openapi3.Schema) bool

IsStringOrInteger returns true if the given OpenAPI schema represents string or integer

func ResolveAllRefs added in v0.104.0

func ResolveAllRefs(ref *openapi3.SchemaRef) *openapi3.Schema

ResolveAllRefs resolves all $ref references in an OpenAPI schema

func ResolveComposedSchema added in v0.104.0

func ResolveComposedSchema(schema *openapi3.Schema) *openapi3.Schema

ResolveComposedSchema resolves allOf/oneOf/anyOf compositions in an OpenAPI schema

func Returns204NoContent

func Returns204NoContent(httpMethod, resourcePath string) (bool, error)

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

func ReturnsTextPlain(httpMethod, resourcePath string) (bool, error)

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

func SearchableQueryParams(resourcePath string) ([]string, error)

SearchableQueryParams returns only query parameters that are primitive types (string, integer) from the GET operation of the given resource path.

func ValidateOperationExists

func ValidateOperationExists(httpMethod, resourcePath string) error

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)

Jump to

Keyboard shortcuts

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