[REQ] Generate Spring HTTP Interface with configurable URL placeholder via Spring properties
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 68/100
Research direction
Start with modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-http-interface/api.mustache and compare it with the example.yaml and generated ExampleService.java shown in the issue. Verify the generated @HttpExchange values support configurable Spring property placeholders while retaining the specification paths as defaults, including paths with variables such as /products/{productId}.
Written by the indexing model from the issue text.
Description
Description
This feature request proposes an enhancement to the OpenAPI Generator Java spring-http-interface. It aims to introduce the ability to generate interfaces annotated with @HttpExchange (Spring Framework 3) where the field url or value attribute can be configured using a placeholder with a default value (the path defined in the API specification).
This is a snippet of the current mustache template:
@HttpExchange(
method = "{{{httpMethod}}}",
value = "{{{path}}}",
accept = { {{#vendorExtensions.x-accepts}}"{{.}}"{{^-last}}, {{/-last}}{{/vendorExtensions.x-accepts}} }{{#vendorExtensions.x-content-type}},
contentType = "{{{vendorExtensions.x-content-type}}}"{{/vendorExtensions.x-content-type}}
)
Proposed Implementation
Update the mustache template to add a placeholder with a default value, for example:
@HttpExchange(
method = "{{{httpMethod}}}",
value = "${openapi.{{operationId}}.base-path:{{path}}}",
accept = { {{#vendorExtensions.x-accepts}}"{{.}}"{{^-last}}, {{/-last}}{{/vendorExtensions.x-accepts}} }{{#vendorExtensions.x-content-type}},
contentType = "{{{vendorExtensions.x-content-type}}}"{{/vendorExtensions.x-content-type}}
)
Creating a custom version of this template embedded into my application is not the best solution.
Does anyone know a way to achieve what I'm asking for using the current template?
Example
Snippet of API definition example.yaml
paths:
/users:
get:
summary: Get all users
operationId: getUsers
/products/{productId}:
get:
summary: Get a product by ID
operationId: getProductById
Generated ExampleService.java
public interface ExampleService {
@HttpExchange(
method = "GET",
value = "${openapi.getUsers.base-path:/users}",
accept = { "application/json" }
)
ResponseEntity<List<User>> getUsers();
@HttpExchange(
method = "GET",
value = "${openapi.getProductById.base-path:/products/{productId}",
accept = { "application/json" }
)
ResponseEntity<Product> getProductById(@PathVariable String productId);
}
Snippet of application.properties file
openapi.getUsers.base-path=/new/path/to/users
openapi.getProductById.base-path=/new/path/to/products/{productId}
Benefis
- Flexibility: this feature allows for dynamic configuration of API paths, potentially from environment variables or configuration files
- Maintainability: separating the path definition from the annotation improves code maintainability and reduces duplication
I hope the OpenAPI Generator maintainers find this feature useful. I would be happy to proceed with implementation. Thank you.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 103
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.
More from OpenAPITools/openapi-generator
-
Issue: Bug
Difficulty 1/5 Under an hour Newbie friendliness 91/100
OpenAPITools/openapi-generator#24978 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
OpenAPITools/openapi-generator#24975 ·
-
Issue: Bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
OpenAPITools/openapi-generator#24859 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
OpenAPITools/openapi-generator#24852 · 1 comment ·
-
[BUG][KOTLIN] Fails to compile after updating to 7.25.0 with useJackson3=false useSpringBoot4=true OpenIssue: Bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
OpenAPITools/openapi-generator#24842 · 1 comment ·
All issues in OpenAPITools/openapi-generator
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
infinispan/infinispan#18150 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
opensearch-project/k-NN#3597 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100