rename module imports
This commit is contained in:
@@ -56,7 +56,7 @@ pub fn generate_actor_module(spec ActorSpecification) !Module {
|
||||
|
||||
// create module with code files and docs folder
|
||||
name_fixed := texttools.name_fix_snake(spec.name)
|
||||
return codemodel.new_module(
|
||||
return code.new_module(
|
||||
name: '${name_fixed}_actor'
|
||||
files: files
|
||||
folders: [docs_folder]
|
||||
|
||||
@@ -14,13 +14,13 @@ const actor_spec = specification.ActorSpecification{
|
||||
specification.ActorMethod{
|
||||
name: 'listPets'
|
||||
description: 'List all pets'
|
||||
func: codemodel.Function{
|
||||
func: code.Function{
|
||||
name: 'listPets'
|
||||
params: [
|
||||
codemodel.Param{
|
||||
code.Param{
|
||||
description: 'Maximum number of pets to return'
|
||||
name: 'limit'
|
||||
typ: codemodel.Type{
|
||||
typ: code.Type{
|
||||
symbol: 'int'
|
||||
}
|
||||
},
|
||||
@@ -30,21 +30,21 @@ const actor_spec = specification.ActorSpecification{
|
||||
specification.ActorMethod{
|
||||
name: 'createPet'
|
||||
description: 'Create a new pet'
|
||||
func: codemodel.Function{
|
||||
func: code.Function{
|
||||
name: 'createPet'
|
||||
}
|
||||
},
|
||||
specification.ActorMethod{
|
||||
name: 'getPet'
|
||||
description: 'Get a pet by ID'
|
||||
func: codemodel.Function{
|
||||
func: code.Function{
|
||||
name: 'getPet'
|
||||
params: [
|
||||
codemodel.Param{
|
||||
code.Param{
|
||||
required: true
|
||||
description: 'ID of the pet to retrieve'
|
||||
name: 'petId'
|
||||
typ: codemodel.Type{
|
||||
typ: code.Type{
|
||||
symbol: 'int'
|
||||
}
|
||||
},
|
||||
@@ -54,14 +54,14 @@ const actor_spec = specification.ActorSpecification{
|
||||
specification.ActorMethod{
|
||||
name: 'deletePet'
|
||||
description: 'Delete a pet by ID'
|
||||
func: codemodel.Function{
|
||||
func: code.Function{
|
||||
name: 'deletePet'
|
||||
params: [
|
||||
codemodel.Param{
|
||||
code.Param{
|
||||
required: true
|
||||
description: 'ID of the pet to delete'
|
||||
name: 'petId'
|
||||
typ: codemodel.Type{
|
||||
typ: code.Type{
|
||||
symbol: 'int'
|
||||
}
|
||||
},
|
||||
@@ -71,21 +71,21 @@ const actor_spec = specification.ActorSpecification{
|
||||
specification.ActorMethod{
|
||||
name: 'listOrders'
|
||||
description: 'List all orders'
|
||||
func: codemodel.Function{
|
||||
func: code.Function{
|
||||
name: 'listOrders'
|
||||
}
|
||||
},
|
||||
specification.ActorMethod{
|
||||
name: 'getOrder'
|
||||
description: 'Get an order by ID'
|
||||
func: codemodel.Function{
|
||||
func: code.Function{
|
||||
name: 'getOrder'
|
||||
params: [
|
||||
codemodel.Param{
|
||||
code.Param{
|
||||
required: true
|
||||
description: 'ID of the order to retrieve'
|
||||
name: 'orderId'
|
||||
typ: codemodel.Type{
|
||||
typ: code.Type{
|
||||
symbol: 'int'
|
||||
}
|
||||
},
|
||||
@@ -95,14 +95,14 @@ const actor_spec = specification.ActorSpecification{
|
||||
specification.ActorMethod{
|
||||
name: 'deleteOrder'
|
||||
description: 'Delete an order by ID'
|
||||
func: codemodel.Function{
|
||||
func: code.Function{
|
||||
name: 'deleteOrder'
|
||||
params: [
|
||||
codemodel.Param{
|
||||
code.Param{
|
||||
required: true
|
||||
description: 'ID of the order to delete'
|
||||
name: 'orderId'
|
||||
typ: codemodel.Type{
|
||||
typ: code.Type{
|
||||
symbol: 'int'
|
||||
}
|
||||
},
|
||||
@@ -112,39 +112,39 @@ const actor_spec = specification.ActorSpecification{
|
||||
specification.ActorMethod{
|
||||
name: 'createUser'
|
||||
description: 'Create a user'
|
||||
func: codemodel.Function{
|
||||
func: code.Function{
|
||||
name: 'createUser'
|
||||
}
|
||||
},
|
||||
]
|
||||
objects: [
|
||||
specification.BaseObject{
|
||||
structure: codemodel.Struct{
|
||||
structure: code.Struct{
|
||||
name: 'Pet'
|
||||
}
|
||||
},
|
||||
specification.BaseObject{
|
||||
structure: codemodel.Struct{
|
||||
structure: code.Struct{
|
||||
name: 'NewPet'
|
||||
}
|
||||
},
|
||||
specification.BaseObject{
|
||||
structure: codemodel.Struct{
|
||||
structure: code.Struct{
|
||||
name: 'Pets'
|
||||
}
|
||||
},
|
||||
specification.BaseObject{
|
||||
structure: codemodel.Struct{
|
||||
structure: code.Struct{
|
||||
name: 'Order'
|
||||
}
|
||||
},
|
||||
specification.BaseObject{
|
||||
structure: codemodel.Struct{
|
||||
structure: code.Struct{
|
||||
name: 'User'
|
||||
}
|
||||
},
|
||||
specification.BaseObject{
|
||||
structure: codemodel.Struct{
|
||||
structure: code.Struct{
|
||||
name: 'NewUser'
|
||||
}
|
||||
},
|
||||
|
||||
@@ -10,7 +10,7 @@ module generator
|
||||
// generate_list_result_struct(actor, object), generate_list_method(actor, object)]
|
||||
|
||||
// items << generate_object_methods(actor, object)
|
||||
// mut file := codemodel.new_file(
|
||||
// mut file := code.new_file(
|
||||
// mod: texttools.name_fix(actor.name)
|
||||
// name: obj_name
|
||||
// imports: [
|
||||
@@ -38,7 +38,7 @@ module generator
|
||||
|
||||
// pub fn (a Actor) generate_model_files() ![]VFile {
|
||||
// structs := a.objects.map(it.structure)
|
||||
// return a.objects.map(codemodel.new_file(
|
||||
// return a.objects.map(code.new_file(
|
||||
// mod: texttools.name_fix(a.name)
|
||||
// name: '${texttools.name_fix(it.structure.name)}_model'
|
||||
// // imports: [Import{mod:'freeflowuniverse.herolib.baobab.actor'}]
|
||||
|
||||
@@ -23,7 +23,7 @@ pub fn generate_object_code(actor Struct, object BaseObject) VFile {
|
||||
generate_list_result_struct(actor, object), generate_list_method(actor, object)]
|
||||
|
||||
items << generate_object_methods(actor, object)
|
||||
mut file := codemodel.new_file(
|
||||
mut file := code.new_file(
|
||||
mod: texttools.name_fix(actor.name)
|
||||
name: obj_name
|
||||
imports: [
|
||||
|
||||
@@ -6,7 +6,7 @@ import os
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
// // generate_object_methods generates CRUD actor methods for a provided structure
|
||||
// pub fn (generator ActorGenerator) generate_object_methods(structure codemodel.Struct) []codemodel.Function {
|
||||
// pub fn (generator ActorGenerator) generate_object_methods(structure code.Struct) []code.Function {
|
||||
// return [
|
||||
// generator.generate_get_method(structure),
|
||||
// // generator.generate_set_method(structure),
|
||||
@@ -18,19 +18,19 @@ import freeflowuniverse.herolib.ui.console
|
||||
// generate_object_methods generates CRUD actor methods for a provided structure
|
||||
pub fn test_generate_get_method() {
|
||||
generator := ActorGenerator{'test'}
|
||||
actor_struct := codemodel.Struct{
|
||||
actor_struct := code.Struct{
|
||||
name: 'TestActor'
|
||||
fields: [
|
||||
codemodel.StructField{
|
||||
code.StructField{
|
||||
name: 'test_struct_map'
|
||||
typ: codemodel.Type{
|
||||
typ: code.Type{
|
||||
symbol: 'map[string]&TestStruct'
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
test_struct := codemodel.Struct{
|
||||
test_struct := code.Struct{
|
||||
name: 'TestStruct'
|
||||
}
|
||||
field := get_child_field(
|
||||
@@ -47,27 +47,27 @@ pub fn test_generate_get_method() {
|
||||
}
|
||||
|
||||
// // generate_object_methods generates CRUD actor methods for a provided structure
|
||||
// pub fn (generator ActorGenerator) generate_set_method(structure codemodel.Struct) codemodel.Function {
|
||||
// pub fn (generator ActorGenerator) generate_set_method(structure code.Struct) code.Function {
|
||||
// params_getter := "id := params.get('id')!"
|
||||
// field := generator.get_object_field(structure)
|
||||
// object_getter := 'object := actor.${field.name}[id]'
|
||||
// body := '${params_getter}\n${object_getter}\nreturn object'
|
||||
// get_method := codemodel.Function{
|
||||
// get_method := code.Function{
|
||||
// name: 'get_${generator.model_name}'
|
||||
// description: 'gets the ${structure.name} with the given object id'
|
||||
// receiver: codemodel.Param{
|
||||
// receiver: code.Param{
|
||||
// name: 'actor'
|
||||
// struct_: generator.actor_struct
|
||||
// }
|
||||
// params: [
|
||||
// codemodel.Param{
|
||||
// code.Param{
|
||||
// name: 'id'
|
||||
// typ: codemodel.Type{
|
||||
// typ: code.Type{
|
||||
// symbol: 'string'
|
||||
// }
|
||||
// },
|
||||
// ]
|
||||
// result: codemodel.Result{
|
||||
// result: code.Result{
|
||||
// structure: structure
|
||||
// }
|
||||
// body: body
|
||||
@@ -76,27 +76,27 @@ pub fn test_generate_get_method() {
|
||||
// }
|
||||
|
||||
// // generate_object_methods generates CRUD actor methods for a provided structure
|
||||
// pub fn (generator ActorGenerator) generate_get_method(structure codemodel.Struct) codemodel.Function {
|
||||
// pub fn (generator ActorGenerator) generate_get_method(structure code.Struct) code.Function {
|
||||
// params_getter := "id := params.get('id')!"
|
||||
// field := generator.get_object_field(structure)
|
||||
// object_getter := 'object := actor.${field.name}[id]'
|
||||
// body := '${params_getter}\n${object_getter}\nreturn object'
|
||||
// get_method := codemodel.Function{
|
||||
// get_method := code.Function{
|
||||
// name: 'get_${generator.model_name}'
|
||||
// description: 'gets the ${structure.name} with the given object id'
|
||||
// receiver: codemodel.Param{
|
||||
// receiver: code.Param{
|
||||
// name: 'actor'
|
||||
// struct_: generator.actor_struct
|
||||
// }
|
||||
// params: [
|
||||
// codemodel.Param{
|
||||
// code.Param{
|
||||
// name: 'id'
|
||||
// typ: codemodel.Type{
|
||||
// typ: code.Type{
|
||||
// symbol: 'string'
|
||||
// }
|
||||
// },
|
||||
// ]
|
||||
// result: codemodel.Result{
|
||||
// result: code.Result{
|
||||
// structure: structure
|
||||
// }
|
||||
// body: body
|
||||
@@ -105,27 +105,27 @@ pub fn test_generate_get_method() {
|
||||
// }
|
||||
|
||||
// // generate_object_methods generates CRUD actor methods for a provided structure
|
||||
// pub fn (generator ActorGenerator) generate_delete_method(structure codemodel.Struct) codemodel.Function {
|
||||
// pub fn (generator ActorGenerator) generate_delete_method(structure code.Struct) code.Function {
|
||||
// params_getter := "id := params.get('id')!"
|
||||
// field := generator.get_object_field(structure)
|
||||
// object_getter := 'object := actor.${field.name}[id]'
|
||||
// body := '${params_getter}\n${object_getter}\nreturn object'
|
||||
// get_method := codemodel.Function{
|
||||
// get_method := code.Function{
|
||||
// name: 'get_${generator.model_name}'
|
||||
// description: 'gets the ${structure.name} with the given object id'
|
||||
// receiver: codemodel.Param{
|
||||
// receiver: code.Param{
|
||||
// name: 'actor'
|
||||
// struct_: generator.actor_struct
|
||||
// }
|
||||
// params: [
|
||||
// codemodel.Param{
|
||||
// code.Param{
|
||||
// name: 'id'
|
||||
// typ: codemodel.Type{
|
||||
// typ: code.Type{
|
||||
// symbol: 'string'
|
||||
// }
|
||||
// },
|
||||
// ]
|
||||
// result: codemodel.Result{
|
||||
// result: code.Result{
|
||||
// structure: structure
|
||||
// }
|
||||
// body: body
|
||||
@@ -133,7 +133,7 @@ pub fn test_generate_get_method() {
|
||||
// return get_method
|
||||
// }
|
||||
|
||||
// pub fn (generator ActorGenerator) get_object_field(structure codemodel.Struct) codemodel.StructField {
|
||||
// pub fn (generator ActorGenerator) get_object_field(structure code.Struct) code.StructField {
|
||||
// fields := generator.actor_struct.fields.filter(it.typ.symbol == 'map[string]&${structure.name}')
|
||||
// if fields.len != 1 {
|
||||
// panic('this should never happen')
|
||||
|
||||
@@ -79,7 +79,7 @@ fn generate_new_method_test(actor Struct, object BaseObject) !Function {
|
||||
return Function{
|
||||
name: 'test_new_${object_name}'
|
||||
description: 'news the ${object_type} with the given object id'
|
||||
result: codemodel.Result{
|
||||
result: code.Result{
|
||||
result: true
|
||||
}
|
||||
body: body
|
||||
@@ -105,7 +105,7 @@ fn generate_get_method_test(actor Struct, object BaseObject) !Function {
|
||||
return Function{
|
||||
name: 'test_get_${object_name}'
|
||||
description: 'news the ${object_type} with the given object id'
|
||||
result: codemodel.Result{
|
||||
result: code.Result{
|
||||
result: true
|
||||
}
|
||||
body: body
|
||||
@@ -143,7 +143,7 @@ fn generate_filter_test(actor Struct, object BaseObject) !Function {
|
||||
return Function{
|
||||
name: 'test_filter_${object_name}'
|
||||
description: 'news the ${object_type} with the given object id'
|
||||
result: codemodel.Result{
|
||||
result: code.Result{
|
||||
result: true
|
||||
}
|
||||
body: body
|
||||
|
||||
@@ -23,7 +23,7 @@ pub fn from_openrpc(spec OpenRPC) !ActorSpecification {
|
||||
// for key, schema_ref in openrpc_doc.components.schemas {
|
||||
// struct_obj := schema_ref.to_code()! // Assuming schema_ref.to_code() converts schema to Struct
|
||||
// // objects << BaseObject{
|
||||
// // structure: codemodel.Struct{
|
||||
// // structure: code.Struct{
|
||||
// // name: struct_obj.name
|
||||
// // }
|
||||
// // }
|
||||
|
||||
Reference in New Issue
Block a user