Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
This is my swagger configuration class:


Java
package com.example.ecourtcustinfolast.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
@CrossOrigin
public class SwaggerConfig {
    @Bean
    public Docket apiProject() {
        return new Docket(DocumentationType.SWAGGER_12)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.example.ecourtcustinfolast"))
                .paths(PathSelectors.any())
                .build().apiInfo(apiInfo());

    }

    private ApiInfo apiInfo() {

        return new ApiInfoBuilder().title("title")

                .description("description - Rest Api")

                .contact(new Contact("xxxx", "xxxx", "xxxx"))

                .version("1.0.0")

                .build();

    }

    @Bean
    public FilterRegistrationBean<CorsFilter> corsFilter() {

        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration config = new CorsConfiguration();
        config.setAllowCredentials(true);
        config.addAllowedOrigin("*");
        config.addAllowedHeader("*");
        config.addAllowedMethod("OPTIONS");
        config.addAllowedMethod("GET");
        config.addAllowedMethod("PUT");
        config.addAllowedMethod("POST");
        config.addAllowedMethod("DELETE");
        config.addAllowedMethod("PATCH");

        source.registerCorsConfiguration("/**", config);
        final FilterRegistrationBean<CorsFilter> bean = new FilterRegistrationBean<>(new CorsFilter(source));
        bean.setOrder(Ordered.HIGHEST_PRECEDENCE);
        return bean;
    }

}


When I run project and using swagger-ui there are no pojo classes that I have created in the models section. What do you think could be the reason for this and is there any solution to bring my pojo classes there?

Models section in Swagger-UI is Empty:


It just shows my BaseClass pojo which called BaseClass that I created in my model package, but I need the output of the others. I was skeptical because of @JsonProperties annotations or extending all classes from my Base Class. But create a new class and I run the project again I ecounter the same operation. Below I show an example of the model classes I created.


Java
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class AccountInfo extends BaseClass{

    @JsonProperty("account_number")
    public String accoutNumber;

    @JsonProperty("account_type")
    public String accountType;

    @JsonProperty("open_date")
    public String openDate;

    @JsonProperty("currency")
    public String currency;

    @JsonProperty("balance")
    public double balance;

    @JsonProperty("closure_date")
    public String closureDate;

    @JsonProperty("status")
    public String status;

}


In addition, only one shows this class.

Java
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public abstract class BaseClass {

}


What I have tried:

I tried to add new annotation whihc called like this: But now worked.

Java
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@ApiModel(value = "Model", description = "Model description")
public class AccountInfo extends BaseClass{

    @JsonProperty("account_number")
    @ApiModelProperty(value = "accoutNumber", dataType = "java.lang.String", required = true)
    public String accoutNumber;
    
    @JsonProperty("account_type")
    @ApiModelProperty(value = "accoutNumber", dataType = "java.lang.String", required = true)
    public String accountType;

    @JsonProperty("open_date")
    @ApiModelProperty(value = "accoutNumber", dataType = "java.lang.String", required = true)
    public String openDate;

    @JsonProperty("currency")
    @ApiModelProperty(value = "accoutNumber", dataType = "java.lang.String", required = true)
    public String currency;

    @JsonProperty("balance")
    @ApiModelProperty(value = "accoutNumber", dataType = "java.lang.String", required = true)
    public double balance;

    @JsonProperty("closure_date")
    @ApiModelProperty(value = "closureDate", dataType = "java.lang.String", required = true)
    public String closureDate;

    @JsonProperty("status")
    @ApiModelProperty(value = "status", dataType = "java.lang.String", required = true)
    public String status;

}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900