From 1dd374fcf2a80f94635b4edb9063acd6c6f71cbf Mon Sep 17 00:00:00 2001 From: peefy Date: Mon, 12 Aug 2024 13:44:24 +0800 Subject: [PATCH] feat: enhancement kcl import go struct with schema name and doc field Signed-off-by: peefy --- pkg/tools/gen/genkcl.go | 2 +- pkg/tools/gen/genkcl_gostruct.go | 7 +- pkg/tools/gen/genkcl_gostruct_test.go | 1497 +++++++++++++++++++++++++ pkg/tools/gen/genkcl_jsonschema.go | 16 +- pkg/tools/gen/genkcl_test.go | 1 - 5 files changed, 1509 insertions(+), 14 deletions(-) create mode 100644 pkg/tools/gen/genkcl_gostruct_test.go diff --git a/pkg/tools/gen/genkcl.go b/pkg/tools/gen/genkcl.go index 60734910..bcc9ae3e 100644 --- a/pkg/tools/gen/genkcl.go +++ b/pkg/tools/gen/genkcl.go @@ -11,7 +11,7 @@ import ( type GenKclOptions struct { Mode Mode - CastingOption castingOption + CastingOption CastingOption UseIntegersForNumbers bool } diff --git a/pkg/tools/gen/genkcl_gostruct.go b/pkg/tools/gen/genkcl_gostruct.go index 26dcb41a..ea0fe30b 100644 --- a/pkg/tools/gen/genkcl_gostruct.go +++ b/pkg/tools/gen/genkcl_gostruct.go @@ -183,7 +183,8 @@ func (ctx *genKclTypeContext) convertSchemaFromGoPackage() ([]convertResult, err name := s.name if _, ok := ctx.resultMap[name]; !ok { result := convertResult{IsSchema: true} - ctx.resultMap[name] = result + result.schema.Name = name + result.schema.Description = s.doc for _, field := range s.fields { typeName := ctx.typeName(name, field.name, field.ty) fieldName := formatName(field.name) @@ -192,15 +193,13 @@ func (ctx *genKclTypeContext) convertSchemaFromGoPackage() ([]convertResult, err fieldName = tagName typeName = tagTy } - result.schema.Name = name - result.schema.Description = s.doc result.schema.Properties = append(result.Properties, property{ Name: fieldName, Type: typeName, Description: s.fieldDocs[field.name], }) - ctx.resultMap[name] = result } + ctx.resultMap[name] = result } } // Append anonymous structs diff --git a/pkg/tools/gen/genkcl_gostruct_test.go b/pkg/tools/gen/genkcl_gostruct_test.go new file mode 100644 index 00000000..bc03f943 --- /dev/null +++ b/pkg/tools/gen/genkcl_gostruct_test.go @@ -0,0 +1,1497 @@ +package gen + +import ( + "bytes" + "log" + "strings" + "testing" + + assert2 "github.com/stretchr/testify/assert" +) + +func TestGenKclFromLibGoStruct(t *testing.T) { + var buf bytes.Buffer + opts := &GenKclOptions{} + err := GenKcl(&buf, "../../spec/gpyrpc/gpyrpc.pb.go", nil, opts) + if err != nil { + log.Fatal(err) + } + kclCode := buf.String() + expectedKclCodeFromField := `""" +This file was generated by the KCL auto-gen tool. DO NOT EDIT. +Editing this file might prove futile when you re-run the KCL auto-gen generate command. +""" + +schema Argument: + r""" + Message representing a key-value argument for KCL. + kcl main.k -D name=value + + + Attributes + ---------- + Name : str, optional + Name of the argument. + + Value : str, optional + Value of the argument. + + """ + + Name?: str + Value?: str + +schema BuildProgram_Args: + r""" + Message for build program request arguments. + + + Attributes + ---------- + ExecArgs : ExecProgram_Args, optional + Arguments for executing the program. + + Output : str, optional + Output path. + + """ + + ExecArgs?: ExecProgram_Args + Output?: str + +schema BuildProgram_Result: + r""" + Message for build program response. + + + Attributes + ---------- + Path : str, optional + Path of the built program. + + """ + + Path?: str + +schema CliConfig: + r""" + Message representing KCL CLI configuration. + + + Attributes + ---------- + Files : [str], optional + List of files. + + Output : str, optional + Output path. + + Overrides : [str], optional + List of overrides. + + PathSelector : [str], optional + Path selectors. + + StrictRangeCheck : bool, optional + Flag for strict range check. + + DisableNone : bool, optional + Flag to disable none values. + + Verbose : int, optional + Verbose level. + + Debug : bool, optional + Debug flag. + + SortKeys : bool, optional + Flag to sort keys in YAML/JSON results. + + ShowHidden : bool, optional + Flag to show hidden attributes. + + IncludeSchemaTypePath : bool, optional + Flag to include schema type path in results. + + FastEval : bool, optional + Flag for fast evaluation. + + """ + + Files?: [str] + Output?: str + Overrides?: [str] + PathSelector?: [str] + StrictRangeCheck?: bool + DisableNone?: bool + Verbose?: int + Debug?: bool + SortKeys?: bool + ShowHidden?: bool + IncludeSchemaTypePath?: bool + FastEval?: bool + +schema Decorator: + r""" + Message representing a decorator in KCL. + + + Attributes + ---------- + Name : str, optional + Name of the decorator. + + Arguments : [str], optional + Arguments for the decorator. + + Keywords : {str:str}, optional + Keyword arguments for the decorator as a map with keyword name as key. + + """ + + Name?: str + Arguments?: [str] + Keywords?: {str:str} + +schema Error: + r""" + Message representing an error. + + + Attributes + ---------- + Level : str, optional + Level of the error (e.g., "Error", "Warning"). + + Code : str, optional + Error code. (e.g., "E1001") + + Messages : [Message], optional + List of error messages. + + """ + + Level?: str + Code?: str + Messages?: [Message] + +schema Example: + r""" + Message representing an example in KCL. + + + Attributes + ---------- + Summary : str, optional + Short description for the example. + + Description : str, optional + Long description for the example. + + Value : str, optional + Embedded literal example. + + """ + + Summary?: str + Description?: str + Value?: str + +schema ExecArtifact_Args: + r""" + Message for execute artifact request arguments. + + + Attributes + ---------- + Path : str, optional + Path of the artifact. + + ExecArgs : ExecProgram_Args, optional + Arguments for executing the program. + + """ + + Path?: str + ExecArgs?: ExecProgram_Args + +schema ExecProgram_Args: + r""" + Message for execute program request arguments. + + + Attributes + ---------- + WorkDir : str, optional + Working directory. + + KFilenameList : [str], optional + List of KCL filenames. + + KCodeList : [str], optional + List of KCL codes. + + Args : [Argument], optional + Arguments for the program. + + Overrides : [str], optional + Override configurations. + + DisableYamlResult : bool, optional + Flag to disable YAML result. + + PrintOverrideAst : bool, optional + Flag to print override AST. + + StrictRangeCheck : bool, optional + Flag for strict range check. + + DisableNone : bool, optional + Flag to disable none values. + + Verbose : int, optional + Verbose level. + + Debug : int, optional + Debug level. + + SortKeys : bool, optional + Flag to sort keys in YAML/JSON results. + + ExternalPkgs : [ExternalPkg], optional + External packages path. + + IncludeSchemaTypePath : bool, optional + Flag to include schema type path in results. + + CompileOnly : bool, optional + Flag to compile only without execution. + + ShowHidden : bool, optional + Flag to show hidden attributes. + + PathSelector : [str], optional + Path selectors for results. + + FastEval : bool, optional + Flag for fast evaluation. + + """ + + WorkDir?: str + KFilenameList?: [str] + KCodeList?: [str] + Args?: [Argument] + Overrides?: [str] + DisableYamlResult?: bool + PrintOverrideAst?: bool + StrictRangeCheck?: bool + DisableNone?: bool + Verbose?: int + Debug?: int + SortKeys?: bool + ExternalPkgs?: [ExternalPkg] + IncludeSchemaTypePath?: bool + CompileOnly?: bool + ShowHidden?: bool + PathSelector?: [str] + FastEval?: bool + +schema ExecProgram_Result: + r""" + Message for execute program response. + + + Attributes + ---------- + JsonResult : str, optional + Result in JSON format. + + YamlResult : str, optional + Result in YAML format. + + LogMessage : str, optional + Log message from execution. + + ErrMessage : str, optional + Error message from execution. + + """ + + JsonResult?: str + YamlResult?: str + LogMessage?: str + ErrMessage?: str + +schema ExternalPkg: + r""" + Message representing an external package for KCL. + kcl main.k -E pkg_name=pkg_path + + + Attributes + ---------- + PkgName : str, optional + Name of the package. + + PkgPath : str, optional + Path of the package. + + """ + + PkgName?: str + PkgPath?: str + +schema FormatCode_Args: + r""" + Message for format code request arguments. + + + Attributes + ---------- + Source : str, optional + Source code to be formatted. + + """ + + Source?: str + +schema FormatCode_Result: + r""" + Message for format code response. + + + Attributes + ---------- + Formatted : [int], optional + Formatted code as bytes. + + """ + + Formatted?: [int] + +schema FormatPath_Args: + r""" + Message for format file path request arguments. + + + Attributes + ---------- + Path : str, optional + Path of the file to format. + + """ + + Path?: str + +schema FormatPath_Result: + r""" + Message for format file path response. + + + Attributes + ---------- + ChangedPaths : [str], optional + List of changed file paths. + + """ + + ChangedPaths?: [str] + +schema GetSchemaTypeMapping_Args: + r""" + Message for get schema type mapping request arguments. + + + Attributes + ---------- + ExecArgs : ExecProgram_Args, optional + Arguments for executing the program. + + SchemaName : str, optional + Name of the schema. + + """ + + ExecArgs?: ExecProgram_Args + SchemaName?: str + +schema GetSchemaTypeMapping_Result: + r""" + Message for get schema type mapping response. + + + Attributes + ---------- + SchemaTypeMapping : {str:KclType}, optional + Map of schema type mappings. + + """ + + SchemaTypeMapping?: {str:KclType} + +schema GetVersion_Args: + r""" + Message for version request arguments. Empty message. + + """ + + +schema GetVersion_Result: + r""" + Message for version response. + + + Attributes + ---------- + Version : str, optional + KCL version. + + Checksum : str, optional + Checksum of the KCL version. + + GitSha : str, optional + Git Git SHA of the KCL code repo. + + VersionInfo : str, optional + Detailed version information as a string. + + """ + + Version?: str + Checksum?: str + GitSha?: str + VersionInfo?: str + +schema KclType: + r""" + Message representing a KCL type. + + + Attributes + ---------- + Type : str, optional + Type name (e.g., schema, dict, list, str, int, float, bool, any, union, number_multiplier). + + UnionTypes : [KclType], optional + Union types if applicable. + + Default : str, optional + Default value of the type. + + SchemaName : str, optional + Name of the schema if applicable. + + SchemaDoc : str, optional + Documentation for the schema. + + Properties : {str:KclType}, optional + Properties of the schema as a map with property name as key. + + Required : [str], optional + List of required schema properties. + + Key : KclType, optional + Key type if the KclType is a dictionary. + + Item : KclType, optional + Item type if the KclType is a list or dictionary. + + Line : int, optional + Line number where the type is defined. + + Decorators : [Decorator], optional + List of decorators for the schema. + + Filename : str, optional + Absolute path of the file where the attribute is located. + + PkgPath : str, optional + Path of the package where the attribute is located. + + Description : str, optional + Documentation for the attribute. + + Examples : {str:Example}, optional + Map of examples with example name as key. + + BaseSchema : KclType, optional + Base schema if applicable. + + """ + + Type?: str + UnionTypes?: [KclType] + Default?: str + SchemaName?: str + SchemaDoc?: str + Properties?: {str:KclType} + Required?: [str] + Key?: KclType + Item?: KclType + Line?: int + Decorators?: [Decorator] + Filename?: str + PkgPath?: str + Description?: str + Examples?: {str:Example} + BaseSchema?: KclType + +schema KeyValuePair: + r""" + Message representing a key-value pair. + + + Attributes + ---------- + Key : str, optional + Key of the pair. + + Value : str, optional + Value of the pair. + + """ + + Key?: str + Value?: str + +schema LintPath_Args: + r""" + Message for lint file path request arguments. + + + Attributes + ---------- + Paths : [str], optional + Paths of the files to lint. + + """ + + Paths?: [str] + +schema LintPath_Result: + r""" + Message for lint file path response. + + + Attributes + ---------- + Results : [str], optional + List of lint results. + + """ + + Results?: [str] + +schema ListDepFiles_Args: + r""" + Message for list dependency files request arguments. + + + Attributes + ---------- + WorkDir : str, optional + Working directory. + + UseAbsPath : bool, optional + Flag to use absolute paths. + + IncludeAll : bool, optional + Flag to include all files. + + UseFastParser : bool, optional + Flag to use fast parser. + + """ + + WorkDir?: str + UseAbsPath?: bool + IncludeAll?: bool + UseFastParser?: bool + +schema ListDepFiles_Result: + r""" + Message for list dependency files response. + + + Attributes + ---------- + Pkgroot : str, optional + Root package path. + + Pkgpath : str, optional + Package path. + + Files : [str], optional + List of file paths in the package. + + """ + + Pkgroot?: str + Pkgpath?: str + Files?: [str] + +schema ListMethod_Args: + r""" + Message for list method request arguments. Empty message. + + """ + + +schema ListMethod_Result: + r""" + Message for list method response. + + + Attributes + ---------- + MethodNameList : [str], optional + List of available method names. + + """ + + MethodNameList?: [str] + +schema ListOptions_Result: + r""" + Message for list options response. + + + Attributes + ---------- + Options : [OptionHelp], optional + List of available options. + + """ + + Options?: [OptionHelp] + +schema ListVariables_Args: + r""" + Message for list variables request arguments. + + + Attributes + ---------- + Files : [str], optional + Files to be processed. + + Specs : [str], optional + Specifications for variables. + + Options : ListVariables_Options, optional + Options for listing variables. + + """ + + Files?: [str] + Specs?: [str] + Options?: ListVariables_Options + +schema ListVariables_Options: + r""" + Message for list variables options. + + + Attributes + ---------- + MergeProgram : bool, optional + Flag to merge program configuration. + + """ + + MergeProgram?: bool + +schema ListVariables_Result: + r""" + Message for list variables response. + + + Attributes + ---------- + Variables : {str:VariableList}, optional + Map of variable lists by file. + + UnsupportedCodes : [str], optional + List of unsupported codes. + + ParseErrors : [Error], optional + List of parse errors encountered. + + """ + + Variables?: {str:VariableList} + UnsupportedCodes?: [str] + ParseErrors?: [Error] + +schema LoadPackage_Args: + r""" + Message for load package request arguments. + + + Attributes + ---------- + ParseArgs : ParseProgram_Args, optional + Arguments for parsing the program. + + ResolveAst : bool, optional + Flag indicating whether to resolve AST. + + LoadBuiltin : bool, optional + Flag indicating whether to load built-in modules. + + WithAstIndex : bool, optional + Flag indicating whether to include AST index. + + """ + + ParseArgs?: ParseProgram_Args + ResolveAst?: bool + LoadBuiltin?: bool + WithAstIndex?: bool + +schema LoadPackage_Result: + r""" + Message for load package response. + + + Attributes + ---------- + Program : str, optional + Program Abstract Syntax Tree (AST) in JSON format. + + Paths : [str], optional + Returns the files in the order they should be compiled. + + ParseErrors : [Error], optional + List of parse errors. + + TypeErrors : [Error], optional + List of type errors. + + Scopes : {str:Scope}, optional + Map of scopes with scope index as key. + + Symbols : {str:Symbol}, optional + Map of symbols with symbol index as key. + + NodeSymbolMap : {str:SymbolIndex}, optional + Map of node-symbol associations with AST index UUID as key. + + SymbolNodeMap : {str:str}, optional + Map of symbol-node associations with symbol index as key. + + FullyQualifiedNameMap : {str:SymbolIndex}, optional + Map of fully qualified names with symbol index as key. + + PkgScopeMap : {str:ScopeIndex}, optional + Map of package scope with package path as key. + + """ + + Program?: str + Paths?: [str] + ParseErrors?: [Error] + TypeErrors?: [Error] + Scopes?: {str:Scope} + Symbols?: {str:Symbol} + NodeSymbolMap?: {str:SymbolIndex} + SymbolNodeMap?: {str:str} + FullyQualifiedNameMap?: {str:SymbolIndex} + PkgScopeMap?: {str:ScopeIndex} + +schema LoadSettingsFiles_Args: + r""" + Message for load settings files request arguments. + + + Attributes + ---------- + WorkDir : str, optional + Working directory. + + Files : [str], optional + Setting files to load. + + """ + + WorkDir?: str + Files?: [str] + +schema LoadSettingsFiles_Result: + r""" + Message for load settings files response. + + + Attributes + ---------- + KclCliConfigs : CliConfig, optional + KCL CLI configuration. + + KclOptions : [KeyValuePair], optional + List of KCL options as key-value pairs. + + """ + + KclCliConfigs?: CliConfig + KclOptions?: [KeyValuePair] + +schema MapEntry: + r""" + Message representing a map entry. + + + Attributes + ---------- + Key : str, optional + Key of the map entry. + + Value : Variable, optional + Value of the map entry. + + """ + + Key?: str + Value?: Variable + +schema Message: + r""" + Message representing a detailed error message with a position. + + + Attributes + ---------- + Msg : str, optional + The error message text. + + Pos : Position, optional + The position in the source code where the error occurred. + + """ + + Msg?: str + Pos?: Position + +schema OptionHelp: + r""" + Message representing a help option. + + + Attributes + ---------- + Name : str, optional + Name of the option. + + Type : str, optional + Type of the option. + + Required : bool, optional + Flag indicating if the option is required. + + DefaultValue : str, optional + Default value of the option. + + Help : str, optional + Help text for the option. + + """ + + Name?: str + Type?: str + Required?: bool + DefaultValue?: str + Help?: str + +schema OverrideFile_Args: + r""" + Message for override file request arguments. + + + Attributes + ---------- + File : str, optional + Path of the file to override. + + Specs : [str], optional + List of override specifications. + + ImportPaths : [str], optional + List of import paths. + + """ + + File?: str + Specs?: [str] + ImportPaths?: [str] + +schema OverrideFile_Result: + r""" + Message for override file response. + + + Attributes + ---------- + Result : bool, optional + Result of the override operation. + + ParseErrors : [Error], optional + List of parse errors encountered. + + """ + + Result?: bool + ParseErrors?: [Error] + +schema ParseFile_Args: + r""" + Message for parse file request arguments. + + + Attributes + ---------- + Path : str, optional + Path of the file to be parsed. + + Source : str, optional + Source code to be parsed. + + ExternalPkgs : [ExternalPkg], optional + External packages path. + + """ + + Path?: str + Source?: str + ExternalPkgs?: [ExternalPkg] + +schema ParseFile_Result: + r""" + Message for parse file response. + + + Attributes + ---------- + AstJson : str, optional + Abstract Syntax Tree (AST) in JSON format. + + Deps : [str], optional + File dependency paths. + + Errors : [Error], optional + List of parse errors. + + """ + + AstJson?: str + Deps?: [str] + Errors?: [Error] + +schema ParseProgram_Args: + r""" + Message for parse program request arguments. + + + Attributes + ---------- + Paths : [str], optional + Paths of the program files to be parsed. + + Sources : [str], optional + Source codes to be parsed. + + ExternalPkgs : [ExternalPkg], optional + External packages path. + + """ + + Paths?: [str] + Sources?: [str] + ExternalPkgs?: [ExternalPkg] + +schema ParseProgram_Result: + r""" + Message for parse program response. + + + Attributes + ---------- + AstJson : str, optional + Abstract Syntax Tree (AST) in JSON format. + + Paths : [str], optional + Returns the files in the order they should be compiled. + + Errors : [Error], optional + List of parse errors. + + """ + + AstJson?: str + Paths?: [str] + Errors?: [Error] + +schema Ping_Args: + r""" + Message for ping request arguments. + + + Attributes + ---------- + Value : str, optional + Value to be sent in the ping request. + + """ + + Value?: str + +schema Ping_Result: + r""" + Message for ping response. + + + Attributes + ---------- + Value : str, optional + Value received in the ping response. + + """ + + Value?: str + +schema Position: + r""" + Message representing a position in the source code. + + + Attributes + ---------- + Line : int, optional + Line number. + + Column : int, optional + Column number. + + Filename : str, optional + Filename the position refers to. + + """ + + Line?: int + Column?: int + Filename?: str + +schema RenameCode_Args: + r""" + Message for rename code request arguments. + + + Attributes + ---------- + PackageRoot : str, optional + File path to the package root. + + SymbolPath : str, optional + Path to the target symbol to be renamed. + + SourceCodes : {str:str}, optional + Map of source code with filename as key and code as value. + + NewName : str, optional + New name of the symbol. + + """ + + PackageRoot?: str + SymbolPath?: str + SourceCodes?: {str:str} + NewName?: str + +schema RenameCode_Result: + r""" + Message for rename code response. + + + Attributes + ---------- + ChangedCodes : {str:str}, optional + Map of changed code with filename as key and modified code as value. + + """ + + ChangedCodes?: {str:str} + +schema Rename_Args: + r""" + Message for rename request arguments. + + + Attributes + ---------- + PackageRoot : str, optional + File path to the package root. + + SymbolPath : str, optional + Path to the target symbol to be renamed. + + FilePaths : [str], optional + Paths to the source code files. + + NewName : str, optional + New name of the symbol. + + """ + + PackageRoot?: str + SymbolPath?: str + FilePaths?: [str] + NewName?: str + +schema Rename_Result: + r""" + Message for rename response. + + + Attributes + ---------- + ChangedFiles : [str], optional + List of file paths that got changed. + + """ + + ChangedFiles?: [str] + +schema Scope: + r""" + Message representing a scope in KCL. + + + Attributes + ---------- + Kind : str, optional + Type of the scope. + + Parent : ScopeIndex, optional + Parent scope. + + Owner : SymbolIndex, optional + Owner of the scope. + + Children : [ScopeIndex], optional + Children of the scope. + + Defs : [SymbolIndex], optional + Definitions in the scope. + + """ + + Kind?: str + Parent?: ScopeIndex + Owner?: SymbolIndex + Children?: [ScopeIndex] + Defs?: [SymbolIndex] + +schema ScopeIndex: + r""" + Message representing a scope index. + + + Attributes + ---------- + I : int, optional + Index identifier. + + G : int, optional + Global identifier. + + Kind : str, optional + Type of the scope. + + """ + + I?: int + G?: int + Kind?: str + +schema Symbol: + r""" + Message representing a symbol in KCL. + + + Attributes + ---------- + Ty : KclType, optional + Type of the symbol. + + Name : str, optional + Name of the symbol. + + Owner : SymbolIndex, optional + Owner of the symbol. + + Def : SymbolIndex, optional + Definition of the symbol. + + Attrs : [SymbolIndex], optional + Attributes of the symbol. + + IsGlobal : bool, optional + Flag indicating if the symbol is global. + + """ + + Ty?: KclType + Name?: str + Owner?: SymbolIndex + Def?: SymbolIndex + Attrs?: [SymbolIndex] + IsGlobal?: bool + +schema SymbolIndex: + r""" + Message representing a symbol index. + + + Attributes + ---------- + I : int, optional + Index identifier. + + G : int, optional + Global identifier. + + Kind : str, optional + Type of the symbol or scope. + + """ + + I?: int + G?: int + Kind?: str + +schema TestCaseInfo: + r""" + Message representing information about a single test case. + + + Attributes + ---------- + Name : str, optional + Name of the test case. + + Error : str, optional + Error message if any. + + Duration : int, optional + Duration of the test case in microseconds. + + LogMessage : str, optional + Log message from the test case. + + """ + + Name?: str + Error?: str + Duration?: int + LogMessage?: str + +schema Test_Args: + r""" + Message for test request arguments. + + + Attributes + ---------- + ExecArgs : ExecProgram_Args, optional + Execution program arguments. + + PkgList : [str], optional + List of KCL package paths to be tested. + + RunRegexp : str, optional + Regular expression for filtering tests to run. + + FailFast : bool, optional + Flag to stop the test run on the first failure. + + """ + + ExecArgs?: ExecProgram_Args + PkgList?: [str] + RunRegexp?: str + FailFast?: bool + +schema Test_Result: + r""" + Message for test response. + + + Attributes + ---------- + Info : [TestCaseInfo], optional + List of test case information. + + """ + + Info?: [TestCaseInfo] + +schema UnimplementedBuiltinServiceServer: + r""" + UnimplementedBuiltinServiceServer can be embedded to have forward compatible implementations. + + """ + + +schema UnimplementedKclvmServiceServer: + r""" + UnimplementedKclvmServiceServer can be embedded to have forward compatible implementations. + + """ + + +schema UpdateDependencies_Args: + r""" + Message for update dependencies request arguments. + + + Attributes + ---------- + ManifestPath : str, optional + Path to the manifest file. + + Vendor : bool, optional + Flag to vendor dependencies locally. + + """ + + ManifestPath?: str + Vendor?: bool + +schema UpdateDependencies_Result: + r""" + Message for update dependencies response. + + + Attributes + ---------- + ExternalPkgs : [ExternalPkg], optional + List of external packages updated. + + """ + + ExternalPkgs?: [ExternalPkg] + +schema ValidateCode_Args: + r""" + Message for validate code request arguments. + + + Attributes + ---------- + Datafile : str, optional + Path to the data file. + + Data : str, optional + Data content. + + File : str, optional + Path to the code file. + + Code : str, optional + Source code content. + + Schema : str, optional + Name of the schema. + + AttributeName : str, optional + Name of the attribute. + + Format : str, optional + Format of the validation (e.g., "json", "yaml"). + + """ + + Datafile?: str + Data?: str + File?: str + Code?: str + Schema?: str + AttributeName?: str + Format?: str + +schema ValidateCode_Result: + r""" + Message for validate code response. + + + Attributes + ---------- + Success : bool, optional + Flag indicating if validation was successful. + + ErrMessage : str, optional + Error message from validation. + + """ + + Success?: bool + ErrMessage?: str + +schema Variable: + r""" + Message representing a variable. + + + Attributes + ---------- + Value : str, optional + Value of the variable. + + TypeName : str, optional + Type name of the variable. + + OpSym : str, optional + Operation symbol associated with the variable. + + ListItems : [Variable], optional + List items if the variable is a list. + + DictEntries : [MapEntry], optional + Dictionary entries if the variable is a dictionary. + + """ + + Value?: str + TypeName?: str + OpSym?: str + ListItems?: [Variable] + DictEntries?: [MapEntry] + +schema VariableList: + r""" + Message representing a list of variables. + + + Attributes + ---------- + Variables : [Variable], optional + List of variables. + + """ + + Variables?: [Variable] + +schema builtinServiceClient: + r""" + builtinServiceClient + """ + + +schema kclvmServiceClient: + r""" + kclvmServiceClient + """ + + +` + assert2.Equal(t, strings.ReplaceAll(kclCode, "\r\n", "\n"), strings.ReplaceAll(expectedKclCodeFromField, "\r\n", "\n")) +} diff --git a/pkg/tools/gen/genkcl_jsonschema.go b/pkg/tools/gen/genkcl_jsonschema.go index f620c33b..7a41114e 100644 --- a/pkg/tools/gen/genkcl_jsonschema.go +++ b/pkg/tools/gen/genkcl_jsonschema.go @@ -16,19 +16,19 @@ import ( "kcl-lang.io/kcl-go/pkg/source" ) -type castingOption int +type CastingOption int const ( - originalName castingOption = iota - snakeCase - camelCase + OriginalName CastingOption = iota + SnakeCase + CamelCase ) type context struct { imports map[string]struct{} resultMap map[string]convertResult paths []string - castingOption castingOption + castingOption CastingOption } type convertContext struct { @@ -47,11 +47,11 @@ type convertResult struct { property } -func convertPropertyName(name string, option castingOption) string { +func convertPropertyName(name string, option CastingOption) string { switch option { - case snakeCase: + case SnakeCase: return strcase.ToSnake(name) - case camelCase: + case CamelCase: return strcase.ToCamel(name) default: return name diff --git a/pkg/tools/gen/genkcl_test.go b/pkg/tools/gen/genkcl_test.go index f8156034..066285be 100644 --- a/pkg/tools/gen/genkcl_test.go +++ b/pkg/tools/gen/genkcl_test.go @@ -15,7 +15,6 @@ func TestGenKcl(t *testing.T) { var buf bytes.Buffer opts := &GenKclOptions{} err := GenKcl(&buf, "./testdata/genkcldata.go", nil, opts) - // err := GenKcl(&buf, "demo", code, opts) if err != nil { log.Fatal(err) }