• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

torand / openapi2java / 18202480060

02 Oct 2025 06:44PM UTC coverage: 81.561% (-0.8%) from 82.388%
18202480060

push

github

web-flow
Merge pull request #48 from torand/refactor-info-classes

Refactor info classes

507 of 736 branches covered (68.89%)

Branch coverage included in aggregate %.

825 of 934 new or added lines in 38 files covered. (88.33%)

11 existing lines in 7 files now uncovered.

1541 of 1775 relevant lines covered (86.82%)

5.09 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

73.08
/src/main/java/io/github/torand/openapi2java/collectors/SecurityRequirementCollector.java
1
/*
2
 * Copyright (c) 2024-2025 Tore Eide Andersen
3
 *
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
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
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.
15
 */
16
package io.github.torand.openapi2java.collectors;
17

18
import io.github.torand.openapi2java.generators.Options;
19
import io.github.torand.openapi2java.model.AnnotationInfo;
20
import io.github.torand.openapi2java.model.SecurityRequirementInfo;
21
import io.swagger.v3.oas.models.security.SecurityRequirement;
22

23
import java.util.ArrayList;
24
import java.util.List;
25

26
import static io.github.torand.javacommons.collection.CollectionHelper.nonEmpty;
27
import static io.github.torand.javacommons.lang.StringHelper.quoteAll;
28
import static io.github.torand.openapi2java.utils.StringUtils.joinCsv;
29

30
/**
31
 * Collects information about a security requirement from a collection of OpenAPI security requirements.
32
 */
33
public class SecurityRequirementCollector extends BaseCollector {
34

35
    public SecurityRequirementCollector(Options opts) {
36
        super(opts);
3✔
37
    }
1✔
38

39
    public SecurityRequirementInfo getSequrityRequirementInfo(List<SecurityRequirement> securityRequirements) {
40
        if (securityRequirements.size() > 1) {
4!
UNCOV
41
            throw new IllegalStateException("Multiple alternative security requirements not supported");
×
42
        }
43

44
        SecurityRequirement securityRequirement = securityRequirements.get(0);
5✔
45
        if (securityRequirement.size() > 1) {
4!
46
            throw new IllegalStateException("Multiple mandatory security scheme names not supported");
×
47
        }
48

49
        String scheme = securityRequirement.keySet().iterator().next();
6✔
50

51
        SecurityRequirementInfo secReqInfo = new SecurityRequirementInfo(scheme)
6✔
52
            .withScopes(securityRequirement.get(scheme));
4✔
53

54
        if (opts.addMpOpenApiAnnotations()) {
4!
55
            List<String> params = new ArrayList<>();
4✔
56
            params.add("name = \"%s\"".formatted(scheme));
11✔
57
            if (nonEmpty(secReqInfo.scopes())) {
4!
NEW
58
                params.add("scopes = %s".formatted(formatAnnotationNamedParam(quoteAll(secReqInfo.scopes()))));
×
59
            }
60

61
            secReqInfo = secReqInfo.withAnnotation(
11✔
62
                new AnnotationInfo("@SecurityRequirement(%s)".formatted(joinCsv(params)), "org.eclipse.microprofile.openapi.annotations.security.SecurityRequirement")
5✔
63
            );
64
        }
65

66
        return secReqInfo;
2✔
67
    }
68
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc