Skip to content

"Override" example value when extending a class #4863

Open
@HenrikHL

Description

@HenrikHL

I was wondering if the following is possible:
I have a Name object being reused in different objects:

import io.swagger.v3.oas.annotations.media.Schema;

@Schema(type = "string", example = "Henrik")
public class Name {}

The Name object is used many places, e.g. in an Address object:

import io.swagger.v3.oas.annotations.media.Schema;

public class Address {
  @Schema(description = "The name of a person", 
  public Name name;
  ...
}

The expected output looks like this:

Address:
  name:
    description: "The name of a person"
    type: "string"
    example: "Henrik"

so far so good 😊
Name is also used in the Car object (but here I want to use another example value for the name-property e.g. Audi)

import io.swagger.v3.oas.annotations.media.Schema;

public class Car {
  @Schema(description = "Name of a car", example = "Audi")
  public Name name;
  ...
}

This does not work! Expected outcome is:

Car:
  name:
    description: "The name of a car"
    type: "string"
    example: "Audi"

but instead I get:

Car:
  name:
    description: "The name of a car"
    type: "string"
    example: "Henrik"

So example value defined on the name-property in the Car object is ignored... ☹️

It will only accept the description in Address and Car objects because description is not defined in Name object. It will not accept the "overwriting" of example="Audi" in the Car object. Why is this the case? Is it a feature or a Bug?

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