bow-swift / bow-openapi

🌐 Functional HTTP client generator from an OpenAPI/Swagger specification.
https://openapi.bow-swift.io
Other
51 stars 1 forks source link

Primitive schema objects are generated empty #31

Closed ferranpujolcamins closed 4 years ago

ferranpujolcamins commented 4 years ago

Given the following schema:

openapi: 3.0.2
info:
  version: 0.7.1
  title: aoide
  description: Music library management
  license:
    name: AGPL-3.0-or-later
    url: 'https://www.gnu.org/licenses/agpl-3.0.html'
paths:
  /date:
    get:
      summary: Get current date
      operationId: date
      parameters:
        - $ref: '#/components/schemas/YYYYMMDD'
      responses:
        '400':
          $ref: '#/components/schemas/YYYYMMDD'
components:
  schemas:
    YYYYMMDD:
      type: integer
      format: int32

bow-openapi 0.1.0 generates the following struct for YYYMMDD:

public struct YYYYMMDD: Codable {

}

I would expect the generated struct to be something like this:

public struct YYYYMMDD: Codable {
    init(_ value: Int32) { self.value = value }
    let value: Int32
}
ferranpujolcamins commented 4 years ago

FYI, This is the actual specification I'm trying to generate:

https://gitlab.com/uklotzde/aoide-rs/-/blob/development/resources/openapi.yaml

miguelangel-dev commented 4 years ago

Ey @ferranpujolcamins! It is great you give it a try. You need to wrap attributes inside properties section. You can find more information in swagger docs. Also you need add a required section to avoid optionals. Example:

components:
  schemas:
    YYYYMMDD:
         type: object
         required:
             - value
         properties:
              value:
                 type: integer
                 format: int32

I write it without check it, so it could not be perfect. Tell me if it works.

FYI. You are building an example it is not exactly the same of the specification about aoide-rs. In the specification it describes YYYYMMDD as plain attribute because it is referenced by complex objects like ReleaseDate (not directly in the endpoint definition of parameters). A different question is if we can define properties using references and bow-openapi will auto-generate valid models... probably not! 😿

ferranpujolcamins commented 4 years ago

Ah I see, thanks for the explanation! However, I thought (according to the spec) that I can define such a schema of primitive type:

http://spec.openapis.org/oas/v3.0.3#primitive-sample

miguelangel-dev commented 4 years ago

Right now, we only support models... hehe! Maybe in the future ^^