Skip to content

Support JSON streaming #832

@maxuai

Description

@maxuai

Currently the handling of JSON streaming fails due to failing deserialization of the streamed data. As an example we are trying to do that in a python client but I guess in general it applies to all languages.

OpenAPI spec file:

openapi: 3.0.0
components:
  examples: { }
  headers: { }
  parameters: { }
  requestBodies: { }
  responses: { }
  schemas: { }
info:
  title: the test title
  version: '1'
  description: 'The test REST API'
  contact: { }
paths:
  /test/stream:
    get:
      operationId: StreamData
      responses:
        "200":
          description: Ok
          content:
            application/json-lines:
              schema:
                type: string
          headers:
            Content-Type:
              schema:
                type: string
                enum:
                  - application/json-lines
                nullable: false
              required: true
      parameters:
        - in: header
          name: Accept
          required: true
          schema:
            type: string
            enum:
              - application/json-lines

servers:
  - url: http://localhost:5000/api/v1
    description: Local development

gen.yaml file:

configVersion: 2.0.0
generation:
  sdkClassName: SDK
  maintainOpenAPIOrder: true
  usageSnippets:
    optionalPropertyRendering: withExample
  useClassNamesForArrayFields: true
  fixes:
    nameResolutionDec2023: true
    parameterOrderingFeb2024: true
    requestResponseComponentNamesFeb2024: true
  auth:
    oAuth2ClientCredentialsEnabled: false
python:
  version: 0.0.1
  additionalDependencies:
    dev: {}
    main: {}
  authors:
    - Speakeasy
  clientServerStatusCodesAsErrors: true
  description: Python Client SDK Generated by Speakeasy
  enumFormat: enum
  flattenGlobalSecurity: true
  flattenRequests: false
  imports:
    option: openapi
    paths:
      callbacks: models/callbacks
      errors: models/errors
      operations: models/operations
      shared: models/components
      webhooks: models/webhooks
  inputModelSuffix: input
  maxMethodParams: 4
  methodArguments: require-security-and-request
  outputModelSuffix: output
  packageName: openapi
  projectUrls: {}
  responseFormat: flat
  templateVersion: v2

I know that there are multiple approaches how to implement the streaming in detail and it probably doesn't make sense to implement the correct handling on your side but as a quick solution it would be perfectly fine to just return the raw response and handle the correct deserilaziation on our side.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions