openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

How to get the request path in code.

Open kush20 opened this issue 1 year ago • 1 comments

While implementing a POST body.

I want to return status of 201 Created along with the URI. However, how do i get the request-path in the first place..

@Override
public ResponseEntity<Void> createPet (Pet p ) {  
     Pet p1 = petRepository.save(p);
     return ResponseEntity.created("  request-path..  ?? "  + p1.id);   // <-- how can i get the input path here
}

i dont want to hard-code request-path.

  • Below is my (pretty regular) pom file.
<plugin>
  <groupId>org.openapitools</groupId>
  <artifactId>openapi-generator-maven-plugin</artifactId>
  <version>7.5.0</version>
  <executions>
    <execution>
      <goals>
        <goal>generate</goal>
      </goals>
      <configuration>
        <inputSpecRootDirectory> ${project.basedir}/src/main/resources/openapi
        </inputSpecRootDirectory>
        <generatorName>spring</generatorName>
        <apiPackage>com.example.openapi.api</apiPackage>
        <modelPackage>com.example.openapi.model</modelPackage>
        <configOptions>
          <modelSuffix>Dto</modelSuffix>
          <useJakartaEe>true</useJakartaEe>
          <library>spring-boot</library>
          <delegatePattern>true</delegatePattern>
          <hideGenerationTimestamp>true</hideGenerationTimestamp>
          <interfaceOnly>true</interfaceOnly>
          <useSpringBoot3>true</useSpringBoot3>
          <useSpringfox>false</useSpringfox>
        </configOptions>
      </configuration>
    </execution>
  </executions>
</plugin>
```
</details>

kush20 avatar May 18 '24 06:05 kush20

Hi @kush20. I might misinterpred your question, but if your question is how to get the request path of the request made to the spring controller. I don't think this is a bug of the generator. This is existing Spring functionality, you can use HttpServletRequest to get the request path of the current request handling thread.

stefankoppier avatar May 19 '24 17:05 stefankoppier