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

Abstract endpoint => Error SyntaxError: Error resolving $ref pointer #269

Open
Thaybow opened this issue Feb 17, 2022 · 0 comments
Open

Comments

@Thaybow
Copy link

Thaybow commented Feb 17, 2022

I get this error on objects declared in a child class
Error reading swagger location http://localhost:8080/v2/api-docs: SyntaxError: Error resolving $ref pointer "http://localhost:8080/v2/api-docs#/definitions/FooDto".
Token "FooDto" does not exist.

This code works if both classes, TypeA and TypeB have just primitive property.

@JsonTypeInfo(
        use = JsonTypeInfo.Id.NAME,
        include = JsonTypeInfo.As.PROPERTY,
        property = "type")
@JsonSubTypes({
        @JsonSubTypes.Type(value = TypeA.class, name = "A"),
        @JsonSubTypes.Type(value = TypeB.class, name = "B")
})
@ApiModel(subTypes = {TypeA.class, TypeB.class}, discriminator = "type",
        description = "Supertype of all type.")
public abstract class AbstractType {

    public abstract String getType();
}

But the same code throws the error when TypeA or TypeB contains a property like :


@ApiModel(value = "TypeA", parent = AbstractType",
public class TypeA extends AbstractType {
@ApiModelProperty(value = "foo")
 private FooDto fooDto;
...
//other dto object
}

The endpoint works properly and returns a json of TypeA or TypeB regarding the case.
And even before, the endpoint was only returning TypeA.class (not AbstractType) and FooDto typescript interface was perfectly generated (and also related restService)

I have the same code for another Abstract class/abstract endpoint where childs contains only string and numbers and no complaints. All is properly generated.

Signature of endpoint where swagger-codegen is issuing:


@ApiOperation(value = "Retrieves a type", response = AbstractType.class)
    @GetMapping(path = "/{id}", produces = APPLICATION_JSON_VALUE)
    public AbstractType getTypeAorB(...){}


springboot 2.6.3
Java 17
angular 9
ng-swagger-gen 1.8.1
pom.xml :

<dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>
<dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-bean-validators</artifactId>
            <version>2.9.2</version>
        </dependency>

I've install json-parser & mustache
codegen is launched via ng-swagger-gen -i http://localhost:8080/v2/api-docs -o src\app\fooProject\api

Any idea? Huge thanks

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

1 participant