diff --git a/examples/baobab/generator/openapi_e2e/generate_actor_module.vsh b/examples/baobab/generator/openapi_e2e/generate_actor_module.vsh index 652fe92c..50ac7785 100755 --- a/examples/baobab/generator/openapi_e2e/generate_actor_module.vsh +++ b/examples/baobab/generator/openapi_e2e/generate_actor_module.vsh @@ -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 )! diff --git a/examples/baobab/specification/openapi_to_specification.vsh b/examples/baobab/specification/openapi_to_specification.vsh index 18447dd8..7035ab3c 100755 --- a/examples/baobab/specification/openapi_to_specification.vsh +++ b/examples/baobab/specification/openapi_to_specification.vsh @@ -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 diff --git a/examples/baobab/specification/openrpc_to_specification.vsh b/examples/baobab/specification/openrpc_to_specification.vsh index f40bd9e5..cabce42c 100755 --- a/examples/baobab/specification/openrpc_to_specification.vsh +++ b/examples/baobab/specification/openrpc_to_specification.vsh @@ -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 diff --git a/examples/baobab/specification/specification_to_openapi.vsh b/examples/baobab/specification/specification_to_openapi.vsh index 37a54d62..f60c1e1b 100755 --- a/examples/baobab/specification/specification_to_openapi.vsh +++ b/examples/baobab/specification/specification_to_openapi.vsh @@ -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 diff --git a/examples/baobab/specification/specification_to_openrpc.vsh b/examples/baobab/specification/specification_to_openrpc.vsh index 91386186..2eb079d8 100755 --- a/examples/baobab/specification/specification_to_openrpc.vsh +++ b/examples/baobab/specification/specification_to_openrpc.vsh @@ -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 diff --git a/examples/schemas/example/generate_model.vsh b/examples/schemas/example/generate_model.vsh new file mode 100755 index 00000000..c2aac606 --- /dev/null +++ b/examples/schemas/example/generate_model.vsh @@ -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' +// } diff --git a/examples/schemas/example/testdata/openrpc.json b/examples/schemas/example/testdata/openrpc.json new file mode 100644 index 00000000..50c6f382 --- /dev/null +++ b/examples/schemas/example/testdata/openrpc.json @@ -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" + } + } + } + } +} diff --git a/lib/schemas/jsonrpc/handler.v b/lib/schemas/jsonrpc/handler.v index 2ea78e82..77f7859d 100644 --- a/lib/schemas/jsonrpc/handler.v +++ b/lib/schemas/jsonrpc/handler.v @@ -1,6 +1,5 @@ module jsonrpc -import log import net.websocket // This file implements a JSON-RPC 2.0 handler for WebSocket servers. diff --git a/lib/schemas/jsonrpc/unixsocket.v b/lib/schemas/jsonrpc/unixsocket.v index 61d2045c..bd83d1a6 100644 --- a/lib/schemas/jsonrpc/unixsocket.v +++ b/lib/schemas/jsonrpc/unixsocket.v @@ -2,7 +2,6 @@ module jsonrpc import net.unix import time -import freeflowuniverse.herolib.ui.console import net // UnixSocketTransport implements the IRPCTransportClient interface for Unix domain sockets