@@ -38,7 +38,8 @@ import (
3838
3939const (
4040 // defPrefix is the prefix used to link to definitions in the OpenAPI schema.
41- defPrefix = "#/definitions/"
41+ defPrefix = "#/definitions/"
42+ typeString = "string"
4243)
4344
4445// byteType is the types.Type for byte (see the types documention
@@ -128,9 +129,9 @@ func infoToSchema(ctx *schemaContext) *apiext.JSONSchemaProps {
128129
129130 // If the obj implements a text marshaler, encode it as a string.
130131 case implements (obj .Type (), textMarshaler ):
131- schema := & apiext.JSONSchemaProps {Type : "string" }
132+ schema := & apiext.JSONSchemaProps {Type : typeString }
132133 applyMarkers (ctx , ctx .info .Markers , schema , ctx .info .RawSpec .Type )
133- if schema .Type != "string" {
134+ if schema .Type != typeString {
134135 err := fmt .Errorf ("%q implements encoding.TextMarshaler but schema type is not string: %q" , ctx .info .RawSpec .Name , schema .Type )
135136 ctx .pkg .AddError (loader .ErrFromNode (err , ctx .info .RawSpec .Type ))
136137 }
@@ -277,7 +278,7 @@ func localNamedToSchema(ctx *schemaContext, ident *ast.Ident) *apiext.JSONSchema
277278 ctx .pkg .AddError (loader .ErrFromNode (err , ident ))
278279 }
279280 var enumMembers []apiext.JSON
280- if ctx .info .Markers .Get ("enum" ) != nil && typ == "string" {
281+ if ctx .info .Markers .Get ("enum" ) != nil && typ == typeString {
281282 enumMembers = make ([]apiext.JSON , 0 , len (ctx .info .EnumValues ))
282283 var ok bool
283284 for i := range ctx .info .EnumValues {
@@ -361,7 +362,7 @@ func arrayToSchema(ctx *schemaContext, array *ast.ArrayType) *apiext.JSONSchemaP
361362 // byte slices are represented as base64-encoded strings
362363 // (the format is defined in OpenAPI v3, but not JSON Schema)
363364 return & apiext.JSONSchemaProps {
364- Type : "string" ,
365+ Type : typeString ,
365366 Format : "byte" ,
366367 }
367368 }
@@ -529,7 +530,7 @@ func builtinToType(basic *types.Basic, allowDangerousTypes bool) (typ string, fo
529530 case basicInfo & types .IsBoolean != 0 :
530531 typ = "boolean"
531532 case basicInfo & types .IsString != 0 :
532- typ = "string"
533+ typ = typeString
533534 case basicInfo & types .IsInteger != 0 :
534535 typ = "integer"
535536 case basicInfo & types .IsFloat != 0 :
0 commit comments