• 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/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.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.EnumInfo;
21
import io.swagger.v3.oas.models.media.Schema;
22

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

27
import static io.github.torand.openapi2java.collectors.Extensions.EXT_MODEL_SUBDIR;
28
import static io.github.torand.openapi2java.collectors.Extensions.extensions;
29
import static io.github.torand.openapi2java.utils.StringUtils.joinCsv;
30
import static java.lang.Boolean.TRUE;
31

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

37
    public EnumInfoCollector(Options opts) {
38
        super(opts);
3✔
39
    }
1✔
40

41
    public EnumInfo getEnumInfo(String name, Schema<?> schema) {
42
        Optional<String> maybeModelSubdir = extensions(schema.getExtensions()).getString(EXT_MODEL_SUBDIR);
6✔
43

44
        EnumInfo enumInfo = new EnumInfo(name, (List<String>)schema.getEnum())
8✔
45
            .withModelSubdir(maybeModelSubdir.orElse(null))
6✔
46
            .withModelSubpackage(maybeModelSubdir.map(this::dirPath2PackagePath).orElse(null));
6✔
47

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

52
        if (TRUE.equals(schema.getDeprecated())) {
5!
NEW
53
            enumInfo = enumInfo.withAddedAnnotation(new AnnotationInfo("@Deprecated"));
×
54
        }
55

56
        return enumInfo;
2✔
57
    }
58

59
    private AnnotationInfo getSchemaAnnotation(String name, Schema<?> pojo) {
60
        String description = pojo.getDescription();
3✔
61

62
        List<String> schemaParams = new ArrayList<>();
4✔
63
        schemaParams.add("name = \"%s\"".formatted(modelName2SchemaName(name)));
13✔
64
        schemaParams.add("description = \"%s\"".formatted(normalizeDescription(description)));
13✔
65
        if (TRUE.equals(pojo.getDeprecated())) {
5!
66
            schemaParams.add("deprecated = true");
×
67
        }
68

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