Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chunk detection based on response format #59

Merged
merged 1 commit into from
Aug 28, 2023
Merged

chunk detection based on response format #59

merged 1 commit into from
Aug 28, 2023

Conversation

tanmaykm
Copy link
Member

This introduces AbstractChunkReader and adds a few chunk readers with different chunk detection strategies. Also includes some auto selection heuristics based on detected response format and ability to specify a chunk reader at Ctx and Client levels.

Chunk readers available:

  • LineChunkReader: Chunks delimited by newline. This was the only available strategy earlier. It is now 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 now the default when the response type is detected to be a OpenAPI.APIModel.
  • RFC7464ChunkReader: A reader based on RFC 7464. Available for use by overriding through Client or Ctx.

The Client and 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 based on the return type of the API call.

This introduces `AbstractChunkReader` and adds a few chunk readers with different chunk detection strategies. Also includes some auto selection heuristics based on detected response format and ability to specify a chunk reader at `Ctx` and `Client` levels.

Chunk readers available:
- `LineChunkReader`: Chunks delimited by newline. This was the only available strategy earlier. It is now 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 now 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 `Client` and `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 based on the return type of the API call.
@tanmaykm
Copy link
Member Author

Adding this issue on OpenAPI specifications for reference: OAI/OpenAPI-Specification#1576.
It is still an open issue, and the implementation is this PR is partly based on discussions in there.

@tanmaykm tanmaykm merged commit 0053243 into main Aug 28, 2023
3 checks passed
@delete-merged-branch delete-merged-branch bot deleted the tan/returntypes branch August 28, 2023 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant