...
This commit is contained in:
@@ -14,12 +14,16 @@ actor_spec := specification.from_openapi(openapi_spec)!
|
||||
|
||||
println(actor_spec)
|
||||
|
||||
// actor_module := generator.generate_actor_module(actor_spec,
|
||||
// interfaces: [.openapi, .http]
|
||||
// )!
|
||||
|
||||
actor_module := generator.generate_actor_module(actor_spec,
|
||||
interfaces: [.openapi, .http]
|
||||
interfaces: [ .http]
|
||||
)!
|
||||
|
||||
actor_module.write(example_dir,
|
||||
format: false
|
||||
format: true
|
||||
overwrite: true
|
||||
compile: false
|
||||
)!
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -w -n -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.baobab.specification
|
||||
import freeflowuniverse.herolib.schemas.openapi
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -w -n -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.baobab.specification
|
||||
import freeflowuniverse.herolib.schemas.openrpc
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -w -n -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import json
|
||||
import freeflowuniverse.herolib.baobab.specification
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -w -n -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import json
|
||||
import freeflowuniverse.herolib.baobab.specification
|
||||
|
||||
52
examples/schemas/example/generate_model.vsh
Executable file
52
examples/schemas/example/generate_model.vsh
Executable file
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import os
|
||||
import freeflowuniverse.herolib.core.code { Alias, Struct }
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
import freeflowuniverse.herolib.schemas.openrpc
|
||||
import freeflowuniverse.herolib.schemas.openrpc.codegen {generate_model}
|
||||
|
||||
const doc_path = '${os.dir(@FILE)}/testdata/openrpc.json'
|
||||
|
||||
mut doc_file := pathlib.get_file(path: doc_path)!
|
||||
content := doc_file.read()!
|
||||
object := openrpc.decode(content)!
|
||||
model := generate_model(object)!
|
||||
|
||||
assert model.len == 3
|
||||
assert model[0] is Alias
|
||||
pet_id := model[0] as Alias
|
||||
assert pet_id.name == 'PetId'
|
||||
println(pet_id)
|
||||
$dbg;
|
||||
|
||||
|
||||
// assert pet_id.typ.symbol == 'int'
|
||||
|
||||
// assert model[1] is Struct
|
||||
// pet_struct := model[1] as Struct
|
||||
// assert pet_struct.name == 'Pet'
|
||||
// assert pet_struct.fields.len == 3
|
||||
|
||||
// // test field is `id PetId @[required]`
|
||||
// assert pet_struct.fields[0].name == 'id'
|
||||
// assert pet_struct.fields[0].typ.symbol == 'PetId'
|
||||
// assert pet_struct.fields[0].attrs.len == 1
|
||||
// assert pet_struct.fields[0].attrs[0].name == 'required'
|
||||
|
||||
// // test field is `name string @[required]`
|
||||
// assert pet_struct.fields[1].name == 'name'
|
||||
// assert pet_struct.fields[1].typ.symbol == 'string'
|
||||
// assert pet_struct.fields[1].attrs.len == 1
|
||||
// assert pet_struct.fields[1].attrs[0].name == 'required'
|
||||
|
||||
// // test field is `tag string`
|
||||
// assert pet_struct.fields[2].name == 'tag'
|
||||
// assert pet_struct.fields[2].typ.symbol == 'string'
|
||||
// assert pet_struct.fields[2].attrs.len == 0
|
||||
|
||||
// assert model[2] is Alias
|
||||
// pets_alias := model[2] as Alias
|
||||
// assert pets_alias.name == 'Pets'
|
||||
// assert pets_alias.typ.symbol == '[]Pet'
|
||||
// }
|
||||
205
examples/schemas/example/testdata/openrpc.json
vendored
Normal file
205
examples/schemas/example/testdata/openrpc.json
vendored
Normal file
@@ -0,0 +1,205 @@
|
||||
{
|
||||
"openrpc": "1.0.0-rc1",
|
||||
"info": {
|
||||
"version": "1.0.0",
|
||||
"title": "Petstore",
|
||||
"license": {
|
||||
"name": "MIT"
|
||||
}
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"name": "localhost",
|
||||
"url": "http://localhost:8080"
|
||||
}
|
||||
],
|
||||
"methods": [
|
||||
{
|
||||
"name": "list_pets",
|
||||
"summary": "List all pets",
|
||||
"tags": [
|
||||
{
|
||||
"name": "pets"
|
||||
}
|
||||
],
|
||||
"params": [
|
||||
{
|
||||
"name": "limit",
|
||||
"description": "How many items to return at one time (max 100)",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "integer",
|
||||
"minimum": 1
|
||||
}
|
||||
}
|
||||
],
|
||||
"result": {
|
||||
"name": "pets",
|
||||
"description": "A paged array of pets",
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/Pets"
|
||||
}
|
||||
},
|
||||
"errors": [
|
||||
{
|
||||
"code": 100,
|
||||
"message": "pets busy"
|
||||
}
|
||||
],
|
||||
"examples": [
|
||||
{
|
||||
"name": "listPetExample",
|
||||
"description": "List pet example",
|
||||
"params": [
|
||||
{
|
||||
"name": "limit",
|
||||
"value": 1
|
||||
}
|
||||
],
|
||||
"result": {
|
||||
"name": "listPetResultExample",
|
||||
"value": [
|
||||
{
|
||||
"id": 7,
|
||||
"name": "fluffy",
|
||||
"tag": "poodle"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "create_pet",
|
||||
"summary": "Create a pet",
|
||||
"tags": [
|
||||
{
|
||||
"name": "pets"
|
||||
}
|
||||
],
|
||||
"params": [
|
||||
{
|
||||
"name": "newPetName",
|
||||
"description": "Name of pet to create",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "newPetTag",
|
||||
"description": "Pet tag to create",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"examples": [
|
||||
{
|
||||
"name": "createPetExample",
|
||||
"description": "Create pet example",
|
||||
"params": [
|
||||
{
|
||||
"name": "newPetName",
|
||||
"value": "fluffy"
|
||||
},
|
||||
{
|
||||
"name": "tag",
|
||||
"value": "poodle"
|
||||
}
|
||||
],
|
||||
"result": {
|
||||
"name": "listPetResultExample",
|
||||
"value": 7
|
||||
}
|
||||
}
|
||||
],
|
||||
"result": {
|
||||
"$ref": "#/components/contentDescriptors/PetId"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "get_pet",
|
||||
"summary": "Info for a specific pet",
|
||||
"tags": [
|
||||
{
|
||||
"name": "pets"
|
||||
}
|
||||
],
|
||||
"params": [
|
||||
{
|
||||
"$ref": "#/components/contentDescriptors/PetId"
|
||||
}
|
||||
],
|
||||
"result": {
|
||||
"name": "pet",
|
||||
"description": "Expected response to a valid request",
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/Pet"
|
||||
}
|
||||
},
|
||||
"examples": [
|
||||
{
|
||||
"name": "getPetExample",
|
||||
"description": "get pet example",
|
||||
"params": [
|
||||
{
|
||||
"name": "petId",
|
||||
"value": 7
|
||||
}
|
||||
],
|
||||
"result": {
|
||||
"name": "getPetExampleResult",
|
||||
"value": {
|
||||
"name": "fluffy",
|
||||
"tag": "poodle",
|
||||
"id": 7
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"components": {
|
||||
"contentDescriptors": {
|
||||
"PetId": {
|
||||
"name": "petId",
|
||||
"required": true,
|
||||
"description": "The id of the pet to retrieve",
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/PetId"
|
||||
}
|
||||
}
|
||||
},
|
||||
"schemas": {
|
||||
"PetId": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
},
|
||||
"Pet": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"id",
|
||||
"name"
|
||||
],
|
||||
"properties": {
|
||||
"id": {
|
||||
"$ref": "#/components/schemas/PetId"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"tag": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Pets": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/Pet"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user