feat: add tool to generate code from spec #75
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add a few methods that help invoke the code generator providing a spec file and generating Julia code.
The OpenAPI Generator Docker image is a code generator that can generate client libraries, server stubs, and API documentation from an OpenAPI Specification. It can also be hosted as a service. OpenAPI.jl will now make use of that to provide a way to generate code. Methos
OpenAPI.generate
will generate code from an OpenAPI specification. It can be pointed at a server hosted on the local machine or a remote server. The OpenAPI Generator must be running at the specifiedgenerator_host
. Returns the folder containing generated code.Arguments:
spec
: The OpenAPI specification as a Dict. It can be obtained by parsing a JSON or YAML file usingJSON.parse
orYAML.load
.Optional arguments:
type
: The type of code to generate. Must be:client
or:server
. Defaults to:client
.package_name
: The name of the package to generate. Defaults to "APIClient".export_models
: Whether to export models. Defaults to false.export_operations
: Whether to export operations. Defaults to false.output_dir
: The directory to save the generated code. Defaults to a temporary directory. Directory will be created if it does not exist.generator_host
: The host of the OpenAPI Generator. Defaults toGeneratorHost.Local
(which points tohttp://localhost:8080
).The
generator_host
can be pointed to any other URL where the OpenAPI Generator is running, e.g.https://openapigen.myorg.com
. Other possible pre-defined values ofgenerator_host
, which point to the public service hosted by OpenAPI org are:OpenAPI.GeneratorHost.OpenAPIGeneratorTech.Stable
: Runs a stable version of the OpenAPI Generator at https://api.openapi-generator.tech.OpenAPI.GeneratorHost.OpenAPIGeneratorTech.Master
: Runs the latest version of the OpenAPI Generator at https://api-latest-master.openapi-generator.tech.A locally hosted generator service is preferred by default for privacy reasons. One can be started on the local machine using
OpenAPI.openapi_generator
. It uses theopenapitools/openapi-generator-online
docker image and requires docker engine to be installed. UseOpenAPI.stop_openapi_generator
to stop the local generator service after use.