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)
| 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 |
| 234 | func 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. |
| 257 | func TypeRef(api *expr.APIExpr, ut *expr.UserTypeExpr) string { |
no test coverage detected