340.3. API doc에 보안 정의 추가

Camel 2.22.0 사용

이제 Rest DSL은 생성된 API 문서에서 Swagger 보안Definitions 선언을 지원합니다. 예를 들면 다음과 같습니다.

rest("/user").tag("dude").description("User rest service")
    // setup security definitions
    .securityDefinitions()
        .oauth2("petstore_auth").authorizationUrl("http://petstore.swagger.io/oauth/dialog").end()
        .apiKey("api_key").withHeader("myHeader").end()
    .end()
    .consumes("application/json").produces("application/json")

여기에서는 두 가지 보안 정의를 설정했습니다.

  • OAuth2 - 제공된 url을 사용한 암시적 권한 부여 사용
  • API Key - myHeader라는 HTTP 헤더에서 제공되는 api 키 사용

그런 다음 키(petstore_auth 또는 api_key)를 참조하여 사용할 나머지 작업을 지정해야 합니다.

.get("/{id}/{date}").description("Find user by id and date").outType(User.class)
    .security("api_key")

...

.put().description("Updates or create a user").type(User.class)
    .security("petstore_auth", "write:pets,read:pets")

여기에서 get operation은 Api Key 보안을 사용하고 있으며 put 작업은 읽기 및 쓰기 반려동물의 허용 범위와 함께 OAuth 보안을 사용하고 있습니다.