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

Missing Open API schema property of collection self type #2184

Closed
lwielek opened this issue Mar 24, 2020 · 1 comment
Closed

Missing Open API schema property of collection self type #2184

lwielek opened this issue Mar 24, 2020 · 1 comment

Comments

@lwielek
Copy link

lwielek commented Mar 24, 2020

Version: io.swagger.vore.v3:swagger-core:2.1.1

The model resolver is skipping properties in the specific scenario:

  • there's a resource returning class A
  • class A contains property of type: collection of B
  • class B contains property of type: collection of B

The B collection property is missing in the schema definition

Below code example, that reproduces the issue.
DataResponse has property buckets (List<BucketResponse>).
BucketResponse has property buckets (List<BucketResponse>).
The BucketResponse.buckets property is missing in the OpenAPI schema.


package swagger.model.issue;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.List;

import io.swagger.v3.core.util.Json;
import io.swagger.v3.jaxrs2.integration.XmlWebOpenApiContext;
import io.swagger.v3.oas.integration.SwaggerConfiguration;
import io.swagger.v3.oas.models.OpenAPI;

import static java.util.Collections.singleton;

public class SwaggerModelIssueTest {

    public static void main(String[] args) throws Exception {
        SwaggerConfiguration oasConfig = new SwaggerConfiguration()
                .resourcePackages(singleton("swagger.model.issue"))
                .readAllResources(true);
        OpenAPI openAPI =
                new XmlWebOpenApiContext<>().openApiConfiguration(oasConfig)
                        .init()
                        .read();
        System.out.println(Json.pretty(openAPI));
        assert(openAPI.getComponents().getSchemas().get("BucketResponse").getProperties().containsKey("buckets"));
    }

    public static class DataResponse {
        private String value;
        private List<BucketResponse> buckets;
        public String getValue() {
            return value;
        }
        public List<BucketResponse> getBuckets() {
            return buckets;
        }
    }
    
    public static class BucketResponse {
        private String value;
        private List<BucketResponse> buckets;
        public String getValue() {
            return value;
        }
        public List<BucketResponse> getBuckets() {
            return buckets;
        }
    }

    @Path("/data")
    @Produces(MediaType.APPLICATION_JSON)
    public static class DataResource {
        @POST
        @Path("/")
        public DataResponse getData() {
            return new DataResponse();
        }
    }
}
@MikeRalphson
Copy link
Member

Please raise tooling-related issues on the relevant repository. This repository is for the OpenAPI specification itself. You may also receive more answers on a general support forum such as StackOverflow. 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

2 participants