Files
herolib/libarchive/baobab/specification/to_openapi_test.v
2025-10-12 12:30:19 +03:00

184 lines
3.9 KiB
V

module specification
import incubaid.herolib.develop.codetools as code
import incubaid.herolib.schemas.jsonschema { Schema, SchemaRef }
import incubaid.herolib.schemas.openapi
import incubaid.herolib.schemas.openrpc
const actor_spec = ActorSpecification{
name: 'Petstore'
structure: code.Struct{
is_pub: false
}
interfaces: [.openrpc]
methods: [
ActorMethod{
name: 'list_pets'
summary: 'List all pets'
parameters: [
openrpc.ContentDescriptor{
name: 'limit'
description: 'How many items to return at one time (max 100)'
required: false
schema: SchemaRef(Schema{
typ: 'integer'
minimum: 1
})
},
]
result: openrpc.ContentDescriptor{
name: 'pets'
description: 'A paged array of pets'
schema: SchemaRef(Schema{
typ: 'array'
items: jsonschema.Items(SchemaRef(Schema{
typ: 'object'
properties: {
'id': SchemaRef(jsonschema.Reference{
ref: '#/components/schemas/PetId'
})
'name': SchemaRef(Schema{
typ: 'string'
})
'tag': SchemaRef(Schema{
typ: 'string'
})
}
required: [
'id',
'name',
]
}))
})
}
},
ActorMethod{
name: 'create_pet'
summary: 'Create a pet'
parameters: [
openrpc.ContentDescriptor{
name: 'newPetName'
description: 'Name of pet to create'
required: true
schema: SchemaRef(Schema{
typ: 'string'
})
},
openrpc.ContentDescriptor{
name: 'newPetTag'
description: 'Pet tag to create'
schema: SchemaRef(Schema{
typ: 'string'
})
},
]
},
ActorMethod{
name: 'get_pet'
summary: 'Info for a specific pet'
result: openrpc.ContentDescriptor{
name: 'pet'
description: 'Expected response to a valid request'
schema: SchemaRef(Schema{
typ: 'object'
properties: {
'id': SchemaRef(jsonschema.Reference{
ref: '#/components/schemas/PetId'
})
'name': SchemaRef(Schema{
typ: 'string'
})
'tag': SchemaRef(Schema{
typ: 'string'
})
}
required: [
'id',
'name',
]
})
}
},
ActorMethod{
name: 'update_pet'
summary: 'Update a pet'
parameters: [
openrpc.ContentDescriptor{
name: 'updatedPetName'
description: 'New name for the pet'
required: true
schema: SchemaRef(Schema{
typ: 'string'
})
},
openrpc.ContentDescriptor{
name: 'updatedPetTag'
description: 'New tag for the pet'
schema: SchemaRef(Schema{
typ: 'string'
})
},
]
result: openrpc.ContentDescriptor{
name: 'pet'
description: 'Updated pet object'
schema: SchemaRef(Schema{
typ: 'object'
properties: {
'id': SchemaRef(jsonschema.Reference{
ref: '#/components/schemas/PetId'
})
'name': SchemaRef(Schema{
typ: 'string'
})
'tag': SchemaRef(Schema{
typ: 'string'
})
}
required: [
'id',
'name',
]
})
}
},
ActorMethod{
name: 'delete_pet'
summary: 'Delete a pet'
result: openrpc.ContentDescriptor{
name: 'success'
description: 'Boolean indicating success'
schema: SchemaRef(Schema{
typ: 'boolean'
})
}
},
]
objects: [
BaseObject{
schema: Schema{
id: 'pet'
title: 'Pet'
typ: 'object'
properties: {
'id': SchemaRef(jsonschema.Reference{
ref: '#/components/schemas/PetId'
})
'name': SchemaRef(Schema{
typ: 'string'
})
'tag': SchemaRef(Schema{
typ: 'string'
})
}
required: ['id', 'name']
}
},
]
}
// Converts ActorSpecification to OpenAPI
pub fn test_specification_to_openapi() {
panic(actor_spec.to_openapi())
}