|
| 1 | +# Tools |
| 2 | + |
| 3 | +## Swagger UI |
| 4 | + |
| 5 | +[Swagger UI](https://swagger.io/tools/swagger-ui/) allows visualization and interaction with the API’s resources without having any of the implementation logic in place. OpenAPI.jl includes convenience methods to launch Swagger UI from Julia. |
| 6 | + |
| 7 | +Use `OpenAPI.swagger_ui` to open Swagger UI. It uses the standard `swaggerapi/swagger-ui` docker image and requires docker engine to be installed. |
| 8 | + |
| 9 | +```julia |
| 10 | +# specify a specification file to start with |
| 11 | +OpenAPI.swagger_ui( |
| 12 | + spec::AbstractString; # the OpenAPI specification to use |
| 13 | + port::Int=8080, # port to use |
| 14 | + use_sudo::Bool=false # whether to use sudo while invoking docker |
| 15 | +) |
| 16 | + |
| 17 | +# specify a folder and specification file name to start with |
| 18 | +OpenAPI.swagger_ui( |
| 19 | + spec_dir::AbstractString; # folder containing the specification file |
| 20 | + spec_file::AbstractString; # the specification file |
| 21 | + port::Int=8080, # port to use |
| 22 | + use_sudo::Bool=false # whether to use sudo while invoking docker |
| 23 | +) |
| 24 | +``` |
| 25 | + |
| 26 | +It returns the URL that should be opened in a browser to access the Swagger UI. Combining it with a tool like [DefaultApplication.jl](https://github.com/tpapp/DefaultApplication.jl) can help open a browser tab directly from Julia. |
| 27 | + |
| 28 | +```julia |
| 29 | +DefaultApplication.open(OpenAPI.swagger_ui("/my/openapi/spec.json")) |
| 30 | +``` |
| 31 | + |
| 32 | +To stop the Swagger UI container, use `OpenAPI.stop_swagger_ui`. |
| 33 | + |
| 34 | +```julia |
| 35 | +OpenAPI.stop_swagger_ui(; |
| 36 | + use_sudo::Bool=false # whether to use sudo while invoking docker |
| 37 | +) |
| 38 | +``` |
| 39 | + |
| 40 | +## Swagger Editor |
| 41 | + |
| 42 | +[Swagger Editor](https://swagger.io/tools/swagger-editor/) allows editing of OpenAPI specifications and simultaneous visualization and interaction with the API’s resources without having any of the client implementation logic in place. OpenAPI.jl includes convenience methods to launch Swagger Editor from Julia. |
| 43 | + |
| 44 | +Use `OpenAPI.swagger_editor` to open Swagger Editor. It uses the standard `swaggerapi/swagger-editor` docker image and requires docker engine to be installed. |
| 45 | + |
| 46 | +```julia |
| 47 | +# specify a specification file to start with |
| 48 | +OpenAPI.swagger_editor( |
| 49 | + spec::AbstractString; # the OpenAPI specification to use |
| 50 | + port::Int=8080, # port to use |
| 51 | + use_sudo::Bool=false # whether to use sudo while invoking docker |
| 52 | +) |
| 53 | + |
| 54 | +# specify a folder and specification file name to start with |
| 55 | +OpenAPI.swagger_editor( |
| 56 | + spec_dir::AbstractString; # folder containing the specification file |
| 57 | + spec_file::AbstractString; # the specification file |
| 58 | + port::Int=8080, # port to use |
| 59 | + use_sudo::Bool=false # whether to use sudo while invoking docker |
| 60 | +) |
| 61 | + |
| 62 | +# start without specifying any initial specification file |
| 63 | +OpenAPI.swagger_editor( |
| 64 | + port::Int=8080, # port to use |
| 65 | + use_sudo::Bool=false # whether to use sudo while invoking docker |
| 66 | +) |
| 67 | +``` |
| 68 | + |
| 69 | +It returns the URL that should be opened in a browser to access the Swagger UI. Combining it with a tool like [DefaultApplication.jl](https://github.com/tpapp/DefaultApplication.jl) can help open a browser tab directly from Julia. |
| 70 | + |
| 71 | +```julia |
| 72 | +DefaultApplication.open(OpenAPI.swagger_editor("/my/openapi/spec.json")) |
| 73 | +``` |
| 74 | + |
| 75 | +To stop the Swagger Editor container, use `OpenAPI.stop_swagger_editor`. |
| 76 | + |
| 77 | +```julia |
| 78 | +OpenAPI.stop_swagger_editor(; |
| 79 | + use_sudo::Bool=false # whether to use sudo while invoking docker |
| 80 | +) |
| 81 | +``` |
| 82 | + |
| 83 | +## Spectral Linter |
| 84 | + |
| 85 | +[Spectral](https://stoplight.io/open-source/spectral) is an open-source API style guide enforcer and linter. OpenAPI.jl includes a convenience method to use the Spectral OpenAPI linter from Julia. |
| 86 | + |
| 87 | +```julia |
| 88 | +# specify a specification file to start with |
| 89 | +OpenAPI.lint( |
| 90 | + spec::AbstractString; # the OpenAPI specification to use |
| 91 | + use_sudo::Bool=false # whether to use sudo while invoking docker |
| 92 | +) |
| 93 | + |
| 94 | +# specify a folder and specification file name to start with |
| 95 | +OpenAPI.lint( |
| 96 | + spec_dir::AbstractString; # folder containing the specification file |
| 97 | + spec_file::AbstractString; # the specification file |
| 98 | + use_sudo::Bool=false # whether to use sudo while invoking docker |
| 99 | +) |
| 100 | +``` |
0 commit comments