Skip to content

Detect invalid use of binary properties in JSON object schemas #701

Open
@MahdiBM

Description

@MahdiBM

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/enhancementImprovements to existing feature.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions