MCPcopy Create free account
hub / github.com/goadesign/goa / ResultTypeRefWithPrefix

Function ResultTypeRefWithPrefix

http/codegen/openapi/json_schema.go:234–254  ·  view source on GitHub ↗

ResultTypeRefWithPrefix produces the JSON reference to the media type definition with the given view and adds the provided prefix to the type name

(api *expr.APIExpr, mt *expr.ResultTypeExpr, view, prefix string)

Source from the content-addressed store, hash-verified

232// ResultTypeRefWithPrefix produces the JSON reference to the media type definition with
233// the given view and adds the provided prefix to the type name
234func ResultTypeRefWithPrefix(api *expr.APIExpr, mt *expr.ResultTypeExpr, view, prefix string) string {
235 projected, err := expr.Project(mt, view)
236 if err != nil {
237 panic(fmt.Sprintf("failed to project media type %#v: %s", mt.Identifier, err)) // bug
238 }
239 var metaName string
240 if n, ok := mt.Meta["openapi:typename"]; ok {
241 metaName = codegen.Goify(n[0], true)
242 }
243 if metaName != "" {
244 projected.TypeName = metaName
245 }
246 if _, ok := Definitions[projected.TypeName]; !ok {
247 projected.TypeName = codegen.Goify(prefix, true) + codegen.Goify(projected.TypeName, true)
248 if metaName != "" {
249 projected.TypeName = metaName
250 }
251 GenerateResultTypeDefinition(api, projected, expr.DefaultView)
252 }
253 return fmt.Sprintf("#/$defs/%s", projected.TypeName)
254}
255
256// TypeRef produces the JSON reference to the type definition.
257func TypeRef(api *expr.APIExpr, ut *expr.UserTypeExpr) string {

Callers 3

responseSpecFromExprFunction · 0.92
ResultTypeRefFunction · 0.85
TypeSchemaWithPrefixFunction · 0.85

Calls 3

ProjectFunction · 0.92
GoifyFunction · 0.92

Tested by

no test coverage detected