Skip to content

"Override" example value when extending a class #4863

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

Open
HenrikHL opened this issue Mar 19, 2025 · 0 comments
Open

"Override" example value when extending a class #4863

HenrikHL opened this issue Mar 19, 2025 · 0 comments

Comments

@HenrikHL
Copy link

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?

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

1 participant