Genie.jl icon indicating copy to clipboard operation
Genie.jl copied to clipboard

integration with OpenAPI

Open rssdev10 opened this issue 11 months ago • 5 comments

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.

rssdev10 avatar Aug 02 '23 18:08 rssdev10

That's a great idea, thanks! Are you familiar with the OpenAPI.jl package (as I'm not). Could you help with this?

essenciary avatar Aug 03 '23 13:08 essenciary

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.

rssdev10 avatar Aug 03 '23 15:08 rssdev10

Thank you for the details @rssdev10 - very helpful!

essenciary avatar Aug 03 '23 16:08 essenciary

Actually I see two scenarios here:

  1. Keep the generated with OpenAPI code as is. And implement a service with components based on Genie (routing, security, logging).
  2. Implement new templates for code generation based on the code https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator/src/main/resources/julia-server . But in this case the question will be - how to keep consistent the Julia code in general for generating and validating data structures. It would be really good to have the only version of this code.

rssdev10 avatar Aug 03 '23 17:08 rssdev10

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.

tanmaykm avatar Aug 04 '23 15:08 tanmaykm