Skip to content

Swift model generate problem, if $ref in model, $ref is ignored. #12184

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

Open
goors opened this issue Jun 18, 2023 · 1 comment
Open

Swift model generate problem, if $ref in model, $ref is ignored. #12184

goors opened this issue Jun 18, 2023 · 1 comment

Comments

@goors
Copy link

goors commented Jun 18, 2023

"AdventuresQuery": {
        "allOf": [
          {
            "$ref": "#/components/schemas/EntitySearchQuery"
          },
          {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "all": {
                "type": "boolean"
              },
              "recommended": {
                "type": "boolean"
              },
              "fields": {
                "$ref": "#/components/schemas/AdventuresQueryFields"
              }
            }
          }
        ]
      },

In swift generator you get this code

public struct AdventuresQuery: Codable {

    public var all: Bool?
    public var recommended: Bool?
    public var fields: AdventuresQueryFields?

    public init(all: Bool? = nil, recommended: Bool? = nil, fields: AdventuresQueryFields? = nil) {
        self.all = all
        self.recommended = recommended
        self.fields = fields
    }


}

as you can see EntitySearchQuery is ignored.

@alteredtech
Copy link

I know you opened this about a 1.5 years ago. Currently seeing a similar issue. I was able to get allOf working by using yaml

Execution:
  description: The history and response
  type: array
  example: []
    properties:
      items:
        allOf:
          - $ref: '#/components/schemas/History'
          - $ref: '#/components/schemas/ExecutionResponse'

Maybe something with JSON?

Though I am also having a similar issue with anyOf. It doesnt have anything in the body. It is also making it a struct when I think it should be an enum? This is how I think it should look.

public enum Notifications {
    case slack(Slack)
    case email(Email)
    case sms(SMS)
}

public struct Slack {
    public var channel: String
    public var text: String
}

...
components:
  schemas:
    ExecutionNotification:
      properties:
        notifications:
          type: array
          example: []
          items:
            anyOf:
              - $ref: '#/components/schemas/Slack'
              - $ref: '#/components/schemas/Email'
              - $ref: '#/components/schemas/SMS'

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

2 participants