ebowman/api-first-hand

Factorizating using allOf does not generate validators

guizmaii opened this issue · 1 comments

Hi,

It's maybe related to #23, maybe not. I don't know.
Here is the problem.

I have an endpoint:

paths:
  /bars:
    post:
      operationId: postBars
      description: Bar
      parameters:
        - name: body
          in: body
          required: true
          schema:
            $ref: '#/definitions/BarsRequest'
      responses:
        200:
          description: Bar OK
          schema:
            $ref: '#/definitions/BarsResponse'

and definitions:

definitions:
  BarsRequest:
    type: object
    properties:
      state:
        type: string
        enum: ["a", "b", "c"]
      id:
        type: string
      query:
        type: string

  BarsResponse:
    type: object
    properties:
      state:
        type: string
        enum: ["a", "b", "c"]
      id:
        type: string
      bars:
        type: array
        items:
          $ref: '#/definitions/Bar'

With these definitions, the generated code is OK.

We can see that state and id are in common to BarsRequest and BarsResponse, so I created AbstractBar and used the allOf keyword:

definitions:

  AbstractBar:
    type: object
    properties:
      state:
        type: string
        enum: ["a", "b", "c"]
      id:
        type: string

  BarsRequest:
    allOf:
      - $ref: '#/definitions/AbstractBar'
      - properties:
          query:
            type: string

  BarsResponse:
    allOf:
      - $ref: '#/definitions/AbstractBar'
      - properties:
          bars:
            type: array
            items:
              $ref: '#/definitions/Bar'

But wIth these new definitions, I have the following error:

capture d ecran 2016-08-01 10 58 06

Fixed in 0.2