yonaskolb / SwagGen

OpenAPI/Swagger 3.0 Parser and Swift code generator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The behavior of inline schema for allOf

ymhuang0808 opened this issue · comments

In version 4.4.0, there is a bug about the inline schema for allOf. In the PR #217 , according to the revision of Sources/SwagGenKit/SwaggerExtensions.swift, allOf cannot be generated in a certain situation. The if condition is true when it ONLY occurs in anyOf or oneOf, because the discriminator will never appears with allOf.

The below OpenAPI example spec shows the category inline schema is not generated in Pet .

components:
  schemas:
    Operator:
      required:
        - operation
      properties:
        operation:
          type: string
          enum:
            - remove
            - replace
    Pet:
      required:
      - name
      - photoUrls
      - category
      type: object
      properties:
        id:
          type: integer
          format: int64
        category:
          allOf:
            - $ref: "#/components/schemas/Operator"
            - properties:
                value:
                  type: object
                  required: 
                    - id
                  properties:
                    id:
                      type: string
        name:
          type: string
          example: doggie
        photoUrls:
          type: array
          xml:
            name: photoUrl
            wrapped: true
          items:
            type: string
        status:
          type: string
          description: pet status in the store
          enum:
          - available
          - pending
          - sold

I expect the the SwagGen will generate a inner Category class in Pet class model. In fact, the Category are not generated.

Hi @ymhuang0808 are you suggesting this #217 caused some kind of regression or that there is additional consideration required to support allOf inline as well?

Apologies my head has been out of this code for too long to offer much meaningful insight.

If it was a regression I wonder if it would be resolved by adding an else if to consider all separately.

if group.discriminator != nil {
  return self
} else if case .all = group.type {
  // might restore previous consideration of all based on group type
  return self
}

Hi @nicholascross
Thanks for your kind reply. Yes, the PR #217 makes the inline class for allOf broken. The code snippet works for the allOf in inline class. Would you like to make a pull request?

Cheers! 😃

Hi both 👋 I think there is a little more involved here and i submitted a patch in #278... Would be great if you could check it out 🙏

ezoic increase your site revenue