MCPcopy
hub / github.com/apache/devlake / GenerateOpenApiSpec

Function GenerateOpenApiSpec

backend/server/services/remote/plugin/doc/open_api.go:34–63  ·  view source on GitHub ↗
(pluginInfo *models.PluginInfo)

Source from the content-addressed store, hash-verified

32)
33
34func GenerateOpenApiSpec(pluginInfo *models.PluginInfo) (*string, errors.Error) {
35 connectionSchema, err := json.Marshal(pluginInfo.ConnectionModelInfo.JsonSchema)
36 if err != nil {
37 return nil, errors.Default.Wrap(err, "connection schema is not valid JSON")
38 }
39 scopeSchema, err := json.Marshal(pluginInfo.ScopeModelInfo.JsonSchema)
40 if err != nil {
41 return nil, errors.Default.Wrap(err, "scope schema is not valid JSON")
42 }
43 scopeConfigSchema, err := json.Marshal(pluginInfo.ScopeConfigModelInfo.JsonSchema)
44 if err != nil {
45 return nil, errors.Default.Wrap(err, "scope config schema is not valid JSON")
46 }
47 specTemplate, tmplErr := specTemplate()
48 if tmplErr != nil {
49 return nil, tmplErr
50 }
51 writer := &strings.Builder{}
52 err = specTemplate.Execute(writer, map[string]interface{}{
53 "PluginName": pluginInfo.Name,
54 "ConnectionSchema": string(connectionSchema),
55 "ScopeSchema": string(scopeSchema),
56 "ScopeConfigSchema": string(scopeConfigSchema),
57 })
58 if err != nil {
59 return nil, errors.Default.Wrap(err, "could not execute swagger doc template")
60 }
61 doc := writer.String()
62 return &doc, nil
63}
64
65func specTemplate() (*template.Template, errors.Error) {
66 path := config.GetConfig().GetString("SWAGGER_DOCS_DIR")

Callers

nothing calls this directly

Calls 4

specTemplateFunction · 0.85
WrapMethod · 0.80
ExecuteMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected