MCPcopy Index your code
hub / github.com/APIParkLab/APIPark / ExportSwagger

Method ExportSwagger

controller/service/iml.go:414–451  ·  view source on GitHub ↗
(ctx *gin.Context)

Source from the content-addressed store, hash-verified

412}
413
414func (i *imlServiceController) ExportSwagger(ctx *gin.Context) {
415 id, has := ctx.Params.Get("id")
416 if !has {
417 ctx.JSON(200, &pm3.Response{
418 Code: -1,
419 Success: "fail",
420 Message: fmt.Sprintf("id is required"),
421 })
422 return
423 }
424 s, err := i.module.Get(ctx, id)
425 if err != nil {
426 ctx.JSON(200, &pm3.Response{
427 Code: -1,
428 Success: "fail",
429 Message: err.Error(),
430 })
431 return
432 }
433 tmp, err := i.swagger(ctx, id)
434 if err != nil {
435 ctx.JSON(200, &pm3.Response{
436 Code: -1,
437 Success: "fail",
438 Message: err.Error(),
439 })
440 return
441 }
442
443 data, _ := tmp.MarshalJSON()
444 ctx.Status(200)
445 // 设置响应头
446 ctx.Header("Content-Disposition", fmt.Sprintf("attachment; filename=%s.json", strings.Replace(s.Name, " ", "_", -1)))
447 ctx.Header("Content-Type", "application/octet-stream")
448 ctx.Header("Content-Transfer-Encoding", "binary")
449 ctx.Writer.Write(data)
450 return
451}
452
453func (i *imlServiceController) Swagger(ctx *gin.Context) {
454 id, has := ctx.Params.Get("id")

Callers

nothing calls this directly

Calls 5

swaggerMethod · 0.95
HeaderMethod · 0.80
WriteMethod · 0.80
GetMethod · 0.65
MarshalJSONMethod · 0.45

Tested by

no test coverage detected