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

torand / openapi2java / 18309258705

07 Oct 2025 10:08AM UTC coverage: 81.939% (-0.01%) from 81.952%
18309258705

push

github

torand
fix: sonar qube issues

548 of 785 branches covered (69.81%)

Branch coverage included in aggregate %.

6 of 9 new or added lines in 3 files covered. (66.67%)

1 existing line in 1 file now uncovered.

1616 of 1856 relevant lines covered (87.07%)

5.1 hits per line

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

80.0
/src/main/java/io/github/torand/openapi2java/collectors/Extensions.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.utils.OpenApi2JavaException;
19

20
import java.util.Collections;
21
import java.util.List;
22
import java.util.Map;
23
import java.util.Optional;
24

25
import static io.github.torand.javacommons.lang.StringHelper.nonBlank;
26
import static java.util.Objects.isNull;
27
import static java.util.Objects.nonNull;
28

29
/**
30
 * Handles custom OpenAPI format extensions.
31
 */
32
public class Extensions {
33
    public static final String EXT_RESTCLIENT_CONFIGKEY = "x-restclient-configkey";
34
    public static final String EXT_RESTCLIENT_HEADERS = "x-restclient-headers";
35
    public static final String EXT_RESTCLIENT_HEADERSFACTORY = "x-restclient-headersfactory";
36
    public static final String EXT_RESTCLIENT_PROVIDERS = "x-restclient-providers";
37
    public static final String EXT_JSON_SERIALIZER = "x-json-serializer";
38
    public static final String EXT_VALIDATION_CONSTRAINT = "x-validation-constraint";
39
    public static final String EXT_NULLABLE = "x-nullable";
40
    public static final String EXT_MODEL_SUBDIR = "x-model-subdir";
41
    public static final String EXT_DEPRECATION_MESSAGE = "x-deprecation-message";
42

43
    private final Map<String, Object> extensionsByName;
44

45
    public static Extensions extensions(Map<String, Object> extensionsByName) {
46
        return new Extensions(extensionsByName);
5✔
47
    }
48

49
    private Extensions(Map<String, Object> extensionsByName) {
2✔
50
        this.extensionsByName = nonNull(extensionsByName) ? extensionsByName : Collections.emptyMap();
8✔
51
    }
1✔
52

53
    public Optional<String> getString(String name) {
54
        Object value = extensionsByName.get(name);
5✔
55
        if (isNull(value)) {
3✔
56
            return Optional.empty();
2✔
57
        }
58
        if (!(value instanceof String)) {
3!
59
            throw new OpenApi2JavaException("Value of extension %s is not a String".formatted(name));
×
60
        }
61
        if (nonBlank((String)value)) {
4!
62
            return Optional.of((String)value);
4✔
63
        }
64

65
        return Optional.empty();
×
66
    }
67

68
    public Optional<List<String>> getStringArray(String name) {
69
        Object value = extensionsByName.get(name);
5✔
70
        if (isNull(value)) {
3✔
71
            return Optional.empty();
2✔
72
        }
73
        if (!(value instanceof List)) {
3!
NEW
74
            throw new OpenApi2JavaException("Value of extension %s is not an array".formatted(name));
×
75
        }
76

77
        return Optional.of((List<String>)value);
4✔
78
    }
79

80
    public Optional<Boolean> getBoolean(String name) {
81
        Object value = extensionsByName.get(name);
5✔
82
        if (isNull(value)) {
3✔
83
            return Optional.empty();
2✔
84
        }
85
        if (!(value instanceof Boolean)) {
3!
86
            throw new OpenApi2JavaException("Value of extension %s is not a Boolean".formatted(name));
×
87
        }
88

89
        return Optional.of((Boolean)value);
4✔
90
    }
91

92
    public Optional<Map<String, Object>> getMap(String name) {
93
        Object value = extensionsByName.get(name);
5✔
94
        if (isNull(value)) {
3✔
95
            return Optional.empty();
2✔
96
        }
97
        if (!(value instanceof Map)) {
3!
NEW
98
            throw new OpenApi2JavaException("Value of extension %s is not a Map (object)".formatted(name));
×
99
        }
100

101
        return Optional.of((Map<String, Object>)value);
4✔
102
    }
103
}
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