A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.
fix(embed): embed plugin type definition
kumfo1d9f88f803cb
diff --git a/docs/docs.go b/docs/docs.goindex cf1264d1..fab0d8e9 100644--- a/docs/docs.go+++ b/docs/docs.go@@ -2738,7 +2738,7 @@ const docTemplate = `{"data": {"type": "array","items": {- "$ref": "#/definitions/schema.GetEmbedOptionResp"+ "$ref": "#/definitions/plugin.EmbedConfig"}}}@@ -4410,7 +4410,7 @@ const docTemplate = `{"data": {"type": "array","items": {- "$ref": "#/definitions/schema.GetTagResp"+ "$ref": "#/definitions/schema.GetTagBasicResp"}}}@@ -5380,7 +5380,7 @@ const docTemplate = `{},"/answer/api/v1/tags": {"get": {- "description": "get tags list",+ "description": "get tags list by slug name","produces": ["application/json"],@@ -5404,7 +5404,22 @@ const docTemplate = `{"200": {"description": "OK","schema": {- "$ref": "#/definitions/handler.RespBody"+ "allOf": [+ {+ "$ref": "#/definitions/handler.RespBody"+ },+ {+ "type": "object",+ "properties": {+ "data": {+ "type": "array",+ "items": {+ "$ref": "#/definitions/schema.GetTagBasicResp"+ }+ }+ }+ }+ ]}}}@@ -6571,14 +6586,14 @@ const docTemplate = `{},"/custom.css": {"get": {- "description": "get site robots information",+ "description": "get site custom CSS","produces": [- "application/json"+ "text/css"],"tags": ["site"],- "summary": "get site robots information",+ "summary": "get site custom CSS","responses": {"200": {"description": "OK",@@ -7004,6 +7019,17 @@ const docTemplate = `{"list": {}}},+ "plugin.EmbedConfig": {+ "type": "object",+ "properties": {+ "enable": {+ "type": "boolean"+ },+ "platform": {+ "type": "string"+ }+ }+ },"schema.AcceptAnswerReq": {"type": "object","required": [@@ -7813,17 +7839,6 @@ const docTemplate = `{}}},- "schema.GetEmbedOptionResp": {- "type": "object",- "properties": {- "enable": {- "type": "boolean"- },- "platform": {- "type": "string"- }- }- },"schema.GetFollowingTagsResp": {"type": "object","properties": {@@ -8242,6 +8257,23 @@ const docTemplate = `{}}},+ "schema.GetTagBasicResp": {+ "type": "object",+ "properties": {+ "display_name": {+ "type": "string"+ },+ "recommend": {+ "type": "boolean"+ },+ "reserved": {+ "type": "boolean"+ },+ "slug_name": {+ "type": "string"+ }+ }+ },"schema.GetTagPageResp": {"type": "object","properties": {@@ -9819,7 +9851,7 @@ const docTemplate = `{"recommend_tags": {"type": "array","items": {- "type": "string"+ "$ref": "#/definitions/schema.SiteWriteTag"}},"required_tag": {@@ -9828,7 +9860,7 @@ const docTemplate = `{"reserved_tags": {"type": "array","items": {- "type": "string"+ "$ref": "#/definitions/schema.SiteWriteTag"}},"restrict_answer": {@@ -9842,7 +9874,7 @@ const docTemplate = `{"recommend_tags": {"type": "array","items": {- "type": "string"+ "$ref": "#/definitions/schema.SiteWriteTag"}},"required_tag": {@@ -9851,7 +9883,7 @@ const docTemplate = `{"reserved_tags": {"type": "array","items": {- "type": "string"+ "$ref": "#/definitions/schema.SiteWriteTag"}},"restrict_answer": {@@ -9859,6 +9891,20 @@ const docTemplate = `{}}},+ "schema.SiteWriteTag": {+ "type": "object",+ "required": [+ "slug_name"+ ],+ "properties": {+ "display_name": {+ "type": "string"+ },+ "slug_name": {+ "type": "string"+ }+ }+ },"schema.TagItem": {"type": "object","properties": {diff --git a/docs/swagger.json b/docs/swagger.jsonindex 1e93d2b0..9ea2d2ee 100644--- a/docs/swagger.json+++ b/docs/swagger.json@@ -2708,7 +2708,7 @@"data": {"type": "array","items": {- "$ref": "#/definitions/schema.GetEmbedOptionResp"+ "$ref": "#/definitions/plugin.EmbedConfig"}}}@@ -4380,7 +4380,7 @@"data": {"type": "array","items": {- "$ref": "#/definitions/schema.GetTagResp"+ "$ref": "#/definitions/schema.GetTagBasicResp"}}}@@ -5350,7 +5350,7 @@},"/answer/api/v1/tags": {"get": {- "description": "get tags list",+ "description": "get tags list by slug name","produces": ["application/json"],@@ -5374,7 +5374,22 @@"200": {"description": "OK","schema": {- "$ref": "#/definitions/handler.RespBody"+ "allOf": [+ {+ "$ref": "#/definitions/handler.RespBody"+ },+ {+ "type": "object",+ "properties": {+ "data": {+ "type": "array",+ "items": {+ "$ref": "#/definitions/schema.GetTagBasicResp"+ }+ }+ }+ }+ ]}}}@@ -6541,14 +6556,14 @@},"/custom.css": {"get": {- "description": "get site robots information",+ "description": "get site custom CSS","produces": [- "application/json"+ "text/css"],"tags": ["site"],- "summary": "get site robots information",+ "summary": "get site custom CSS","responses": {"200": {"description": "OK",@@ -6974,6 +6989,17 @@"list": {}}},+ "plugin.EmbedConfig": {+ "type": "object",+ "properties": {+ "enable": {+ "type": "boolean"+ },+ "platform": {+ "type": "string"+ }+ }+ },"schema.AcceptAnswerReq": {"type": "object","required": [@@ -7783,17 +7809,6 @@}}},- "schema.GetEmbedOptionResp": {- "type": "object",- "properties": {- "enable": {- "type": "boolean"- },- "platform": {- "type": "string"- }- }- },"schema.GetFollowingTagsResp": {"type": "object","properties": {@@ -8212,6 +8227,23 @@}}},+ "schema.GetTagBasicResp": {+ "type": "object",+ "properties": {+ "display_name": {+ "type": "string"+ },+ "recommend": {+ "type": "boolean"+ },+ "reserved": {+ "type": "boolean"+ },+ "slug_name": {+ "type": "string"+ }+ }+ },"schema.GetTagPageResp": {"type": "object","properties": {@@ -8809,7 +8841,7 @@"enum": ["newest","active",- "frequent",+ "hot","score","unanswered"]@@ -9789,7 +9821,7 @@"recommend_tags": {"type": "array","items": {- "type": "string"+ "$ref": "#/definitions/schema.SiteWriteTag"}},"required_tag": {@@ -9798,7 +9830,7 @@"reserved_tags": {"type": "array","items": {- "type": "string"+ "$ref": "#/definitions/schema.SiteWriteTag"}},"restrict_answer": {@@ -9812,7 +9844,7 @@"recommend_tags": {"type": "array","items": {- "type": "string"+ "$ref": "#/definitions/schema.SiteWriteTag"}},"required_tag": {@@ -9821,7 +9853,7 @@"reserved_tags": {"type": "array","items": {- "type": "string"+ "$ref": "#/definitions/schema.SiteWriteTag"}},"restrict_answer": {@@ -9829,6 +9861,20 @@}}},+ "schema.SiteWriteTag": {+ "type": "object",+ "required": [+ "slug_name"+ ],+ "properties": {+ "display_name": {+ "type": "string"+ },+ "slug_name": {+ "type": "string"+ }+ }+ },"schema.TagItem": {"type": "object","properties": {diff --git a/docs/swagger.yaml b/docs/swagger.yamlindex 93f8116a..1b176960 100644--- a/docs/swagger.yaml+++ b/docs/swagger.yaml@@ -117,6 +117,13 @@ definitions:type: integerlist: {}type: object+ plugin.EmbedConfig:+ properties:+ enable:+ type: boolean+ platform:+ type: string+ type: objectschema.AcceptAnswerReq:properties:answer_id:@@ -687,13 +694,6 @@ definitions:description: websitetype: stringtype: object- schema.GetEmbedOptionResp:- properties:- enable:- type: boolean- platform:- type: string- type: objectschema.GetFollowingTagsResp:properties:display_name:@@ -983,6 +983,17 @@ definitions:terms_of_service_parsed_text:type: stringtype: object+ schema.GetTagBasicResp:+ properties:+ display_name:+ type: string+ recommend:+ type: boolean+ reserved:+ type: boolean+ slug_name:+ type: string+ type: objectschema.GetTagPageResp:properties:created_at:@@ -1401,7 +1412,7 @@ definitions:enum:- newest- active- - frequent+ - hot- score- unansweredtype: string@@ -2071,13 +2082,13 @@ definitions:properties:recommend_tags:items:- type: string+ $ref: '#/definitions/schema.SiteWriteTag'type: arrayrequired_tag:type: booleanreserved_tags:items:- type: string+ $ref: '#/definitions/schema.SiteWriteTag'type: arrayrestrict_answer:type: boolean@@ -2086,17 +2097,26 @@ definitions:properties:recommend_tags:items:- type: string+ $ref: '#/definitions/schema.SiteWriteTag'type: arrayrequired_tag:type: booleanreserved_tags:items:- type: string+ $ref: '#/definitions/schema.SiteWriteTag'type: arrayrestrict_answer:type: booleantype: object+ schema.SiteWriteTag:+ properties:+ display_name:+ type: string+ slug_name:+ type: string+ required:+ - slug_name+ type: objectschema.TagItem:properties:display_name:@@ -4353,7 +4373,7 @@ paths:- properties:data:items:- $ref: '#/definitions/schema.GetEmbedOptionResp'+ $ref: '#/definitions/plugin.EmbedConfig'type: arraytype: objectsummary: GetEmbedConfig@@ -5382,7 +5402,7 @@ paths:- properties:data:items:- $ref: '#/definitions/schema.GetTagResp'+ $ref: '#/definitions/schema.GetTagBasicResp'type: arraytype: objectsecurity:@@ -5965,7 +5985,7 @@ paths:- Tag/answer/api/v1/tags:get:- description: get tags list+ description: get tags list by slug nameparameters:- collectionFormat: csvdescription: string collection@@ -5980,7 +6000,14 @@ paths:"200":description: OKschema:- $ref: '#/definitions/handler.RespBody'+ allOf:+ - $ref: '#/definitions/handler.RespBody'+ - properties:+ data:+ items:+ $ref: '#/definitions/schema.GetTagBasicResp'+ type: array+ type: objectsummary: get tags listtags:- Tag@@ -6677,15 +6704,15 @@ paths:- Activity/custom.css:get:- description: get site robots information+ description: get site custom CSSproduces:- - application/json+ - text/cssresponses:"200":description: OKschema:type: string- summary: get site robots information+ summary: get site custom CSStags:- site/installation/base-info:diff --git a/internal/controller/embed_controller.go b/internal/controller/embed_controller.goindex c9691d29..a61bd68c 100644--- a/internal/controller/embed_controller.go+++ b/internal/controller/embed_controller.go@@ -21,7 +21,6 @@ package controllerimport ("github.com/apache/incubator-answer/internal/base/handler"- "github.com/apache/incubator-answer/internal/schema""github.com/apache/incubator-answer/plugin""github.com/gin-gonic/gin")@@ -40,27 +39,14 @@ func NewEmbedController() *EmbedController {// @Accept json// @Produce json// @Router /answer/api/v1/embed/config [get]-// @Success 200 {object} handler.RespBody{data=[]schema.GetEmbedOptionResp}+// @Success 200 {object} handler.RespBody{data=[]plugin.EmbedConfig}func (c *EmbedController) GetEmbedConfig(ctx *gin.Context) {- resp := make([]*schema.GetEmbedOptionResp, 0)- var slugName string+ resp := make([]*plugin.EmbedConfig, 0)- _ = plugin.CallEmbed(func(base plugin.Embed) error {- slugName = base.Info().SlugName+ _ = plugin.CallEmbed(func(embed plugin.Embed) (err error) {+ resp, err = embed.GetEmbedConfigs(ctx)return nil})- _ = plugin.CallConfig(func(fn plugin.Config) error {- if fn.Info().SlugName == slugName {- for _, field := range fn.ConfigFields() {- resp = append(resp, &schema.GetEmbedOptionResp{- Platform: field.Name,- Enable: field.Value.(bool),- })- }- return nil- }- return nil- })handler.HandleResponse(ctx, nil, resp)}diff --git a/internal/schema/plugin_option_schema.go b/internal/schema/plugin_option_schema.godeleted file mode 100644index 8db22973..00000000--- a/internal/schema/plugin_option_schema.go+++ /dev/null@@ -1,25 +0,0 @@-/*- * Licensed to the Apache Software Foundation (ASF) under one- * or more contributor license agreements. See the NOTICE file- * distributed with this work for additional information- * regarding copyright ownership. The ASF licenses this file- * to you under the Apache License, Version 2.0 (the- * "License"); you may not use this file except in compliance- * with the License. You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing,- * software distributed under the License is distributed on an- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY- * KIND, either express or implied. See the License for the- * specific language governing permissions and limitations- * under the License.- */--package schema--type GetEmbedOptionResp struct {- Platform string `json:"platform"`- Enable bool `json:"enable"`-}diff --git a/plugin/embed.go b/plugin/embed.goindex 55149f66..e853c8c2 100644--- a/plugin/embed.go+++ b/plugin/embed.go@@ -19,8 +19,16 @@package plugin+import "github.com/gin-gonic/gin"++type EmbedConfig struct {+ Platform string `json:"platform"`+ Enable bool `json:"enable"`+}+type Embed interface {Base+ GetEmbedConfigs(ctx *gin.Context) (embedConfigs []*EmbedConfig, err error)}var (