swagger-api / swagger-api/swagger-codegen
How to generate common classes to a separate package and then reuse them
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
I can define common classes in a separate schema file:
common.json
{
...
"components": {
"schemas": {
"FinancialContext": {
...
}
}
}
and then reuse it in many other schemas:
"financialContext":
"$ref": "common.json#/components/schemas/FinancialContext"
}
but when I generate models using swagger-codegen-maven-plugin this class will be duplicated in each package for each schema (I cannot generate all the classes to the same package because they can have other classes with the same name, but different content).
I want to be able to generate common.json to a separate package (this is actually possible now) and then all other executions of the plugin should import already generated classes from the common package instead of generating copies of the class in the apis packages.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the swagger-codegen-maven-plugin flow for generating a separate package from common.json, then inspect how $ref schemas are handled in subsequent executions. The change is complete when generated API packages import the existing common-package classes instead of duplicating them, while same-named schemas with different content remain separate.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, json
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100