Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the request path in code. #18704

Open
kush20 opened this issue May 18, 2024 · 1 comment
Open

How to get the request path in code. #18704

kush20 opened this issue May 18, 2024 · 1 comment

Comments

@kush20
Copy link

kush20 commented May 18, 2024

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>
@stefankoppier
Copy link
Contributor

stefankoppier commented May 19, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants