forked from getkin/kin-openapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenapi3gen.txt
More file actions
102 lines (72 loc) · 3.85 KB
/
Copy pathopenapi3gen.txt
File metadata and controls
102 lines (72 loc) · 3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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 FieldNameGenerator func(field reflect.StructField, defaultName string) string
FieldNameGenerator allows client to set custom name for struct fields in
the generated schema. defaultName is the name, determined by generator's
standard JSON, YAML and Go field name resolution rules. Useful for
processing custom binding tags, such as `form` or `xml`. Function should
always return non-empty string.
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 CreateFieldNameGenerator(fngnrt FieldNameGenerator) Option
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