Skip to content

Commit

Permalink
feat: suitable to support python-sdk.
Browse files Browse the repository at this point in the history
  • Loading branch information
xufeixiang committed Sep 9, 2024
1 parent 1c6fc6a commit 89cf772
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 20 deletions.
2 changes: 1 addition & 1 deletion assets/front
Submodule front updated 166 files
2 changes: 1 addition & 1 deletion pkg/common/consts/config_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const (
HookGlobalParent = "global"
HookAuthenticationParent = "authentication"
HookOperationParent = "operation"
HookStorageParent = "storage"
HookStorageProfileParent = "upload"
HookCustomizeParent = "customize"
HookProxyParent = "proxy"
HookFunctionParent = "function"
Expand Down
23 changes: 12 additions & 11 deletions pkg/common/models/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@ const (
)

type Sdk struct {
Name string `json:"name"`
Enabled bool `json:"enabled"`
Type sdkType `json:"type"`
Language string `json:"language"`
Extension string `json:"extension"`
GitUrl string `json:"gitUrl"`
GitBranch string `json:"gitBranch"`
GitCommitHash string `json:"gitCommitHash"`
OutputPath string `json:"outputPath"`
CodePackage string `json:"codePackage"`
UpperFirstBasename bool `json:"upperFirstBasename"`
Name string `json:"name"`
Enabled bool `json:"enabled"`
Type sdkType `json:"type"`
Language string `json:"language"`
Extension string `json:"extension"`
GitUrl string `json:"gitUrl"`
GitBranch string `json:"gitBranch"`
GitCommitHash string `json:"gitCommitHash"`
OutputPath string `json:"outputPath"`
CodePackage string `json:"codePackage"`
UpperFirstBasename bool `json:"upperFirstBasename"`
Keywords []string `json:"keywords"`

CreateTime string `json:"createTime"`
UpdateTime string `json:"updateTime"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/common/models/storage_profile_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func buildS3UploadProfileHook(hook consts.UploadHook, enabledFunc func(item *wgp
if codePackage != "" {
outputPath = utils.NormalizePath(outputPath, codePackage)
}
outputPath = utils.NormalizePath(outputPath, consts.HookStorageParent)
outputPath = utils.NormalizePath(outputPath, consts.HookStorageProfileParent)
}
item.Root = outputPath
item.UpperFirstBasename = upperFirstBasename
Expand Down
10 changes: 5 additions & 5 deletions pkg/engine/sdk/hook_reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type (
endpoints map[string]*endpointMetadata
}
baseRequestBody struct {
Wg baseRequestBodyWg `json:"__wg"`
Wg baseRequestBodyWg `json:"__wg,omitempty"`
}
baseRequestBodyWg struct {
ClientRequest hooks.WunderGraphRequest `json:"clientRequest"`
Expand Down Expand Up @@ -288,7 +288,7 @@ func (o *reflectObjectFactory) reflectBaseHook() {
hookParentSchema.Title = "HookParent"
hookParentSchema.Enum = append(hookParentSchema.Enum,
consts.HookGeneratedParent, consts.HookGlobalParent, consts.HookAuthenticationParent,
consts.HookOperationParent, consts.HookStorageParent, consts.HookCustomizeParent,
consts.HookOperationParent, consts.HookStorageProfileParent, consts.HookCustomizeParent,
consts.HookProxyParent, consts.HookFunctionParent, consts.HookFragmentsParent)
o.buildObjectFromDataSchema(&openapi3.SchemaRef{Value: hookParentSchema}, &objectField{})

Expand Down Expand Up @@ -378,9 +378,9 @@ func (o *reflectObjectFactory) reflectOperationHook() {

// 生成上传钩子相关的jsonschema
func (o *reflectObjectFactory) reflectUploadHook() {
o.reflectStructSchema(uploadHookPayload{}, consts.HookStorageParent)
o.reflectStructSchema(hooks.UploadHookResponse{}, consts.HookStorageParent)
o.reflectStructSchema(s3uploadclient.UploadedFiles{}, consts.HookStorageParent)
o.reflectStructSchema(uploadHookPayload{}, consts.HookStorageProfileParent)
o.reflectStructSchema(hooks.UploadHookResponse{}, consts.HookStorageProfileParent)
o.reflectStructSchema(s3uploadclient.UploadedFiles{}, consts.HookStorageProfileParent)

uploadHookSchema := openapi3.NewStringSchema()
uploadHookSchema.Title = utils.GetTypeName(consts.PreUpload)
Expand Down
3 changes: 2 additions & 1 deletion pkg/engine/sdk/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ func (o *objectInfoFactory) optimizeFieldInfo() {
for _, field := range o.objectFieldMap {
o.buildObjectFieldItemRef(field)
slices.SortFunc(field.Fields, func(a *objectField, b *objectField) bool {
return a.Name < b.Name
aa, bb := cast.ToInt(a.Required), cast.ToInt(b.Required)
return aa > bb || aa == bb && a.Name < b.Name
})
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/engine/sdk/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type (

OnceMap map[string]any
LengthMap map[string]any
Sdk *models.Sdk
}
)

Expand Down Expand Up @@ -168,6 +169,7 @@ func (t *templateContext) generateTemplate(sdk *models.Sdk) {
}

t.OnceMap = make(map[string]any)
t.Sdk = sdk
ignoredFiles := getIgnoredFiles(utils.NormalizePath(outputPath, ignoreFile))
existIgnoredFiles := len(ignoredFiles) > 0
if existIgnoredFiles {
Expand Down
10 changes: 10 additions & 0 deletions pkg/engine/sdk/template_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,14 @@ func init() {

return defaultValue
})
// 获取值或默认值
handlebars.RegisterHelper("filterFieldsByKeywords", func(fields []*objectField, keywords []string) []*objectField {
var result []*objectField
for _, item := range fields {
if slices.Contains(keywords, item.Name) {
result = append(result, item)
}
}
return result
})
}

0 comments on commit 89cf772

Please sign in to comment.