Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

389
Visualizações
Swagger doesnt show inherited objects

I have a class "SubModel" which inherits from class "SuperModel". My REST request returns an object of one of these classes. Now i want to document that in my Swagger UI that either an object of SubModel OR an object of SuperModel will be returned. I googled for this use case and found the @ApiModel annotations but they dont work, does anybody have an idea what i´m doing wrong here?

@ApiModel(value = "SuperModel", discriminator = "foo", subTypes = { 
SubModel.class })
public class SuperModel
{
    @ApiModelProperty(required = true)
    private String foo;

    public String getFoo() {
        return this.foo;
    }

    public void setFoo( String foo ) {
        this.foo = foo;
    }
}  

@ApiModel(value = "SubModel")
public class SubModel extends SuperModel
{
    private int    number;

    public int getNumber() {
        return this.number;
    }

    public void setNumber( int number ) {
        this.number = number;
    }
}

What i see in Swagger UI is only:

SuperModel {
  foo (string)
}

I found the example at this site: https://github.com/swagger-api/swagger-core/wiki/Annotations#apiresponses-apiresponse but it doesnt work :-(

Any ideas? Thanks a lot!

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

This is not supported in springfox yet. See https://github.com/springfox/springfox/issues/868

Yes, it's confusing, since they do have annotations with attributes like "discriminator" and "subTypes", but they don't work.

UPDATE: the issue was closed in the meantime (in March 2018), and it should work in Springfox >= 2.9.0 (haven't tested it myself)

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda