Closed arthurcro closed 1 month ago
Closes https://github.com/apple/swift-openapi-generator/issues/651. Today, some responses have no headers nor body (for example, 204 No Content).
In generated code it looks like this:
internal enum Output: Sendable, Hashable { internal struct NoContent: Sendable, Hashable { /// Creates a new `NoContent`. internal init() {} } case noContent(Operations.addPollAnswer.Output.NoContent) }
And when writing a server handler, adopters have to spell it as:
return .noContent(.init())
The (.init()) bit is unnecessary, and we should make this common case prettier.
(.init())
Adds a static property to the generated Output enum for any response which does not have a header or a body and does not require a status code.
Output
The following is code is generated:
internal enum Output: Sendable, Hashable { internal struct NoContent: Sendable, Hashable { /// Creates a new `NoContent`. internal init() {} } case noContent(Operations.addPollAnswer.Output.NoContent) internal static var noContent: Self { .noContent(.init()) } }
Update FileBasedReferenceTests.swift to reflect the changes in the generated Types.swift.
FileBasedReferenceTests.swift
Types.swift
Motivation
Closes https://github.com/apple/swift-openapi-generator/issues/651. Today, some responses have no headers nor body (for example, 204 No Content).
In generated code it looks like this:
And when writing a server handler, adopters have to spell it as:
The
(.init())
bit is unnecessary, and we should make this common case prettier.Modifications
Adds a static property to the generated
Output
enum for any response which does not have a header or a body and does not require a status code.Result
The following is code is generated:
Test Plan
Update
FileBasedReferenceTests.swift
to reflect the changes in the generatedTypes.swift
.