2 * Copyright 2017-2022 ZTE Corporation.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.holmes.engine.resources;
19 import lombok.extern.slf4j.Slf4j;
20 import org.springframework.web.bind.annotation.GetMapping;
21 import org.springframework.web.bind.annotation.RequestMapping;
22 import org.springframework.web.bind.annotation.RestController;
24 import jakarta.ws.rs.core.MediaType;
25 import java.io.BufferedReader;
27 import java.io.FileReader;
28 import java.io.IOException;
30 import java.net.URLDecoder;
34 @RequestMapping("/swagger.json")
35 public class SwaggerResource {
37 @GetMapping(produces = MediaType.APPLICATION_JSON)
38 public String getSwaggerJson() {
39 URL url = SwaggerResource.class.getResource("/swagger.json");
44 System.out.println(URLDecoder.decode(url.getPath(), "UTF-8"));
45 file = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
46 } catch (IOException e) {
47 log.warn("An error occurred while decoding url");
51 log.warn("Unable to get Swagger Json since API description file could not be read");
55 try (BufferedReader br = new BufferedReader(new FileReader(file))) {
56 StringBuffer buffer = new StringBuffer();
58 while ((line = br.readLine()) != null) {
61 ret = buffer.toString();
62 } catch (IOException e) {
63 log.warn("An error occurred while reading swagger.json.");