Skip to content

Commit

Permalink
update docs, increment version (#60)
Browse files Browse the repository at this point in the history
Updated docs for recent changes.
Incremented patch version for tagging.
  • Loading branch information
tanmaykm authored Aug 28, 2023
1 parent 0053243 commit ca99f1d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ keywords = ["Swagger", "OpenAPI", "REST"]
license = "MIT"
desc = "OpenAPI server and client helper for Julia"
authors = ["JuliaHub Inc."]
version = "0.1.16"
version = "0.1.17"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
23 changes: 23 additions & 0 deletions docs/src/userguide.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ Client(root::String;
timeout::Int=DEFAULT_TIMEOUT_SECS,
long_polling_timeout::Int=DEFAULT_LONGPOLL_TIMEOUT_SECS,
pre_request_hook::Function,
escape_path_params::Union{Nothing,Bool}=nothing,
chunk_reader_type::Union{Nothing,Type{<:AbstractChunkReader}}=nothing,
verbose::Union{Bool,Function}=false,
)
```
Expand All @@ -136,12 +138,16 @@ Where:
- `timeout`: optional timeout to apply for server methods (default `OpenAPI.Clients.DEFAULT_TIMEOUT_SECS`)
- `long_polling_timeout`: optional timeout to apply for long polling methods (default `OpenAPI.Clients.DEFAULT_LONGPOLL_TIMEOUT_SECS`)
- `pre_request_hook`: user provided hook to modify the request before it is sent
- `escape_path_params`: Whether the path parameters should be escaped before being used in the URL (true by default). This is useful if the path parameters contain characters that are not allowed in URLs or contain path separators themselves.
- `chunk_reader_type`: The type of chunk reader to be used for streaming responses.
- `verbose`: whether to enable verbose logging

The `pre_request_hook` must provide the following two implementations:
- `pre_request_hook(ctx::OpenAPI.Clients.Ctx) -> ctx`
- `pre_request_hook(resource_path::AbstractString, body::Any, headers::Dict{String,String}) -> (resource_path, body, headers)`

The `chunk_reader_type` can be one of `LineChunkReader`, `JSONChunkReader` or `RFC7464ChunkReader`. If not specified, then the type is automatically determined based on the return type of the API call. Refer to the [Streaming Responses](#Streaming-Responses) section for more details.

The `verbose` option can be one of:
- `false`: the default, no verbose logging
- `true`: enables curl verbose logging to stderr
Expand Down Expand Up @@ -191,3 +197,20 @@ Optional middlewares can be one or more of:

The order in which middlewares are invoked is:
`init |> read |> pre_validation |> validate |> pre_invoke |> invoke |> post_invoke`

## Streaming Responses

Some OpenAPI implementations implement streaming of responses by sending more than one items in the response, each of which is of the type declared as the return type in the specification. E.g. the [Twitter OpenAPI specification](https://api.twitter.com/2/openapi.json) that keeps sending tweets in JSON like this forever:

```json
{"data":{"id":"1800000000000000000","text":"mmm i like a sandwich"},"matching_rules":[{"id":1800000000000000000,"tag":"\"sandwich\""}]}
{"data":{"id":"1800000000000000001","text":"lets have a sandwich"},"matching_rules":[{"id":1800000000000000001,"tag":"\"sandwich\""}]}
```

OpenAPI.jl handles such responses through "chunk readers" which are engaged only with the streaming API endpoints. There can be multiple implementations of chunk readers, each of which must be of type `AbstractChunkReader`. The following are the chunk readers provided, each with a different chunk detection strategy. They are selected based on some heuristics based on the response data type.

- `LineChunkReader`: Chunks delimited by newline. This is the default when the response type is detected to be not of `OpenAPI.APIModel` type.
- `JSONChunkReader`: Each chunk is a JSON. Whitespaces between JSONs are ignored. This is the default when the response type is detected to be a `OpenAPI.APIModel`.
- `RFC7464ChunkReader`: A reader based on [RFC 7464](https://www.rfc-editor.org/rfc/rfc7464.html). Available for use by overriding through `Client` or `Ctx`.

The `OpenAPI.Clients.Client` and `OpenAPI.Clients.Ctx` constructors take an additional `chunk_reader_type` keyword parameter. This can be one of `OpenAPI.Clients.LineChunkReader`, `OpenAPI.Clients.JSONChunkReader` or `OpenAPI.Clients.RFC7464ChunkReader`. If not specified, then the type is automatically determined as described above.
1 change: 1 addition & 0 deletions src/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ end
timeout::Int=DEFAULT_TIMEOUT_SECS,
pre_request_hook::Function=noop_pre_request_hook,
escape_path_params::Union{Nothing,Bool}=nothing,
chunk_reader_type::Union{Nothing,Type{<:AbstractChunkReader}}=nothing,
verbose::Union{Bool,Function}=false,
)
Expand Down

2 comments on commit ca99f1d

@tanmaykm
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/90397

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.17 -m "<description of version>" ca99f1db70681930201571656074ca0c9e9e30cf
git push origin v0.1.17

Please sign in to comment.