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.rulemgt.resources;
19 import jakarta.ws.rs.Produces;
20 import jakarta.ws.rs.core.MediaType;
21 import lombok.extern.slf4j.Slf4j;
22 import org.springframework.web.bind.annotation.GetMapping;
23 import org.springframework.web.bind.annotation.RequestMapping;
24 import org.springframework.web.bind.annotation.RestController;
28 import java.net.URLDecoder;
31 @RequestMapping("/swagger.json")
33 public class SwaggerResource {
36 @Produces(MediaType.APPLICATION_JSON)
37 public String getSwaggerJson() {
38 URL url = SwaggerResource.class.getResource("/swagger.json");
43 System.out.println(URLDecoder.decode(url.getPath(), "UTF-8"));
44 file = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
45 } catch(IOException e) {
46 log.warn("An error occurred while reading swagger.json.", e);
49 try(BufferedReader br = new BufferedReader(new FileReader(file));) {
50 StringBuffer buffer = new StringBuffer();
52 while ((line = br.readLine()) != null) {
55 ret = buffer.toString();
56 } catch (FileNotFoundException e) {
57 log.warn("Failed to read the API description file.", e);
58 } catch (IOException e) {
59 log.warn("An error occurred while reading swagger.json.", e);