generate uri from dynamic @RequestMapping in spring

Viewed 261

I'm using openapi-generator-maven-plugin to generate our api from an openapi spec.

The generator creates controllers with an @RequestMapping("${openapi.appname.base-path:/api}") annotation.

So far so good. But when I try to build an URI for a specific method of this controller, things start to get messy.

I have the following method in my service

    @Override
    public ResponseEntity<Void> createAwards(Awards awards) {

        AwardsEntity entity = AwardsMapper.toEntity(awards);
        entity = repository.save(entity);

        UriComponents uriComponents = MvcUriComponentsBuilder.fromMethodName(
                AwardsApiController.class, "getAwardsById", entity.getId()).buildAndExpand();
        return ResponseEntity.created(uriComponents.toUri()).build();
    }

This code runs without an exception, but the resulting URI in the Location header looks like this

http://localhost:8080/$%7Bopenapi.oscarVoting.base-path:/api%7D/awards/3

The MvcUriComponentsBuilder treats the ${openapi.oscarVoting.base-path:/api} part as an path parameter and url-encodes it.

Is there any way to fix this?

0 Answers
Related