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

Use first group schema type when there is only one group schema #217

Merged
merged 1 commit into from
Feb 29, 2020
Merged

Use first group schema type when there is only one group schema #217

merged 1 commit into from
Feb 29, 2020

Conversation

nicholascross
Copy link
Contributor

This avoids hitting the fallback to using the property name which without further intervention results in missing types when compiling generated code.

...

"ExampleModel": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "exampleProperty": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/ExampleType"
              }
            ]
          }
        }
}
...

Before

public var exampleProperty: ExampleProperty

After

public var exampleProperty: ExampleType

This change still would result in compilation errors for generated code where there was more than one possible schema for a group schema. Is there a proposed or correct way of handling this?

From what I can tell right now this will just generate the property type using a camel cased property name which seems a bit fragile - I am assuming the intention is this type be implemented manually but that seems error prone as there is the possibility of type collisions.

@yonaskolb
Copy link
Owner

Thanks @nicholascross.
It's strange to have a spec with just a single oneOf, but I guess if you do this makes it better. Could you add a changelog as well, and a test case to https:/yonaskolb/SwagGen/blob/master/Specs/TestSpec/spec.yml

Generating oneOf types hasn't been implemented yet, but could be done by generating an enum with associated types within the containing type.

@nicholascross
Copy link
Contributor Author

Thanks @yonaskolb! I will make the requested changes in the near future.

The swagger spec I am using is automatically generated from server side code and I think it comes into play anytime there is some kind of inheritance going on in the backend models.

I like the idea of enum for greater support of this part of the spec. I might have a crack at it when I get some free time.

This avoids hitting the fallback to using the property name which without further intervention results in missing types when compiling generated code

public class InlineAnimal: Animal {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yonaskolb - This type is no longer generated but I think that is expected under this change.

@yonaskolb yonaskolb merged commit bbb1ad7 into yonaskolb:master Feb 29, 2020
@ymhuang0808
Copy link

ymhuang0808 commented Mar 18, 2021

Hi, @nicholascross
Excuse me, could you take a look at the issue #267 related with the PR? I have a question about the allOf with inline schema. Thank you.

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

Successfully merging this pull request may close these issues.

3 participants