add example actor generation from example specification
This commit is contained in:
@@ -5,150 +5,196 @@ import freeflowuniverse.herolib.baobab.specification
|
||||
import freeflowuniverse.herolib.schemas.openrpc
|
||||
import freeflowuniverse.herolib.schemas.jsonschema
|
||||
import os
|
||||
import x.json2 as json {Any}
|
||||
|
||||
const actor_spec = specification.ActorSpecification{
|
||||
name: 'Pet Store'
|
||||
description: 'A sample API for a pet store'
|
||||
structure: code.Struct{}
|
||||
interfaces: [.openrpc]
|
||||
interfaces: [.openapi]
|
||||
methods: [
|
||||
specification.ActorMethod{
|
||||
name: 'list_pets'
|
||||
name: 'listPets'
|
||||
summary: 'List all pets'
|
||||
parameters: [openrpc.ContentDescriptor{
|
||||
name: 'limit'
|
||||
description: 'How many items to return at one time (max 100)'
|
||||
required: false
|
||||
schema: jsonschema.SchemaRef(jsonschema.Schema{
|
||||
typ: 'integer'
|
||||
minimum: 1
|
||||
example: openrpc.ExamplePairing{
|
||||
params: [
|
||||
openrpc.ExampleRef(openrpc.Example{
|
||||
name: 'Example limit'
|
||||
description: 'Example Maximum number of pets to return'
|
||||
value: 10
|
||||
})
|
||||
]
|
||||
result: openrpc.ExampleRef(openrpc.Example{
|
||||
name: 'Example response'
|
||||
value: json.raw_decode('[
|
||||
{"id": 1, "name": "Fluffy", "tag": "dog"},
|
||||
{"id": 2, "name": "Whiskers", "tag": "cat"}
|
||||
]')!
|
||||
})
|
||||
}]
|
||||
}
|
||||
parameters: [
|
||||
openrpc.ContentDescriptor{
|
||||
name: 'limit'
|
||||
summary: 'Maximum number of pets to return'
|
||||
description: 'Maximum number of pets to return'
|
||||
required: false
|
||||
schema: jsonschema.SchemaRef(jsonschema.Schema{
|
||||
...jsonschema.schema_u32,
|
||||
example: 10
|
||||
})
|
||||
}
|
||||
]
|
||||
result: openrpc.ContentDescriptor{
|
||||
name: 'pets'
|
||||
description: 'A paged array of pets'
|
||||
schema: jsonschema.SchemaRef(jsonschema.Schema{
|
||||
typ: 'array'
|
||||
items: jsonschema.Items(jsonschema.SchemaRef(jsonschema.Reference{
|
||||
ref: '#/components/schemas/Pet'
|
||||
items: jsonschema.Items(jsonschema.SchemaRef(jsonschema.Schema{
|
||||
id: 'pet'
|
||||
title: 'Pet'
|
||||
typ: 'object'
|
||||
properties: {
|
||||
'id': jsonschema.SchemaRef(jsonschema.Reference{
|
||||
ref: '#/components/schemas/PetId'
|
||||
}),
|
||||
'name': jsonschema.SchemaRef(jsonschema.Schema{
|
||||
typ: 'string'
|
||||
}),
|
||||
'tag': jsonschema.SchemaRef(jsonschema.Schema{
|
||||
typ: 'string'
|
||||
})
|
||||
}
|
||||
required: ['id', 'name']
|
||||
}))
|
||||
})
|
||||
}
|
||||
},
|
||||
specification.ActorMethod{
|
||||
name: 'create_pet'
|
||||
summary: 'Create a pet'
|
||||
parameters: [
|
||||
openrpc.ContentDescriptor{
|
||||
name: 'newPetName'
|
||||
description: 'Name of pet to create'
|
||||
required: true
|
||||
schema: jsonschema.SchemaRef(jsonschema.Schema{
|
||||
typ: 'string'
|
||||
})
|
||||
},
|
||||
openrpc.ContentDescriptor{
|
||||
name: 'newPetTag'
|
||||
description: 'Pet tag to create'
|
||||
schema: jsonschema.SchemaRef(jsonschema.Schema{
|
||||
typ: 'string'
|
||||
})
|
||||
errors: [
|
||||
openrpc.ErrorSpec{
|
||||
code: 400
|
||||
message: 'Invalid request'
|
||||
}
|
||||
]
|
||||
result: openrpc.ContentDescriptor{
|
||||
name: 'petId'
|
||||
description: 'The ID of the created pet'
|
||||
schema: jsonschema.SchemaRef(jsonschema.Schema{
|
||||
typ: 'integer'
|
||||
})
|
||||
}
|
||||
},
|
||||
specification.ActorMethod{
|
||||
name: 'get_pet'
|
||||
summary: 'Info for a specific pet'
|
||||
parameters: [openrpc.ContentDescriptor{
|
||||
name: 'petId'
|
||||
description: 'The ID of the pet to retrieve'
|
||||
name: 'createPet'
|
||||
summary: 'Create a new pet'
|
||||
example: openrpc.ExamplePairing{
|
||||
result: openrpc.ExampleRef(openrpc.Example{
|
||||
name: 'Example response'
|
||||
value: '[]'
|
||||
})
|
||||
}
|
||||
result: openrpc.ContentDescriptor{
|
||||
name: 'result'
|
||||
description: 'The response of the operation.'
|
||||
required: true
|
||||
schema: jsonschema.SchemaRef(jsonschema.Schema{
|
||||
typ: 'integer'
|
||||
})
|
||||
}]
|
||||
result: openrpc.ContentDescriptor{
|
||||
name: 'pet'
|
||||
description: 'The pet details'
|
||||
schema: jsonschema.SchemaRef(jsonschema.Reference{
|
||||
ref: '#/components/schemas/Pet'
|
||||
})
|
||||
}
|
||||
errors: [
|
||||
openrpc.ErrorSpec{
|
||||
code: 400
|
||||
message: 'Invalid input'
|
||||
}
|
||||
]
|
||||
},
|
||||
specification.ActorMethod{
|
||||
name: 'update_pet'
|
||||
summary: 'Update a pet'
|
||||
name: 'getPet'
|
||||
summary: 'Get a pet by ID'
|
||||
example: openrpc.ExamplePairing{
|
||||
params: [
|
||||
openrpc.ExampleRef(openrpc.Example{
|
||||
name: 'Example petId'
|
||||
description: 'Example ID of the pet to retrieve'
|
||||
value: 1
|
||||
})
|
||||
]
|
||||
result: openrpc.ExampleRef(openrpc.Example{
|
||||
name: 'Example response'
|
||||
value: json.raw_decode('{"id": 1, "name": "Fluffy", "tag": "dog"}')!
|
||||
})
|
||||
}
|
||||
parameters: [
|
||||
openrpc.ContentDescriptor{
|
||||
name: 'petId'
|
||||
description: 'The ID of the pet to update'
|
||||
summary: 'ID of the pet to retrieve'
|
||||
description: 'ID of the pet to retrieve'
|
||||
required: true
|
||||
schema: jsonschema.SchemaRef(jsonschema.Schema{
|
||||
typ: 'integer'
|
||||
})
|
||||
},
|
||||
openrpc.ContentDescriptor{
|
||||
name: 'updatedPetName'
|
||||
description: 'New name for the pet'
|
||||
schema: jsonschema.SchemaRef(jsonschema.Schema{
|
||||
typ: 'string'
|
||||
})
|
||||
},
|
||||
openrpc.ContentDescriptor{
|
||||
name: 'updatedPetTag'
|
||||
description: 'New tag for the pet'
|
||||
schema: jsonschema.SchemaRef(jsonschema.Schema{
|
||||
typ: 'string'
|
||||
...jsonschema.schema_u32,
|
||||
format:'uint32'
|
||||
example: 1
|
||||
})
|
||||
}
|
||||
]
|
||||
result: openrpc.ContentDescriptor{
|
||||
name: 'pet'
|
||||
description: 'The updated pet object'
|
||||
name: 'result'
|
||||
description: 'The response of the operation.'
|
||||
required: true
|
||||
schema: jsonschema.SchemaRef(jsonschema.Reference{
|
||||
ref: '#/components/schemas/Pet'
|
||||
})
|
||||
}
|
||||
errors: [
|
||||
openrpc.ErrorSpec{
|
||||
code: 404
|
||||
message: 'Pet not found'
|
||||
}
|
||||
]
|
||||
},
|
||||
specification.ActorMethod{
|
||||
name: 'delete_pet'
|
||||
summary: 'Delete a pet'
|
||||
parameters: [openrpc.ContentDescriptor{
|
||||
name: 'petId'
|
||||
description: 'The ID of the pet to delete'
|
||||
name: 'deletePet'
|
||||
summary: 'Delete a pet by ID'
|
||||
example: openrpc.ExamplePairing{
|
||||
params: [
|
||||
openrpc.ExampleRef(openrpc.Example{
|
||||
name: 'Example petId'
|
||||
description: 'Example ID of the pet to delete'
|
||||
value: 1
|
||||
})
|
||||
]
|
||||
}
|
||||
parameters: [
|
||||
openrpc.ContentDescriptor{
|
||||
name: 'petId'
|
||||
summary: 'ID of the pet to delete'
|
||||
description: 'ID of the pet to delete'
|
||||
required: true
|
||||
schema: jsonschema.SchemaRef(jsonschema.Schema{
|
||||
...jsonschema.schema_u32,
|
||||
example: 1
|
||||
})
|
||||
}
|
||||
]
|
||||
result: openrpc.ContentDescriptor{
|
||||
name: 'result'
|
||||
description: 'The response of the operation.'
|
||||
required: true
|
||||
schema: jsonschema.SchemaRef(jsonschema.Schema{
|
||||
typ: 'integer'
|
||||
})
|
||||
}]
|
||||
}
|
||||
errors: [
|
||||
openrpc.ErrorSpec{
|
||||
code: 404
|
||||
message: 'Pet not found'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
objects: [specification.BaseObject{
|
||||
schema: jsonschema.Schema{
|
||||
id: 'pet'
|
||||
title: 'Pet'
|
||||
description: 'A pet object'
|
||||
typ: 'object'
|
||||
properties: {
|
||||
'id': jsonschema.SchemaRef(jsonschema.Schema{
|
||||
typ: 'integer'
|
||||
}),
|
||||
'name': jsonschema.SchemaRef(jsonschema.Schema{
|
||||
typ: 'string'
|
||||
}),
|
||||
'tag': jsonschema.SchemaRef(jsonschema.Schema{
|
||||
typ: 'string'
|
||||
})
|
||||
objects: [
|
||||
specification.BaseObject{
|
||||
schema: jsonschema.Schema{
|
||||
title: 'Pet'
|
||||
typ: 'object'
|
||||
properties: {
|
||||
'id': jsonschema.schema_u32,
|
||||
'name': jsonschema.SchemaRef(jsonschema.Schema{
|
||||
typ: 'string'
|
||||
}),
|
||||
'tag': jsonschema.SchemaRef(jsonschema.Schema{
|
||||
typ: 'string'
|
||||
})
|
||||
}
|
||||
required: ['id', 'name']
|
||||
}
|
||||
required: ['id', 'name']
|
||||
}
|
||||
}]
|
||||
]
|
||||
}
|
||||
|
||||
const destination = '${os.dir(@FILE)}/testdata'
|
||||
@@ -159,7 +205,6 @@ fn test_generate_plain_actor_module() {
|
||||
actor_module.write(destination,
|
||||
format: true
|
||||
overwrite: true
|
||||
compile: true
|
||||
test: true
|
||||
)!
|
||||
}
|
||||
@@ -170,7 +215,6 @@ fn test_generate_actor_module_with_openrpc_interface() {
|
||||
actor_module.write(destination,
|
||||
format: true
|
||||
overwrite: true
|
||||
compile: true
|
||||
test: true
|
||||
)!
|
||||
}
|
||||
@@ -183,7 +227,6 @@ fn test_generate_actor_module_with_openapi_interface() {
|
||||
actor_module.write(destination,
|
||||
format: true
|
||||
overwrite: true
|
||||
compile: true
|
||||
test: true
|
||||
)!
|
||||
}
|
||||
@@ -196,7 +239,6 @@ fn test_generate_actor_module_with_all_interfaces() {
|
||||
actor_module.write(destination,
|
||||
format: true
|
||||
overwrite: true
|
||||
compile: true
|
||||
test: true
|
||||
)!
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user