Conversation
Add a few methods that help invoke the code generator providing a spec file and generating Julia code. The [OpenAPI Generator Docker image](https://hub.docker.com/r/openapitools/openapi-generator-cli) 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 specified `generator_host`. Returns the folder containing generated code. ```julia OpenAPI.generate( spec::Dict{String,Any}; type::Symbol=:client, package_name::AbstractString="APIClient", export_models::Bool=false, export_operations::Bool=false, output_dir::AbstractString="", generator_host::AbstractString=GeneratorHost.Local ) ``` Arguments: - `spec`: The OpenAPI specification as a Dict. It can be obtained by parsing a JSON or YAML file using `JSON.parse` or `YAML.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 to `GeneratorHost.Local` (which points to `http://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 of `generator_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 the `openapitools/openapi-generator-online` docker image and requires docker engine to be installed. Use `OpenAPI.stop_openapi_generator` to stop the local generator service after use. ```julia OpenAPI.openapi_generator(; port::Int=8080, # port to use use_sudo::Bool=false # whether to use sudo while invoking docker ) OpenAPI.stop_openapi_generator(; use_sudo::Bool=false # whether to use sudo while invoking docker ) ```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.generatewill 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.parseorYAML.load.Optional arguments:
type: The type of code to generate. Must be:clientor: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_hostcan 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-onlinedocker image and requires docker engine to be installed. UseOpenAPI.stop_openapi_generatorto stop the local generator service after use.