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

knowledgepixels / nanopub-query / 30900389272

04 Aug 2026 10:22AM UTC coverage: 59.213% (+0.2%) from 58.987%
30900389272

Pull #153

github

web-flow
Merge f846a9e4d into e95371cce
Pull Request #153: fix(openapi): avoid YAML anchors in parameter schemas (#50)

629 of 1202 branches covered (52.33%)

Branch coverage included in aggregate %.

1839 of 2966 relevant lines covered (62.0%)

9.51 hits per line

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

80.82
src/main/java/com/knowledgepixels/query/OpenApiSpecPage.java
1
package com.knowledgepixels.query;
2

3
import com.knowledgepixels.query.GrlcSpec.InvalidGrlcSpecException;
4
import io.vertx.core.MultiMap;
5
import org.yaml.snakeyaml.DumperOptions;
6
import org.yaml.snakeyaml.Yaml;
7

8
import java.util.*;
9

10
/**
11
 * Page for Open API compliant specification.
12
 */
13
public class OpenApiSpecPage {
14

15
    private Map<String, Object> dataMap = new LinkedHashMap<>();
15✔
16

17
    /**
18
     * Creates a new page instance.
19
     *
20
     * @param requestUrl The request URL
21
     * @param parameters The URL request parameters
22
     * @throws InvalidGrlcSpecException If the GRLC specification is invalid
23
     */
24
    public OpenApiSpecPage(String requestUrl, MultiMap parameters) throws InvalidGrlcSpecException {
6✔
25
        GrlcSpec grlcSpec = new GrlcSpec(requestUrl, parameters);
18✔
26

27

28
        dataMap.put("openapi", "3.0.4");
18✔
29

30
        Map<String, Object> infoMap = new LinkedHashMap<>();
12✔
31
        infoMap.put("title", grlcSpec.getLabel());
18✔
32
        infoMap.put("description", "API definition source: <a target=\"_blank\" href=\"" + grlcSpec.getNanopub().getUri() +
27✔
33
                                   "\"><svg height=\"0.8em\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 8 8\"><path d=\"M5,8H8L3,0H0M8,4.8V0H5M0,3.2V8H3\"/></svg> " +
34
                                   grlcSpec.getArtifactCode().substring(0, 10) + "</a>");
15✔
35
        infoMap.put("version", grlcSpec.getArtifactCode().substring(0, 10));
27✔
36
        dataMap.put("info", infoMap);
18✔
37

38
        List<Object> serversList = new ArrayList<>();
12✔
39
        Map<String, Object> serverMap = new LinkedHashMap<>();
12✔
40
        serverMap.put("url", Utils.getEnvString("NANOPUB_QUERY_URL", "http://localhost:9393/") + "api/" + grlcSpec.getArtifactCode());
30✔
41
        serverMap.put("description", "This Nanopub Query instance");
15✔
42
        serversList.add(serverMap);
12✔
43
        dataMap.put("servers", serversList);
18✔
44

45
        Map<String, Object> pathsMap = new LinkedHashMap<>();
12✔
46
        Map<String, Object> rootPathMap = new LinkedHashMap<>();
12✔
47
        Map<String, Object> getOpMap = new LinkedHashMap<>();
12✔
48
        //getOpMap.put("summary", label);
49
        getOpMap.put("description", grlcSpec.getDescription());
18✔
50
        Map<String, Object> responsesMap = new LinkedHashMap<>();
12✔
51
        Map<String, Object> successrespMap = new LinkedHashMap<>();
12✔
52
        Map<String, Object> contentMap = new LinkedHashMap<>();
12✔
53
        if (grlcSpec.isConstructQuery()) {
9!
54
            contentMap.put("text/turtle", new HashMap<>());
×
55
            contentMap.put("application/ld+json", new HashMap<>());
×
56
            contentMap.put("application/n-triples", new HashMap<>());
×
57
            contentMap.put("application/trix", new HashMap<>());
×
58
            contentMap.put("application/xml", new HashMap<>());
×
59
        } else {
60
            contentMap.put("text/csv", new HashMap<>());
21✔
61
            contentMap.put("application/json", new HashMap<>());
21✔
62
            contentMap.put("application/xml", new HashMap<>());
21✔
63
        }
64
        successrespMap.put("content", contentMap);
15✔
65
        successrespMap.put("description", "result table");
15✔
66
        responsesMap.put("200", successrespMap);
15✔
67
        List<Object> parametersList = new ArrayList<>();
12✔
68

69
        for (String p : grlcSpec.getPlaceholdersList()) {
33✔
70
            Map<String, Object> paramMap = new LinkedHashMap<>();
12✔
71
            paramMap.put("in", "query");
15✔
72
            String name = GrlcSpec.getParamName(p);
9✔
73
            paramMap.put("name", name);
15✔
74
            paramMap.put("required", !GrlcSpec.isOptionalPlaceholder(p));
33✔
75
            // A fresh schema map is created for each parameter on purpose: sharing a single map
76
            // instance across parameters makes SnakeYAML emit YAML anchors/aliases (&id/*id), which
77
            // some OpenAPI validators fail to resolve (see issue #50).
78
            final Map<String, Object> stringType = new LinkedHashMap<>();
12✔
79
            stringType.put("type", "string");
15✔
80
            if (GrlcSpec.isMultiPlaceholder(p)) {
9!
81
                final Map<String, Object> stringListType = new LinkedHashMap<>();
×
82
                stringListType.put("type", "array");
×
83
                stringListType.put("items", stringType);
×
84
                paramMap.put("style", "form");
×
85
                paramMap.put("explode", true);
×
86
                paramMap.put("schema", stringListType);
×
87
            } else {
×
88
                paramMap.put("schema", stringType);
15✔
89
            }
90
            parametersList.add(paramMap);
12✔
91
        }
3✔
92
        getOpMap.put("parameters", parametersList);
15✔
93
        getOpMap.put("responses", responsesMap);
15✔
94
        rootPathMap.put("get", getOpMap);
15✔
95
        pathsMap.put("/" + grlcSpec.getQueryName(), rootPathMap);
21✔
96
        dataMap.put("paths", pathsMap);
18✔
97
    }
3✔
98

99
    /**
100
     * Returns the Open API spec as a string.
101
     *
102
     * @return Open API specification string
103
     */
104
    public String getSpec() {
105
        final DumperOptions options = new DumperOptions();
12✔
106
        options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
9✔
107
        options.setPrettyFlow(true);
9✔
108
        return new Yaml(options).dump(dataMap);
24✔
109
    }
110

111
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc