原创

如何在 Spring Boot OpenAPI 委托中获取对 HTTP 请求的引用?

温馨提示:
本文最后更新于 2024年04月12日,已超过 48 天没有更新。若文章内的图片失效(无法正常加载),请留言反馈或直接联系我

我正在尝试使用 Spring Boot 和 OpenAPI 代码生成器来实现 OpenAPI 规范。我浏览了网上能找到的所有内容,并能够生成 OpenAPI 存根。我使用 editor.swagger.io 上的示例规范作为存根。现在我尝试提供这样的实现:

public class PetApiDelegateImpl implements PetApiDelegate {
    /**
     * POST /pet : Add a new pet to the store
     * Add a new pet to the store
     *
     * @param pet Create a new pet in the store (required)
     * @return Successful operation (status code 200)
     *         or Invalid input (status code 400)
     *         or Validation exception (status code 422)
     * @see PetApi#addPet
     */
    @Override
    ResponseEntity<Pet> addPet(Pet pet) {
      // TODO: fill out the implementation
    }
}

我面临的问题是我想在方法中获取对 HTTP 请求的引用,但看起来没有办法获取它。例如,如果我查看存根 [1]:

/**
 * A delegate to be called by the {@link PetApiController}}.
 * Implement this interface with a {@link org.springframework.stereotype.Service} annotated class.
 */
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2024-04-10T14:44:58.115530-07:00[America/Los_Angeles]", comments = "Generator version: 7.4.0")
public interface PetApiDelegate {

    default Optional<NativeWebRequest> getRequest() {
        return Optional.empty();
    }

它只是返回空请求。

如何在我的委托方法中获取对HTTP请求的引用?

正文到此结束
热门推荐
本文目录