Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/codegen/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ type Schema struct {
GoType string // The Go type needed to represent the schema
RefType string // If the type has a type name, this is set

EnumValues []string // Enum values

Properties []Property // For an object, the fields with names
HasAdditionalProperties bool // Whether we support additional properties
AdditionalPropertiesType *Schema // And if we do, their type
Expand Down Expand Up @@ -248,6 +250,9 @@ func GenerateGoSchema(sref *openapi3.SchemaRef, path []string) (Schema, error) {
}
outSchema.GoType = "bool"
case "string":
for _, enumValue := range schema.Enum {
outSchema.EnumValues = append(outSchema.EnumValues, enumValue.(string))
}
// Special case string formats here.
switch f {
case "byte":
Expand Down
9 changes: 9 additions & 0 deletions pkg/codegen/templates/templates.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions pkg/codegen/templates/typedef.tmpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
{{range .Types}}
// {{.TypeName}} defines model for {{.JsonName}}.
type {{.TypeName}} {{.Schema.TypeDecl}}
{{- if gt (len .Schema.EnumValues) 0 }}
// List of {{ .TypeName }}
const (
{{- $typeName := .TypeName }}
{{- range .Schema.EnumValues }}
{{ $typeName }}_{{ . }} {{ $typeName }} = "{{ . }}"
{{- end }}
)
{{- end }}
{{end}}