swagger-api / swagger-api/swagger-codegen
[JAVA] Support Javax injection for creation of API delegate instead of static factory pattern
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Replace/Complement static factory with DI injection
Currently, the generator for jersey and rest-easy use the static factory pattern to create the delegate that gets called by the REST API.
Swagger-codegen version
Whatever version this gradle plugin in using, (I think it's the current release).
Swagger declaration file content or url
Use the pet-store as an example.
Command line used for generation
swagger {
inputSpec = "${project.projectDir.path}/spec/swagger.yaml"
output = 'build/swagger'
language = 'jaxrs-resteasy'
additionalProperties = [
'invokerPackage' : 'edu.wpi.grip.web.swagger',
'modelPackage' : 'edu.wpi.grip.web.swagger.model',
'apiPackage' : 'edu.wpi.grip.web.swagger.api',
'serializableModel': 'true'
]
apis = ''
models = ''
supportingFiles = ''
}
Suggest a Fix
I'm using a custom api.mustache file that replaces the delegate creation with constructor injection.
import javax.inject.Inject;
public class {{classname}} {
private final {{classname}}Service delegate;
@Inject
{{classname}}({{classname}}Service delegate) {
this.delegate = delegate;
}
If a zero argument constructor is needed for other reasons and other frameworks both solutions could be implemented in parallel.
import javax.inject.Inject;
public class {{classname}} {
private final {{classname}}Service delegate;
{{classname}}() { // Zero argument constructor because some frameworks need this
this({{classname}}ServiceFactory.get{{classname}}(););
}
@Inject
{{classname}}({{classname}}Service delegate) {
this.delegate = delegate;
}
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 reading the jersey and rest-easy API generation templates, including the custom api.mustache example, and generate the pet-store API with the provided Gradle configuration. Compare the generated delegate construction with the requested javax.inject constructor approach and verify whether the zero-argument factory path must remain available for other frameworks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend-api-design, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100