Open rssdev10 opened 1 year ago
That's a great idea, thanks! Are you familiar with the OpenAPI.jl package (as I'm not). Could you help with this?
Hi, yes, we are working with OpenAPI.jl.
E.g. there is the specification - https://github.com/OpenSesame/GptSearchPlugin/blob/main/resources/dev-openai/.well-known/openapi.yaml
openapi-generator
can be installed by different ways - https://openapi-generator.tech/docs/installation/ or be used directly as a openapi-generator-cli java-jar file from https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/.
And, there is a script for generating the code: https://github.com/OpenSesame/GptSearchPlugin/blob/main/scripts/openapi_generator.sh
For this generated code some additional methods should be implemented. E.g. in our sample, these methods are mentioned here - https://github.com/OpenSesame/GptSearchPlugin/blob/main/src/generated/src/GptPluginServer.jl#L8-L16
And, the routes should be registered: https://github.com/OpenSesame/GptSearchPlugin/blob/main/src/generated/src/GptPluginServer.jl#L32-L51
As a result, we created https://github.com/OpenSesame/GptSearchPlugin/blob/main/src/server.jl
The service entry point in our case is https://github.com/OpenSesame/GptSearchPlugin/blob/main/ws_run.jl
More general examples are available at https://github.com/JuliaComputing/OpenAPI.jl/tree/main/test/server And I think @tanmaykm, who is the author of OpenAPI.jl, can also comment on it.
Thank you for the details @rssdev10 - very helpful!
Actually I see two scenarios here:
Thanks for initiating this. It will be great to have OpenAPI and Genie work together. I am yet to go through the details, but am happy to pitch in wherever needed.
OpenAPI is a common way to describe API specification both for server and clients. The package https://github.com/JuliaComputing/OpenAPI.jl as well as https://openapi-generator.tech/docs/generators/julia-server/ provides a server code generation with data structures both for requests and responses. And, the code provides data parsing, validation and serializing of the results.
But OpenAPI.jl doesn't provide any functionality for authentication, CORS, routing and logging. These parts of the code should be implemented manually. See the example - https://github.com/OpenSesame/GptSearchPlugin/blob/main/src/server.jl or https://github.com/JuliaComputing/OpenAPI.jl/blob/main/test/server/petstore_v3/petstore_server.jl
It would be good to have a way to reuse components of Genie to have an easy way to write web services based on external OpenAPI specification.