Skip to content

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

@Thaybow

Description

@Thaybow

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions