Skip to content

Commit 92ae10e

Browse files
committed
Merge remote-tracking branch 'upstream/master' into defect/exactly-one-item-dont-make-property-item-array
2 parents 5fc8ae4 + a69d201 commit 92ae10e

File tree

9 files changed

+189
-141
lines changed

9 files changed

+189
-141
lines changed

src/main/java/edu/isi/oba/Mapper.java

+10-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package edu.isi.oba;
22

3+
import edu.isi.oba.config.CONFIG_FLAG;
34
import edu.isi.oba.config.YamlConfig;
45
import static edu.isi.oba.Oba.logger;
56

@@ -33,17 +34,11 @@ class Mapper {
3334
YamlConfig config_data;
3435

3536
public OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
36-
private Boolean follow_references;
37-
private Boolean default_descriptions;
38-
private Boolean default_properties;
3937

4038
public Mapper(YamlConfig config_data) throws OWLOntologyCreationException, IOException {
4139
this.config_data = config_data;
4240
this.selected_paths = config_data.getPaths();
4341
this.mappedClasses = new ArrayList<>();
44-
this.follow_references = config_data.getFollow_references();
45-
this.default_descriptions = config_data.getDefault_descriptions();
46-
this.default_properties = config_data.getDefault_properties();
4742

4843
List<String> config_ontologies = config_data.getOntologies();
4944
String destination_dir = config_data.getOutput_dir() + File.separator + config_data.getName();
@@ -106,14 +101,10 @@ private void download_ontologies(List<String> config_ontologies, String destinat
106101
* The schemas includes the properties
107102
*
108103
* @param destination_dir directory to write the final results
109-
* @param config_data yaml configuration
110104
*/
111105
public void createSchemas(String destination_dir) {
112106
Query query = new Query(destination_dir);
113-
Path pathGenerator = new Path(this.config_data.getEnable_get_paths(),
114-
this.config_data.getEnable_post_paths(),
115-
this.config_data.getEnable_put_paths(),
116-
this.config_data.getEnable_delete_paths(),
107+
PathGenerator pathGenerator = new PathGenerator(this.config_data.getConfigFlags(),
117108
this.config_data.getAuth().getEnable()
118109
);
119110

@@ -148,7 +139,7 @@ public void createSchemas(String destination_dir) {
148139
}
149140
}
150141

151-
private void add_user_path(Path pathGenerator) {
142+
private void add_user_path(PathGenerator pathGenerator) {
152143
//User schema
153144
Map<String, Schema> userProperties = new HashMap<>();
154145
StringSchema username = new StringSchema();
@@ -165,7 +156,7 @@ private void add_user_path(Path pathGenerator) {
165156
this.paths.addPathItem("/user/login", pathGenerator.user_login(userSchema.getName()));
166157
}
167158

168-
private List<OWLClass> add_owlclass_to_openapi(Query query, Path pathGenerator, OWLOntology ontology,
159+
private List<OWLClass> add_owlclass_to_openapi(Query query, PathGenerator pathGenerator, OWLOntology ontology,
169160
String defaultOntologyPrefixIRI, OWLClass cls, Boolean topLevel) {
170161
List<OWLClass> ref = new ArrayList<>();
171162
String classPrefixIRI = cls.getIRI().getNamespace();
@@ -183,7 +174,7 @@ private List<OWLClass> add_owlclass_to_openapi(Query query, Path pathGenerator,
183174
if(ontology.containsClassInSignature(clsToCheck.getIRI())) {
184175
System.out.println("ADD "+ clsToCheck);
185176
for (OWLOntology temp_ontology : this.ontologies) {
186-
if (this.follow_references) {
177+
if (this.config_data.getConfigFlagValue(CONFIG_FLAG.FOLLOW_REFERENCES)) {
187178
this.mappedClasses.add(clsToCheck);
188179
this.getMapperSchema(query, temp_ontology, clsToCheck, this.schemaDescriptions.get(clsToCheck.getIRI()));
189180
this.add_owlclass_to_openapi(query, pathGenerator, temp_ontology, classPrefixIRI, clsToCheck, false);
@@ -199,7 +190,7 @@ private List<OWLClass> add_owlclass_to_openapi(Query query, Path pathGenerator,
199190
logger.info("The class " + ref_class + " exists ");
200191
} else {
201192
for (OWLOntology temp_ontology : this.ontologies) {
202-
if (this.follow_references) {
193+
if (this.config_data.getConfigFlagValue(CONFIG_FLAG.FOLLOW_REFERENCES)) {
203194
this.mappedClasses.add(ref_class);
204195
this.getMapperSchema(query, temp_ontology, ref_class,this.schemaDescriptions.get(ref_class.getIRI()));
205196
this.add_owlclass_to_openapi(query, pathGenerator, temp_ontology, classPrefixIRI, ref_class, false);
@@ -221,7 +212,7 @@ private List<OWLClass> add_owlclass_to_openapi(Query query, Path pathGenerator,
221212

222213
private MapperSchema getMapperSchema(Query query, OWLOntology ontology, OWLClass cls, String cls_description) {
223214
//Convert from OWL Class to OpenAPI Schema.
224-
MapperSchema mapperSchema = new MapperSchema(this.ontologies, cls, cls_description, this.schemaNames, ontology, this.follow_references, this.default_descriptions, this.default_properties);
215+
MapperSchema mapperSchema = new MapperSchema(this.ontologies, cls, cls_description, schemaNames, ontology, this.config_data.getConfigFlags());
225216
//Write queries
226217
query.write_readme(mapperSchema.name);
227218
//Create the OpenAPI schema
@@ -230,7 +221,7 @@ private MapperSchema getMapperSchema(Query query, OWLOntology ontology, OWLClass
230221
return mapperSchema;
231222
}
232223

233-
private void addOpenAPIPaths(Path pathGenerator, MapperSchema mapperSchema, OWLClass cls) {
224+
private void addOpenAPIPaths(PathGenerator pathGenerator, MapperSchema mapperSchema, OWLClass cls) {
234225
if (this.selected_classes != null && !this.selected_classes.contains(cls)) {
235226
logger.info("Ignoring class " + cls.toString());
236227
} else {
@@ -253,11 +244,11 @@ private void setSchemaNames(Set<OWLClass> classes) {
253244
private void setSchemaDrescriptions(Set<OWLClass> classes, OWLOntology ontology){
254245
for (OWLClass cls: classes) {
255246
System.out.println(cls);
256-
schemaDescriptions.put(cls.getIRI(), ObaUtils.getDescription(cls, ontology, this.default_descriptions));
247+
schemaDescriptions.put(cls.getIRI(), ObaUtils.getDescription(cls, ontology, this.config_data.getConfigFlagValue(CONFIG_FLAG.DEFAULT_DESCRIPTIONS)));
257248
}
258249
}
259250

260-
private void add_path(Path pathGenerator, MapperSchema mapperSchema) {
251+
private void add_path(PathGenerator pathGenerator, MapperSchema mapperSchema) {
261252
String singular_name = "/" + mapperSchema.name.toLowerCase() + "s/{id}";
262253
String plural_name = "/" + mapperSchema.name.toLowerCase() + "s";
263254
//Create the plural paths: for example: /models/

src/main/java/edu/isi/oba/MapperOperation.java

+21-24
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import io.swagger.models.Method;
44
import io.swagger.v3.oas.models.Operation;
5-
import io.swagger.v3.oas.models.headers.Header;
65
import io.swagger.v3.oas.models.media.*;
76
import io.swagger.v3.oas.models.parameters.Parameter;
87
import io.swagger.v3.oas.models.parameters.PathParameter;
@@ -30,14 +29,12 @@ class MapperOperation {
3029
private final ApiResponses apiResponses = new ApiResponses();
3130
private final Cardinality cardinality;
3231
private final Schema schema;
32+
private final Operation operation;
3333

3434
public Operation getOperation() {
3535
return operation;
3636
}
3737

38-
private final Operation operation;
39-
40-
4138
public MapperOperation(String schemaName, String schemaURI, Method method, Cardinality cardinality, Boolean auth) {
4239
this.auth = auth;
4340
this.cardinality = cardinality;
@@ -50,6 +47,9 @@ public MapperOperation(String schemaName, String schemaURI, Method method, Cardi
5047
case GET:
5148
setOperationGet();
5249
break;
50+
case PATCH:
51+
setOperationPatch();
52+
break;
5353
case PUT:
5454
setOperationPut();
5555
break;
@@ -59,7 +59,8 @@ public MapperOperation(String schemaName, String schemaURI, Method method, Cardi
5959
case DELETE:
6060
setOperationDelete();
6161
break;
62-
62+
default:
63+
break;
6364
}
6465

6566
if (cardinality == Cardinality.SINGULAR){
@@ -70,32 +71,30 @@ public MapperOperation(String schemaName, String schemaURI, Method method, Cardi
7071
.schema(new StringSchema()));
7172
}
7273

73-
if (auth && (method == Method.PUT || method == Method.POST || method == Method.DELETE )) {
74+
if (auth && Set.of(Method.PATCH, Method.PUT, Method.POST, Method.DELETE).contains(method)) {
7475
parameters.add(new QueryParameter()
7576
.description("Username")
7677
.name("user")
7778
.required(false)
7879
.schema(new StringSchema()));
7980
}
81+
8082
operation = new Operation()
8183
.description(description)
8284
.summary(summary)
8385
.addTagsItem(schemaName)
8486
.parameters(parameters)
8587
.responses(apiResponses);
8688

87-
88-
if (method == Method.PUT || method == Method.POST ){
89+
if (Set.of(Method.PATCH, Method.PUT, Method.POST).contains(method)) {
8990
operation.setRequestBody(requestBody);
9091
}
9192

92-
93-
if (method == Method.PUT || method == Method.POST || method == Method.DELETE ){
93+
if (Set.of(Method.PATCH, Method.PUT, Method.POST, Method.DELETE).contains(method)) {
9494
SecurityRequirement securityRequirement = new SecurityRequirement();
9595
securityRequirement.addList("BearerAuth");
9696
operation.addSecurityItem(securityRequirement);
9797
}
98-
9998
}
10099

101100
private void setOperationGet() {
@@ -113,7 +112,7 @@ private void setOperationGet() {
113112
case PLURAL:
114113
summary = "List all instances of " + this.schemaName;
115114
description = "Gets a list of all instances of " + this.schemaName +
116-
" (more information in " +this.schemaURI+")";
115+
" (more information in " + this.schemaURI + ")";
117116
responseDescriptionOk = "Successful response - returns an array with the instances of " + schemaName + ".";
118117

119118
//Set response
@@ -140,9 +139,9 @@ private void setOperationGet() {
140139
.schema(new IntegerSchema()._default(100).maximum(BigDecimal.valueOf(200)).minimum(BigDecimal.valueOf(1))));
141140
break;
142141
case SINGULAR:
143-
summary = "Get a single " + this.schemaName +" by its id";
144-
description = "Gets the details of a given " + this.schemaName+
145-
" (more information in " +this.schemaURI+")";
142+
summary = "Get a single " + this.schemaName + " by its id";
143+
description = "Gets the details of a given " + this.schemaName +
144+
" (more information in " + this.schemaURI + ")";
146145
responseDescriptionOk = "Gets the details of a given " + schemaName;
147146

148147
//Set request
@@ -153,7 +152,10 @@ private void setOperationGet() {
153152
break;
154153

155154
}
155+
}
156156

157+
private void setOperationPatch() {
158+
// TODO: implement
157159
}
158160

159161
private void setOperationPost() {
@@ -177,13 +179,12 @@ private void setOperationPost() {
177179
);
178180
}
179181

180-
181182
private void setOperationPut() {
182183
String requestDescription = "An old " + this.schemaName + "to be updated";
183184

184185
summary = "Update an existing " + this.schemaName;
185-
description = "Updates an existing " + this.schemaName+
186-
" (more information in " +this.schemaURI+")";
186+
description = "Updates an existing " + this.schemaName +
187+
" (more information in " + this.schemaURI + ")";
187188

188189
//Set request
189190
MediaType mediaType = new MediaType().schema(schema);
@@ -199,22 +200,18 @@ private void setOperationPut() {
199200
)
200201
.addApiResponse("404", new ApiResponse()
201202
.description("Not Found"));
202-
203203
}
204204

205-
206205
private void setOperationDelete() {
207206
summary = "Delete an existing " + this.schemaName;
208-
description = "Delete an existing " + this.schemaName+
209-
" (more information in " +this.schemaURI+")";
207+
description = "Delete an existing " + this.schemaName +
208+
" (more information in " + this.schemaURI + ")";
210209

211210
//Set the response
212211
apiResponses
213212
.addApiResponse("202", new ApiResponse()
214213
.description("Deleted"))
215214
.addApiResponse("404", new ApiResponse()
216215
.description("Not Found"));
217-
218216
}
219-
220217
}

src/main/java/edu/isi/oba/MapperSchema.java

+15-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package edu.isi.oba;
22

3+
import edu.isi.oba.config.CONFIG_FLAG;
34
import static edu.isi.oba.Oba.logger;
45

56
import io.swagger.v3.oas.models.examples.Example;
@@ -35,9 +36,8 @@ class MapperSchema {
3536
private OWLOntology ontology_cls;
3637
private OWLReasonerFactory reasonerFactory;
3738
public List<OWLClass> properties_range;
38-
private boolean follow_references;
39-
private Boolean default_descriptions;
40-
private Boolean default_properties;
39+
40+
private final Map<CONFIG_FLAG, Boolean> configFlags = new HashMap<>();
4141

4242
public List<OWLObjectProperty> propertiesFromObjectRestrictions;
4343
public Map<String, List<String>> propertiesFromObjectRestrictions_ranges;
@@ -62,11 +62,9 @@ public Schema getSchema() {
6262
return this.schema;
6363
}
6464

65-
public MapperSchema(List<OWLOntology> ontologies, OWLClass cls, String clsDescription, Map<IRI, String> schemaNames, OWLOntology class_ontology, Boolean follow_references, Boolean default_descriptions, Boolean default_properties) {
65+
public MapperSchema(List<OWLOntology> ontologies, OWLClass cls, String clsDescription, Map<IRI, String> schemaNames, OWLOntology class_ontology, Map<CONFIG_FLAG, Boolean> configFlags) {
6666
this.schemaNames = schemaNames;
67-
this.follow_references = follow_references;
68-
this.default_descriptions = default_descriptions;
69-
this.default_properties = default_properties;
67+
this.configFlags.putAll(configFlags);
7068
this.cls = cls;
7169
this.cls_description = clsDescription;
7270
this.type = "object";
@@ -230,7 +228,7 @@ private Map<String, Schema> getDataProperties() {
230228
}
231229

232230
List<String> propertyRanges = getCodeGenTypesByRangeData(ranges, odp);
233-
String propertyDescription = ObaUtils.getDescription(odp, this.ontology_cls, this.default_descriptions);
231+
String propertyDescription = ObaUtils.getDescription(odp, this.ontology_cls, this.configFlags.get(CONFIG_FLAG.DEFAULT_DESCRIPTIONS));
234232
MapperDataProperty mapperProperty = new MapperDataProperty(propertyName, propertyDescription, isFunctional, restrictionValues, valuesFromDataRestrictions_ranges, propertyRanges, array, nullable);
235233
try {
236234
this.properties.put(mapperProperty.name, mapperProperty.getSchemaByDataProperty());
@@ -242,7 +240,7 @@ private Map<String, Schema> getDataProperties() {
242240
}
243241
}
244242

245-
if (this.default_properties) {
243+
if (this.configFlags.get(CONFIG_FLAG.DEFAULT_DESCRIPTIONS)) {
246244
properties.putAll(this.getDefaultProperties());
247245
}
248246

@@ -338,7 +336,7 @@ private Map<String, Schema> getObjectProperties() {
338336

339337
String propertyURI = odp.getIRI().toString();
340338
propertyNameURI.put(propertyURI, propertyName);
341-
List<String> propertyRanges = getCodeGenTypesByRangeObject(ranges, odp, owlThing, this.follow_references);
339+
List<String> propertyRanges = getCodeGenTypesByRangeObject(ranges, odp, owlThing);
342340

343341
Map<String,String> restrictionValues = new HashMap<String, String>() ;
344342
for (OWLOntology ontology: this.ontologies) {
@@ -358,7 +356,7 @@ private Map<String, Schema> getObjectProperties() {
358356
}
359357
}
360358

361-
String propertyDescription = ObaUtils.getDescription(odp, this.ontology_cls, this.default_descriptions);
359+
String propertyDescription = ObaUtils.getDescription(odp, this.ontology_cls, this.configFlags.get(CONFIG_FLAG.DEFAULT_DESCRIPTIONS));
362360
MapperObjectProperty mapperObjectProperty = new MapperObjectProperty(propertyName, propertyDescription, isFunctional, restrictionValues, propertyRanges);
363361
try {
364362
this.properties.put(mapperObjectProperty.name, mapperObjectProperty.getSchemaByObjectProperty());
@@ -398,10 +396,9 @@ private List<String> getCodeGenTypesByRangeData(Set<OWLDataPropertyRangeAxiom> r
398396
* @param ranges Represents a ObjectPropertyRange
399397
* @param odp Represents a OWLObjectProperty
400398
* @param owlThing
401-
* @param follow_references
402399
* @return A list<String> with the properties
403400
*/
404-
private List<String> getCodeGenTypesByRangeObject(Set<OWLObjectPropertyRangeAxiom> ranges, OWLObjectProperty odp, OWLClass owlThing, boolean follow_references) {
401+
private List<String> getCodeGenTypesByRangeObject(Set<OWLObjectPropertyRangeAxiom> ranges, OWLObjectProperty odp, OWLClass owlThing) {
405402
List<String> objectProperty = new ArrayList<>();
406403

407404
for (OWLObjectPropertyRangeAxiom propertyRangeAxiom : ranges) {
@@ -412,9 +409,8 @@ private List<String> getCodeGenTypesByRangeObject(Set<OWLObjectPropertyRangeAxio
412409
logger.info("Ignoring owl:Thing" + odp);
413410
} else {
414411
this.properties_range.add(rangeClass.asOWLClass());
415-
if (follow_references) {
416-
objectProperty.add(getSchemaName(rangeClass.asOWLClass()));
417-
}
412+
if (this.configFlags.get(CONFIG_FLAG.FOLLOW_REFERENCES))
413+
objectProperty.add(getSchemaName(rangeClass.asOWLClass()));
418414
}
419415
}
420416
}
@@ -469,7 +465,7 @@ private void getClassRestrictions(OWLClass analyzedClass) {
469465
} else {
470466
for (OWLObjectProperty op: this.propertiesFromObjectRestrictions) {
471467
MapperObjectProperty mapperObjectProperty;
472-
String propertyDescription = ObaUtils.getDescription(op, this.ontology_cls, this.default_descriptions);
468+
String propertyDescription = ObaUtils.getDescription(op, this.ontology_cls, this.configFlags.get(CONFIG_FLAG.DEFAULT_DESCRIPTIONS));
473469
if (!this.propertiesFromObjectRestrictions_ranges.isEmpty()) {
474470
List<String> rangesOP = this.propertiesFromObjectRestrictions_ranges.get(this.sfp.getShortForm(op.getIRI()));
475471
for (String j : restrictionsValuesFromClass.keySet()) {
@@ -536,7 +532,7 @@ private void getClassRestrictions(OWLClass analyzedClass) {
536532

537533
for (OWLDataProperty dp: this.propertiesFromDataRestrictions) {
538534
List<String> valuesFromDataRestrictions_ranges = new ArrayList<>();
539-
String propertyDescription = ObaUtils.getDescription(dp, this.ontology_cls, this.default_descriptions);
535+
String propertyDescription = ObaUtils.getDescription(dp, this.ontology_cls, this.configFlags.get(CONFIG_FLAG.DEFAULT_DESCRIPTIONS));
540536
if (!this.propertiesFromDataRestrictions_ranges.isEmpty()) {
541537
List<String> rangesDP = this.propertiesFromDataRestrictions_ranges.get(this.sfp.getShortForm(dp.getIRI()));
542538
for (String j: restrictionsValuesFromClass.keySet()) {
@@ -601,7 +597,7 @@ private void getClassRestrictions(OWLClass analyzedClass) {
601597
this.properties = setProperties();
602598
}
603599

604-
if (this.default_properties) {
600+
if (this.configFlags.get(CONFIG_FLAG.DEFAULT_PROPERTIES)) {
605601
this.properties.putAll(this.getDefaultProperties());
606602
}
607603
}

src/main/java/edu/isi/oba/Oba.java

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package edu.isi.oba;
22

33
import edu.isi.oba.config.*;
4+
45
import io.swagger.v3.oas.models.OpenAPI;
56
import io.swagger.v3.oas.models.PathItem;
67

0 commit comments

Comments
 (0)