dankinsoid / VaporToOpenAPI

OpenAPI specification generator for Vapor based Swift projects.
MIT License
98 stars 8 forks source link

Array item type being erased #15

Closed willmorris44 closed 10 months ago

willmorris44 commented 10 months ago

When using an array in a response, the type within the array is getting erased.

extension Tag {
    struct Response: Content {
        let id: Int
        let value: String
    }

    struct ListResponse: Content {
        let tags: [Response]
    }

The expected response JSON would be

{
  tags: [
    {
      "id": 0,
      "value": "string"
     }
  ]
}

Instead is is being displayed as

{
  "tags": [
    "string"
  ]
}

When using the .openAPI method

request.get(use: index)
  .openAPI(
    summary: "Get Tags",
    description: "Get an array of tags",
    response: .type(Tag.ListResponse.self),
    responseContentType: .application(.json)
  )

func index(request: Request) async throws -> Tag.ListResponse {}
dankinsoid commented 10 months ago

@willmorris44 fixed in 4.3.11

willmorris44 commented 10 months ago

@dankinsoid Seems this fix is now failing the build in 'Route+UserInfo.swift'

    @discardableResult
    func userInfo<Key: RouteInfoKey>(key: Key.Type, _ value: Key.Value) -> Route {
        userInfo[Key.name] = value
        return self
    }

    func userInfo<Key: RouteInfoKey>(for key: Key.Type) -> Key.Value? {
        userInfo[Key.name] as? Key.Value
    }

Build errors are Cannot convert value of type 'String' to expected argument type 'AnySendableHashable' and Type of expression is ambiguous without a type annotation

willmorris44 commented 10 months ago

@dankinsoid Seems this fix is now failing the build in 'Route+UserInfo.swift'

  @discardableResult
  func userInfo<Key: RouteInfoKey>(key: Key.Type, _ value: Key.Value) -> Route {
      userInfo[Key.name] = value
      return self
  }

  func userInfo<Key: RouteInfoKey>(for key: Key.Type) -> Key.Value? {
      userInfo[Key.name] as? Key.Value
  }

Build errors are Cannot convert value of type 'String' to expected argument type 'AnySendableHashable' and Type of expression is ambiguous without a type annotation

This is being addressed here: https://github.com/dankinsoid/VaporToOpenAPI/issues/16#issue-1990227971