• 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

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.Map;
22
import java.util.Optional;
23

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

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

39
    private final Map<String, Object> schemaExtensions;
40

41
    public static Extensions extensions(Map<String, Object> schemaExtensions) {
42
        return new Extensions(schemaExtensions);
5✔
43
    }
44

45
    public Extensions(Map<String, Object> schemaExtensions) {
2✔
46
        this.schemaExtensions = nonNull(schemaExtensions) ? schemaExtensions : Collections.emptyMap();
8✔
47
    }
1✔
48

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

61
        return Optional.empty();
×
62
    }
63

64
    public Optional<Boolean> getBoolean(String name) {
65
        Object value = schemaExtensions.get(name);
5✔
66
        if (isNull(value)) {
3✔
67
            return Optional.empty();
2✔
68
        }
69
        if (!(value instanceof Boolean)) {
3!
NEW
70
            throw new OpenApi2JavaException("Value of extension %s is not a Boolean".formatted(name));
×
71
        }
72

73
        return Optional.of((Boolean)value);
4✔
74
    }
75
}
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