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

Add support for union types with inheritance #298

Closed
wants to merge 1 commit into from
Closed

Add support for union types with inheritance #298

wants to merge 1 commit into from

Conversation

lctncld
Copy link

@lctncld lctncld commented Feb 5, 2019

Currently union type interpreter generates code correctly only if union types don't extend other user-defined types.

For example let's look at the schema used for a unit test

types:
  Phone:
    type: object
    properties:
      manufacturer:
        type: string
      numberOfSIMCards:
        type: number
  Notebook:
    type: object
    properties:
      manufacturer:
        type: string
      numberOfUSBPorts:
        type: number
  Device:
    type: Phone | Notebook

If I change Phone and Notebook types to extend another custom type

types:
  Manufactured:
    type: object
    properties:
     manufacturer:
        type: string
  Phone:
    type: Manufactured
    properties:
      numberOfSIMCards:
        type: number
  Notebook:
    type: Manufactured
    properties:
      numberOfUSBPorts:
        type: number
  Device:
    type: Phone | Notebook

Interpreter ignores Phone/Notebook types and Device POJO looks like this:

public class Device implements Serializable {
    protected Manufactured Phone;
    protected Manufactured Notebook;
}

This PR contains a fix for this behavior, I believe expected result is similar to

public class Device implements Serializable {
  protected com.gen.test.model.Phone Phone;
  protected com.gen.test.model.Notebook Notebook;
}

Could you please review it and maybe propose a better solution?

@stojsavljevic
Copy link
Contributor

Hi,
thanks for reaching us.

  Device:
    type: Phone | Notebook

represents union type. This means Device is either Phone or Notebook.
So it should be either
public class Device extends Phone or
public class Device extends Notebook
but I don't see the way to accomplish both with Java.
Regarding your solution - I don't feel attributes are expected here. POJO's attributes are always generated based on type's properties.

If you think we should discuss the topic more, please open an issue so the conversation can continue there.

Thanks.

@lctncld
Copy link
Author

lctncld commented Feb 6, 2019

Thanks, I think we can continue in #289 since you've already asked the question there.

@lctncld lctncld closed this Feb 7, 2019
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.

None yet

2 participants