Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The behavior of inline schema for allOf #267

Open
ymhuang0808 opened this issue Mar 18, 2021 · 3 comments
Open

The behavior of inline schema for allOf #267

ymhuang0808 opened this issue Mar 18, 2021 · 3 comments

Comments

@ymhuang0808
Copy link

ymhuang0808 commented Mar 18, 2021

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.

@nicholascross
Copy link
Contributor

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
}

@ymhuang0808
Copy link
Author

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! 😃

yonaskolb pushed a commit that referenced this issue Apr 12, 2021
* Restore generation of inline types for all of (#267)

* Update change log with fix for issue #267
liamnichols added a commit to liamnichols/SwagGen that referenced this issue Jul 27, 2021
@liamnichols
Copy link
Contributor

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 🙏

yonaskolb pushed a commit that referenced this issue Aug 5, 2021
…ema (#278)

* Update TestSpec to include a scenario where allOf is used to change a referenced schemas nullability or description

* Update inlineSchema extension on Schema to ignore allOf groups where there is only a single child schema

* Update generated fixtures to match expected results after patch

* Update CHANGELOG.md

* Update TestSpec to include example demonstrated in #267
kerrmarin-lvmh pushed a commit to kerrmarin-lvmh/SwagGen that referenced this issue Sep 28, 2021
…ema (yonaskolb#278)

* Update TestSpec to include a scenario where allOf is used to change a referenced schemas nullability or description

* Update inlineSchema extension on Schema to ignore allOf groups where there is only a single child schema

* Update generated fixtures to match expected results after patch

* Update CHANGELOG.md

* Update TestSpec to include example demonstrated in yonaskolb#267
rusik pushed a commit to agorra/SwagGen that referenced this issue Oct 14, 2021
…ema (yonaskolb#278)

* Update TestSpec to include a scenario where allOf is used to change a referenced schemas nullability or description

* Update inlineSchema extension on Schema to ignore allOf groups where there is only a single child schema

* Update generated fixtures to match expected results after patch

* Update CHANGELOG.md

* Update TestSpec to include example demonstrated in yonaskolb#267
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants