yonaskolb / SwagGen

OpenAPI/Swagger 3.0 Parser and Swift code generator
MIT License
626 stars 146 forks source link

oneOf not working? #210

Closed goors closed 4 years ago

goors commented 4 years ago

I got, for example, geoRestriction that is oneOf GeoAreaSet but the generator is somehow doing this

public class SomeClass {
  public var geoRestriction: GeoRestriction?
}

instead of

public class SomeClass {
  public var geoRestriction: GeoAreaSet?
}

In swift lib, i got like 9.999+ errors. Everything is there but somehow messed up. I got like 772 models with wrong data.

yonaskolb commented 4 years ago

Hi @goors. I can't help without part of an example spec

normand1 commented 4 years ago

@yonaskolb I think I ran into an example just now and I'm having the same issue. From the Listen Notes API yaml: https://listen-api.listennotes.com/api/v2/openapi.yaml

After generating the code for this .yaml I'm missing the Results object which contains a oneOf OAS 3 type modifier:

        results:
          type: array
          description: A list of search results.
          items:
            oneOf:
            - $ref: '#/components/schemas/EpisodeSearchResult'
            - $ref: '#/components/schemas/PodcastSearchResult'
            - $ref: '#/components/schemas/CuratedListSearchResult'
normand1 commented 4 years ago

Nevermind. I took a look at your TestSpec and the yaml file I was trying to use doesn't specify a discriminator. I modified the ymal to add a discriminator and SwagGen works fine. Thanks! https://github.com/yonaskolb/SwagGen/blob/bbb1ad72df2e6279da25effc546a11bd8627cd01/Specs/TestSpec/spec.yml#L311