Skip to content

Commit

Permalink
Merge pull request #58 from spdx/issue57
Browse files Browse the repository at this point in the history
Generation missing required properties for arrays
  • Loading branch information
goneall authored Jun 28, 2022
2 parents 05afeed + 71b6c1b commit 07832f0
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/main/java/org/spdx/tools/schema/OwlToJsonSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public ObjectNode convertToJsonSchema() {
ExtendedIterator<Ontology> ontologyIter = model.listOntologies();
if (ontologyIter.hasNext()) {
Ontology ont = ontologyIter.next();
String ontologyUri = ont.getURI();
String version = ont.getVersionInfo();
String ontologyUri = version == null ? ont.getURI() : ont.getURI() + "/" + version;
if (Objects.nonNull(ontologyUri)) {
root.put("$id", ontologyUri);
}
Expand Down Expand Up @@ -231,6 +232,10 @@ private void addClassProperties(OntClass spdxClass, ObjectNode jsonSchemaPropert
jsonSchemaProperties.set(MultiFormatStore.propertyNameToCollectionPropertyName(
checkConvertRenamedPropertyName(property.getLocalName())),
deriveListPropertySchema(property, restrictions));
if (!restrictions.isOptional() || restrictions.getMinCardinality() > 0) {
required.add(MultiFormatStore.propertyNameToCollectionPropertyName(
checkConvertRenamedPropertyName(property.getLocalName())));
}
} else {
jsonSchemaProperties.set(checkConvertRenamedPropertyName(property.getLocalName()), derivePropertySchema(property, restrictions));
if (!restrictions.isOptional()) {
Expand Down Expand Up @@ -322,9 +327,9 @@ private ObjectNode derivePropertySchema(OntProperty property, PropertyRestrictio
// check for AnyLicenseInfo - these are strings with the exception of the extractedLicensingInfos which are the actual license description
JsonNode description = propertySchema.get("description");
if (Objects.isNull(description)) {
propertySchema.put("description", "License expression");
propertySchema.put("description", "License expression. See SPDX Annex D for the license expression syntax.");
} else {
propertySchema.put("description", "License expression for "+checkConvertRenamedPropertyName(property.getLocalName())+". "+description.asText());
propertySchema.put("description", "License expression for "+checkConvertRenamedPropertyName(property.getLocalName())+". See SPDX Annex D for the license expression syntax. "+description.asText());
}
propertySchema.put(JSON_RESTRICTION_TYPE, JSON_TYPE_STRING);
} else if (Objects.nonNull(clazz) && SpdxElement.class.isAssignableFrom(clazz)) {
Expand Down

0 comments on commit 07832f0

Please sign in to comment.