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

(Spring) SubClass annotations are missing from the base class #4606

Closed
eamon316 opened this issue Jan 20, 2017 · 2 comments
Closed

(Spring) SubClass annotations are missing from the base class #4606

eamon316 opened this issue Jan 20, 2017 · 2 comments

Comments

@eamon316
Copy link
Contributor

Description

Applying fix for #2449 to JavaSpring

In order for jackson ObjectMapper to deserialize correctly a base class to its subclasses, we need to include annotations defining all expected subclasses in the parent class.
The codegen currently does not generate those annotations.
For this example YAML:

definitions:
Base:
type: object
discriminator: disc
properties:
disc:
type: string
required:
- disc
SubClass:
allOf:
- $ref: '#/definitions/Base'
required:
- field
properties:
field:
type: string

Jackson expects these annotations to be produced, but they are not:
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "disc")
@JsonSubTypes({ @type(value = SubClass.class, name = "SubClass") })
public class Base {
}

Swagger-codegen version

2.2.2-SNAPSHOT

Swagger declaration file content or url
Command line used for generation

java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate
-i modules/swagger-codegen/src/test/resources/2_0/allOfTest.yaml
-l spring
-o /tmp/java_spring

Steps to reproduce

Run the above command.
The following annotations are not included
@JsonTypeInfo
@JsonSubTypes

Related issues

#2449

Suggest a Fix

I have submitted a pull request

eamon316 added a commit to eamon316/swagger-codegen that referenced this issue Jan 20, 2017
eamon316 added a commit to eamon316/swagger-codegen that referenced this issue Jan 20, 2017
… the base class

   * Commit updated samples from ./bin/spring-all-pestore.sh
wing328 pushed a commit that referenced this issue Feb 3, 2017
* Issue #4606 (Spring) SubClass annotations are missing from the base class

* Issue #4606 (Spring) SubClass annotations are missing from the base class
   * Commit updated samples from ./bin/spring-all-pestore.sh
davidgri pushed a commit to davidgri/swagger-codegen that referenced this issue May 11, 2017
* Issue swagger-api#4606 (Spring) SubClass annotations are missing from the base class

* Issue swagger-api#4606 (Spring) SubClass annotations are missing from the base class
   * Commit updated samples from ./bin/spring-all-pestore.sh
@philipptrenz
Copy link

Short question: How's the state? Does it work now?

@wing328
Copy link
Contributor

wing328 commented May 19, 2017

@philipptrenz the fix (#4607) by @eamon316 has been merged into master. Please pull the latest master to give it a try.

Thanks for the PR from @eamon316

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants