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

torand / jsonschema2java / 18399814123

10 Oct 2025 07:35AM UTC coverage: 78.214% (-0.9%) from 79.157%
18399814123

push

github

torand
fix: bean validation annotations on primitive subtypes of compound pojo property types now generated

287 of 413 branches covered (69.49%)

Branch coverage included in aggregate %.

440 of 533 new or added lines in 26 files covered. (82.55%)

1 existing line in 1 file now uncovered.

808 of 987 relevant lines covered (81.86%)

4.75 hits per line

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

80.0
/src/main/java/io/github/torand/jsonschema2java/collectors/EnumInfoCollector.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.jsonschema2java.collectors;
17

18
import io.github.torand.jsonschema2java.generators.Options;
19
import io.github.torand.jsonschema2java.model.AnnotationInfo;
20
import io.github.torand.jsonschema2java.model.EnumInfo;
21
import io.github.torand.jsonschema2java.utils.JsonSchemaDef;
22

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

27
import static io.github.torand.jsonschema2java.collectors.Extensions.EXT_MODEL_SUBDIR;
28
import static io.github.torand.jsonschema2java.utils.StringUtils.joinCsv;
29

30
/**
31
 * Collects information about an enum from a schema.
32
 */
33
public class EnumInfoCollector extends BaseCollector {
34

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

39
    public EnumInfo getEnumInfo(String name, JsonSchemaDef schema) {
40
        Optional<String> maybeModelSubdir = schema.extensions().getString(EXT_MODEL_SUBDIR);
5✔
41

42
        EnumInfo enumInfo = new EnumInfo(name, schema.enums().toList())
9✔
43
            .withModelSubdir(maybeModelSubdir.orElse(null))
6✔
44
            .withModelSubpackage(maybeModelSubdir.map(this::dirPath2PackagePath).orElse(null));
6✔
45

46
        if (opts.addMpOpenApiAnnotations()) {
4!
47
            enumInfo = enumInfo.withAddedAnnotation(getSchemaAnnotation(name, schema));
7✔
48
        }
49

50
        if (schema.isDeprecated()) {
3!
NEW
51
            enumInfo = enumInfo.withAddedAnnotation(new AnnotationInfo("@Deprecated"));
×
52
        }
53

54
        return enumInfo;
2✔
55
    }
56

57
    private AnnotationInfo getSchemaAnnotation(String name, JsonSchemaDef pojo) {
58
        String description = pojo.description();
3✔
59

60
        List<String> schemaParams = new ArrayList<>();
4✔
61
        schemaParams.add("name = \"%s\"".formatted(modelName2SchemaName(name)));
13✔
62
        schemaParams.add("description = \"%s\"".formatted(normalizeDescription(description)));
13✔
63
        if (pojo.isDeprecated()) {
3!
64
            schemaParams.add("deprecated = true");
×
65
        }
66

67
        return new AnnotationInfo(
9✔
68
            "@Schema(%s)".formatted(joinCsv(schemaParams)),
5✔
69
            "org.eclipse.microprofile.openapi.annotations.media.Schema"
70
        );
71
    }
72
}
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