OpenAPITools / OpenAPITools/openapi-generator

[BUG] Openapi-generator spring: How to replace @RequestMapping(“${openapi.someproject.base-path:/v1}”)

Open
#10,077 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

I'm importing a jar file containing the RestResources generated with openapi-codegen

@Controller
@RequestMapping({"${openapi.someproject.base-path:/v1}"}) // <-- ${openapi.someproject.base-path:/v1} should be replaced by /v1
public class ApiApiController implements ApiApi {
private final ApiApiDelegate delegate;

public ApiApiController(@Autowired(required = false) ApiApiDelegate delegate) {
    this.delegate = (ApiApiDelegate)Optional.ofNullable(delegate).orElse(new ApiApiDelegate() {
    });
}

When deploying my application is see an endpoint named "${openapi.someproject.base-path:/v1}". When I use Spring Hateoas:

linkTo(methodOn(ApiApiController.class).methodName(Optional.empty()))
            .withSelfRel()
            .getHref();

Url become this:
http://localhost:8080/application-name${openapi.productOrdering.base-pathv1}{?fields}
Is there anyway to remove ${openapi.productOrdering.base-path ?

The imported jar was generated as follows with the openapi-generator-maven-plugin:

<groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>3.3.0</version>
                <executions>
                    <execution>
                        <id>back-end-swagger</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>${project.basedir}/src/main/resources/swagger/api.yml</inputSpec>
                            <generatorName>spring</generatorName>
                            <apiPackage>com.test.api</apiPackage>
                            <modelPackage>com.test.api.model</modelPackage>                                <supportingFilesToGenerate>ApiUtil.java</supportingFilesToGenerate>
                            <validateSpec>true</validateSpec>
                            <configOptions>
                                <delegatePattern>true</delegatePattern>
                            </configOptions>
                        </configuration>
                    </execution>

The api.yml file looks as follows:

swagger: "2.0"
info:
  version: "1.0.0"
  title: "someproject"
host: "somehost.io"
basePath: "/v1"
tags:
- name: "endpoint"
schemes:
- "https"
- "http"
paths:
  /api/test:
    get:
      produces:
      - "application/json"
      responses:
        200:
          description: OK
openapi-generator version

I'm using version 5.1.1

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 reproducing the generated Spring output from the provided api.yml and openapi-generator-maven-plugin configuration, then inspect the generated ApiApiController and the Spring generator templates that produce its @RequestMapping value. Confirm whether the base path is resolved at runtime and whether the generated HATEOAS link is correct; done means the endpoint and link use /v1 rather than the unresolved placeholder.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.