Skip to content

Empty Dictionary fails to encode #525

@grahamburgsma

Description

@grahamburgsma

Description

Returning an empty dictionary as the response body fails to encode.

Error thrown:
EncodingError: invalidValue jsonPayload(additionalProperties: [:]) - at : Top-level jsonPayload did not encode any values.

Reproduction

openapi: '3.1.0'

paths:
  /test:
    get:
      operationId: testEmpty
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                additionalProperties:
                  type: array
                  items:
                    type: string
func testEmpty(_ input: Operations.testEmpty.Input) async throws -> Operations.testEmpty.Output {
    return .ok(.init(body: .json(.init(additionalProperties: [:]))))
}

Package version(s)

OpenAPIKit 3.1.2
swift-openapi-generator 1.2.0
swift-openapi-runtime 1.3.2
swift-openapi-vapor 1.0.0
swift-openapi-context 1.0.0

Expected behavior

The response should be encoded as:

{}

Environment

swift-driver version: 1.87.3 Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)
Target: arm64-apple-macosx14.0

Metadata

Metadata

Assignees

Labels

kind/bugFeature doesn't work as expected.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions