swagger-api / swagger-api/swagger-core

[Feature]: Allow values in @ExampleObject to be read from a file

Open
#5,180 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

backlog Feature
Dominant language
Java
Stars
7.5k
Forks
2.3k
Avg merge
18h 1m
Merged PRs (30d)
10

Description

Feature Description

I would like to see a way to define example payloads in the @ExampleObject annotation from a file, rather than declaring constants for it.

  • What problem does it solve?
    For APIs with larger payloads, defining payloads with @ExampleObjects becomes unmanageable because the examples must be defined as constants, resulting in boilerplate code in Java classes.
  • How would it improve swagger-core?
    It will make it easier to maintain large example payloads without creating constants in Java.
  • Is it related to OpenAPI spec support, annotation improvements, integration, etc.?
    It would be categorized as annotation improvement.

Use Case

@ExampleObject ( description = "test description", file = "classpath:/main/resources/openapi/test-example.json")

Suggested Solution (optional)

Add a feature in the @ExampleObject annotation to read a value from a file.

Alternatives Considered

Additional Context

Checklist

  • I have searched the existing issues to ensure this is not a duplicate.
  • This feature would be useful to more than just my use case.
  • I have provided enough detail for the maintainers to understand the scope of the request.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the @ExampleObject annotation and the code that processes its example values. Check the related annotation tests, then verify that a file or classpath resource can supply the example payload while preserving the existing description behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.