(pluginInfo *models.PluginInfo)
| 32 | ) |
| 33 | |
| 34 | func 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 | |
| 65 | func specTemplate() (*template.Template, errors.Error) { |
| 66 | path := config.GetConfig().GetString("SWAGGER_DOCS_DIR") |
nothing calls this directly
no test coverage detected