package openapi3gen // import "github.com/getkin/kin-openapi/openapi3gen"

Package openapi3gen generates OpenAPIv3 JSON schemas from Go types.

VARIABLES

var RefSchemaRef = openapi3.NewSchemaRef("Ref",
	openapi3.NewObjectSchema().WithProperty("$ref", openapi3.NewStringSchema().WithMinLength(1)))

FUNCTIONS

func NewSchemaRefForValue(value any, schemas openapi3.Schemas, opts ...Option) (*openapi3.SchemaRef, error)
    NewSchemaRefForValue is a shortcut for
    NewGenerator(...).NewSchemaRefForValue(...)


TYPES

type CycleError struct{}
    CycleError indicates that a type graph has one or more possible cycles.

func (err *CycleError) Error() string

type ExcludeSchemaSentinel struct{}
    ExcludeSchemaSentinel indicates that the schema for a specific field should
    not be included in the final output.

func (err *ExcludeSchemaSentinel) Error() string

type ExportComponentSchemasOptions struct {
	ExportComponentSchemas bool
	ExportTopLevelSchema   bool
	ExportGenerics         bool
}

type Generator struct {
	Types map[reflect.Type]*openapi3.SchemaRef

	// SchemaRefs contains all references and their counts.
	// If count is 1, it's not ne
	// An OpenAPI identifier has been assigned to each.
	SchemaRefs map[*openapi3.SchemaRef]int

	// Has unexported fields.
}

func NewGenerator(opts ...Option) *Generator

func (g *Generator) GenerateSchemaRef(t reflect.Type) (*openapi3.SchemaRef, error)

func (g *Generator) NewSchemaRefForValue(value any, schemas openapi3.Schemas) (*openapi3.SchemaRef, error)
    NewSchemaRefForValue uses reflection on the given value to produce a
    SchemaRef, and updates a supplied map with any dependent component schemas
    if they lead to cycles

type Option func(*generatorOpt)
    Option allows tweaking SchemaRef generation

func CreateComponentSchemas(exso ExportComponentSchemasOptions) Option
    CreateComponents changes the default behavior to add all schemas as
    components Reduces duplicate schemas in routes

func CreateTypeNameGenerator(tngnrt TypeNameGenerator) Option

func SchemaCustomizer(sc SchemaCustomizerFn) Option
    SchemaCustomizer allows customization of the schema that is generated for a
    field, for example to support an additional tagging scheme

func ThrowErrorOnCycle() Option
    ThrowErrorOnCycle changes the default behavior of creating cycle refs to
    instead error if a cycle is detected.

func UseAllExportedFields() Option
    UseAllExportedFields changes the default behavior of only generating schemas
    for struct fields with a JSON tag.

type SchemaCustomizerFn func(name string, t reflect.Type, tag reflect.StructTag, schema *openapi3.Schema) error
    SchemaCustomizerFn is a callback function, allowing the OpenAPI schema
    definition to be updated with additional properties during the generation
    process, based on the name of the field, the Go type, and the struct tags.
    name will be "_root" for the top level object, and tag will be "".
    A SchemaCustomizerFn can return an ExcludeSchemaSentinel error to indicate
    that the schema for this field should not be included in the final output

type SetSchemar interface {
	SetSchema(*openapi3.Schema)
}
    SetSchemar allows client to set their own schema definition according to
    their specification. Useful when some custom datatype is needed and/or some
    custom logic is needed on how the schema values would be generated

type TypeNameGenerator func(t reflect.Type) string

