aboutsummaryrefslogtreecommitdiffstats
path: root/ms/sliboot/src/main/templates/api.mustache
blob: 91483eda6a532c0797f212afe8c3d6f7133685c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/**
* NOTE: This class is auto generated by the swagger code generator program ({{{generatorVersion}}}).
* https://github.com/swagger-api/swagger-codegen
* Do not edit the class manually.
*/
package {{package}};

{{#imports}}import {{import}};
{{/imports}}
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
{{#useBeanValidation}}
    import org.springframework.validation.annotation.Validated;
{{/useBeanValidation}}
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;
import org.onap.ccsdk.apps.services.RestException;


{{#jakarta}}
import jakarta.servlet.*;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
{{/jakarta}}
{{^jakarta}}
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
{{/jakarta}}
{{#useBeanValidation}}
{{#jakarta}}
import jakarta.validation.Valid;
import jakarta.validation.constraints.*;
{{/jakarta}}
{{^jakarta}}
import javax.validation.Valid;
import javax.validation.constraints.*;
{{/jakarta}}
{{/useBeanValidation}}
import java.io.IOException;
import java.util.List;
import java.util.Optional;
{{#async}}
import java.util.concurrent.{{^jdk8}}Callable{{/jdk8}}{{#jdk8}}CompletableFuture{{/jdk8}};
{{/async}}
{{>generatedAnnotation}}
@Api(value = "{{{baseName}}}", description = "the {{{baseName}}} API")
{{#operations}}
    public interface {{classname}} {

        {{^isDelegate}}
            Logger log = LoggerFactory.getLogger({{classname}}.class);

            default Optional<ObjectMapper> getObjectMapper() {
                return Optional.empty();
                }

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

                default Optional<String> getAcceptHeader() {
                return getRequest().map(r -> r.getHeader("Accept"));
                }
        {{/isDelegate}}
        {{#isDelegate}}
            {{classname}}Delegate getDelegate();
        {{/isDelegate}}
    {{#operation}}

            @ApiOperation(value = "{{{summary}}}", nickname = "{{{operationId}}}", notes = "{{{notes}}}"{{#returnBaseType}}, response = {{{returnBaseType}}}.class{{/returnBaseType}}{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}}{{#hasAuthMethods}}, authorizations = {
        {{#authMethods}}@Authorization(value = "{{name}}"{{#isOAuth}}, scopes = {
        {{#scopes}}@AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{#hasMore}},
        {{/hasMore}}{{/scopes}}
            }{{/isOAuth}}){{#hasMore}},
        {{/hasMore}}{{/authMethods}}
            }{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}",{{/vendorExtensions.x-tags}} })
            @ApiResponses(value = { {{#responses}}
                @ApiResponse(code = {{{code}}}, message = "{{{message}}}"{{#baseType}}, response = {{{baseType}}}.class{{/baseType}}{{#containerType}}, responseContainer = "{{{containerType}}}"{{/containerType}}){{#hasMore}},{{/hasMore}}{{/responses}} })
        {{#implicitHeaders}}
                @ApiImplicitParams({
            {{#headerParams}}
                {{>implicitHeader}}
            {{/headerParams}}
                })
        {{/implicitHeaders}}
            @RequestMapping(value = "{{{path}}}",{{#singleContentTypes}}
                produces = "{{{vendorExtensions.x-accepts}}}",
                consumes = "{{{vendorExtensions.x-contentType}}}",{{/singleContentTypes}}{{^singleContentTypes}}{{#hasProduces}}
                produces = { {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }, {{/hasProduces}}{{#hasConsumes}}
                consumes = { {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} },{{/hasConsumes}}{{/singleContentTypes}}
            method = RequestMethod.{{httpMethod}})
            default {{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{#delegate-method}}_{{/delegate-method}}{{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{/allParams}}) throws RestException {
        {{#delegate-method}}
                return {{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
                }

                // Override this method
                default {{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}({{#allParams}}{{^isFile}}{{{dataType}}}{{/isFile}}{{#isFile}}MultipartFile{{/isFile}} {{paramName}}{{#hasMore}},{{/hasMore}}{{/allParams}}) throws RestException {
        {{/delegate-method}}
        {{^isDelegate}}
                if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
            {{#examples}}
                    if (getAcceptHeader().get().contains("{{{contentType}}}")) {
                    try {
                    return {{#async}}CompletableFuture.completedFuture({{/async}}new ResponseEntity<>(getObjectMapper().get().readValue("{{#lambdaRemoveLineBreak}}{{#lambdaEscapeDoubleQuote}}{{{example}}}{{/lambdaEscapeDoubleQuote}}{{/lambdaRemoveLineBreak}}", {{>exampleReturnTypes}}.class), HttpStatus.NOT_IMPLEMENTED){{#async}}){{/async}};
                    } catch (IOException e) {
                    log.error("Couldn't serialize response for content type {{{contentType}}}", e);
                    return {{#async}}CompletableFuture.completedFuture({{/async}}new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR){{#async}}){{/async}};
                    }
                    }
            {{/examples}}
                } else {
                log.warn("ObjectMapper or HttpServletRequest not configured in default {{classname}} interface so no example is generated");
                }
                return {{#async}}CompletableFuture.completedFuture({{/async}}new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED){{#async}}){{/async}};
        {{/isDelegate}}
        {{#isDelegate}}
                return getDelegate().{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
        {{/isDelegate}}
            }

    {{/operation}}
        }
{{/operations}}