apple / apple/swift-openapi-generator
Detect invalid use of binary properties in JSON object schemas
- Dominant language
- Swift
- Stars
- 2k
- Forks
- 182
- Avg merge
- 13h 28m
- Merged PRs (30d)
- 5
Description
### Description
Compiler error for generated code related to binary content encoding.
See below for a quick repro.
the error is:
```
API/Sources/OpenAPI/GeneratedSources/Types.swift:27:24: error: type 'Components.Schemas.CategoryResponse' does not conform to protocol 'Decodable'
25 | package enum Schemas {
26 | /// - Remark: Generated from `#/components/schemas/CategoryResponse`.
27 | package struct CategoryResponse: Codable, Hashable, Sendable {
| `- error: type 'Components.Schemas.CategoryResponse' does not conform to protocol 'Decodable'
28 | /// The image file for the category (supported formats: jpg, png, webp)
29 | ///
30 | /// - Remark: Generated from `#/components/schemas/CategoryResponse/image`.
31 | package var image: OpenAPIRuntime.HTTPBody?
| `- note: cannot automatically synthesize 'Decodable' because 'OpenAPIRuntime.HTTPBody?' does not conform to 'Decodable'
32 | /// Creates a new `CategoryResponse`.
33 | ///
Swift.Decodable:2:5: note: protocol requires initializer 'init(from:)' with type 'Decodable'
1 | public protocol Decodable {
2 | init(from decoder: any Decoder) throws
| `- note: protocol requires initializer 'init(from:)' with type 'Decodable'
3 | }
API/Sources/OpenAPI/GeneratedSources/Types.swift:27:24: error: type 'Components.Schemas.CategoryResponse' does not conform to protocol 'Encodable'
25 | package enum Schemas {
26 | /// - Remark: Generated from `#/components/schemas/CategoryResponse`.
27 | package struct CategoryResponse: Codable, Hashable, Sendable {
| `- error: type 'Components.Schemas.CategoryResponse' does not conform to protocol 'Encodable'
28 | /// The image file for the category (supported formats: jpg, png, webp)
29 | ///
30 | /// - Remark: Generated from `#/components/schemas/CategoryResponse/image`.
31 | package var image: OpenAPIRuntime.HTTPBody?
| `- note: cannot automatically synthesize 'Encodable' because 'OpenAPIRuntime.HTTPBody?' does not conform to 'Encodable'
32 | /// Creates a new `CategoryResponse`.
33 | ///
Swift.Encodable:2:10: note: protocol requires function 'encode(to:)' with type 'Encodable'
1 | public protocol Encodable {
2 | func encode(to encoder: any Encoder) throws
| `- note: protocol requires function 'encode(to:)' with type 'Encodable'
3 | }
```
### Reproduction
```yaml
openapi: "3.1.0"
info:
title: My API
version: 1.0.0
components:
schemas:
CategoryResponse:
type: object
properties:
image:
title: Image
type: string
contentEncoding: binary
description: "The image file for the category (supported formats: jpg, png, webp)"
```
### Package version(s)
generator 1.3.0
runtime 1.5.0
### Expected behavior
code should compile
### Environment
irrelevant but Swift 6, M-series mac.
### Additional information
_No response_
Contributor guide
Research direction
Start with the YAML reproduction and the generated API/Sources/OpenAPI/GeneratedSources/Types.swift output, especially CategoryResponse.image. Trace how contentEncoding: binary is translated for a JSON object property. Done when running the reproduction no longer produces the Codable conformance failure and the invalid use is handled explicitly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100