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

torand / openapi2java / 15494024830

06 Jun 2025 03:23PM UTC coverage: 82.388%. First build
15494024830

push

github

torand
refactor: replace util package with dep

503 of 716 branches covered (70.25%)

Branch coverage included in aggregate %.

7 of 14 new or added lines in 5 files covered. (50.0%)

1415 of 1612 relevant lines covered (87.78%)

4.77 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.SecurityRequirementInfo;
20
import io.swagger.v3.oas.models.security.SecurityRequirement;
21

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

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

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

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

38
    public SecurityRequirementInfo getSequrityRequirementInfo(List<SecurityRequirement> securityRequirements) {
39
        SecurityRequirementInfo secReqInfo = new SecurityRequirementInfo();
4✔
40

41
        if (securityRequirements.size() > 1) {
4!
42
            throw new IllegalStateException("Multiple alternative security requirements not supported");
×
43
        }
44

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

50
        List<String> params = new ArrayList<>();
4✔
51

52
        secReqInfo.scheme = securityRequirement.keySet().iterator().next();
7✔
53
        params.add("name = \"%s\"".formatted(secReqInfo.scheme));
12✔
54

55
        secReqInfo.scopes = securityRequirement.get(secReqInfo.scheme);
7✔
56
        if (nonEmpty(secReqInfo.scopes)) {
4!
NEW
57
            params.add("scopes = %s".formatted(formatAnnotationNamedParam(quoteAll(secReqInfo.scopes))));
×
58
        }
59

60
        if (opts.addMpOpenApiAnnotations) {
4!
61
            secReqInfo.imports.add("org.eclipse.microprofile.openapi.annotations.security.SecurityRequirement");
5✔
62
            secReqInfo.annotations.add("@SecurityRequirement(%s)".formatted(joinCsv(params)));
13✔
63
        }
64

65
        return secReqInfo;
2✔
66
    }
67
}
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