diff --git a/.github/badges/branches.svg b/.github/badges/branches.svg
index 7999994..df38c36 100644
--- a/.github/badges/branches.svg
+++ b/.github/badges/branches.svg
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/.github/badges/jacoco.svg b/.github/badges/jacoco.svg
index 8752148..51fd592 100644
--- a/.github/badges/jacoco.svg
+++ b/.github/badges/jacoco.svg
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 023462c..2107669 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,7 @@
*.idea*
+*.iml
target
+*.iml
*.log
*.log*.zip
.classpath
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1aff968..1528742 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,10 @@
# CHANGELOG
+1.0.7 - 30/05/2024
+- fix bug while handling generation of oneOf construct inside json schema
+- fix issue preventing generation of schemas in case of objects without properties, forcing generation with additionalProperties enabled
+- fix issue preventing generation of json schemas with swagger files that have objects schemas defined inline rather than inside "components"
+
1.0.6 - 07/07/2023
- updated swagger-parser library due to a bug that could not read additionalProperties inside a model.
diff --git a/README.md b/README.md
index ff257db..723af84 100644
--- a/README.md
+++ b/README.md
@@ -12,8 +12,6 @@ Maven plugin that converts swagger 2.0/OAS 3.0.x schema objects into self contai
- Each operation MUST have a non-empty OperationID field
-- Each operation MUST not declare inline request/response body but always reference to Object Schema (no error is thrown, only a warn log)
-
diff --git a/pom.xml b/pom.xml
index 8ba5dd3..86f58ac 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
it.imolinfo.maven.plugins
openapi2jsonschema4j
- 1.0.7-SNAPSHOT
+ 1.0.7
maven-plugin
OpenAPI2JsonSchema4J
diff --git a/src/main/java/it/imolainformatica/openapi2jsonschema4j/base/BaseJsonSchemaGenerator.java b/src/main/java/it/imolainformatica/openapi2jsonschema4j/base/BaseJsonSchemaGenerator.java
index 6994875..4be6fc7 100644
--- a/src/main/java/it/imolainformatica/openapi2jsonschema4j/base/BaseJsonSchemaGenerator.java
+++ b/src/main/java/it/imolainformatica/openapi2jsonschema4j/base/BaseJsonSchemaGenerator.java
@@ -12,6 +12,8 @@
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.PathItem;
+import io.swagger.v3.oas.models.media.ObjectSchema;
+import io.swagger.v3.oas.models.media.ArraySchema;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.responses.ApiResponse;
import io.swagger.v3.parser.core.models.ParseOptions;
@@ -50,7 +52,9 @@ protected void readFromInterface(File interfaceFile) {
SwaggerParseResult result = new OpenAPIParser().readLocation(interfaceFile.getAbsolutePath(),null,po);
OpenAPI swagger = result.getOpenAPI();
Validate.notNull(swagger,"Error during parsing of interface file "+interfaceFile.getAbsolutePath());
- objectsDefinitions = swagger.getComponents().getSchemas();
+ if (swagger.getComponents() != null && swagger.getComponents().getSchemas() != null) {
+ objectsDefinitions = swagger.getComponents().getSchemas();
+ }
for (Map.Entry entry : swagger.getPaths().entrySet()) {
String k = entry.getKey();
PathItem v = entry.getValue();
@@ -66,11 +70,17 @@ private void analyzeOperation(PathItem v) {
ApiResponse r = op.getResponses().get(key);
if (r.getContent()!=null) {
if (r.getContent().get(APPLICATION_JSON) != null) {
+ Schema sc = r.getContent().get(APPLICATION_JSON).getSchema();
if (r.getContent().get(APPLICATION_JSON).getSchema().get$ref() != null) {
log.info("code={} responseSchema={}", key, r.getContent().get(APPLICATION_JSON).getSchema().get$ref());
messageObjects.add(r.getContent().get(APPLICATION_JSON).getSchema().get$ref());
} else {
log.warn("code={} response schema is not a referenced definition! type={}", key, r.getContent().get("application/json").getClass());
+ log.debug("Reference not found, creating it manually");
+ if (!(sc instanceof ArraySchema)) {
+ objectsDefinitions.put(op.getOperationId()+"response"+key, sc);
+ messageObjects.add(op.getOperationId()+"response"+key);
+ }
}
}
}
@@ -85,9 +95,14 @@ private void findRequestBodySchema(Operation op, Set messageObjects) {
if (sc != null) {
log.info("Request schema={}", sc.get$ref());
if (sc.get$ref()!=null) {
- messageObjects.add(sc.get$ref());
+ messageObjects.add(sc.get$ref());
} else {
log.warn("Request schema is not a referenced definition!");
+ log.debug("Ref not found, cresting it manually if object");
+ if (!(sc instanceof ArraySchema)) {
+ objectsDefinitions.put(op.getOperationId()+"request", sc);
+ messageObjects.add(op.getOperationId()+"request");
+ }
}
}
} else {
diff --git a/src/main/java/it/imolainformatica/openapi2jsonschema4j/impl/DraftV4JsonSchemaGenerator.java b/src/main/java/it/imolainformatica/openapi2jsonschema4j/impl/DraftV4JsonSchemaGenerator.java
index efd8f07..35e8f53 100644
--- a/src/main/java/it/imolainformatica/openapi2jsonschema4j/impl/DraftV4JsonSchemaGenerator.java
+++ b/src/main/java/it/imolainformatica/openapi2jsonschema4j/impl/DraftV4JsonSchemaGenerator.java
@@ -7,6 +7,8 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.datatype.jsr310.*;
+
+import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.media.*;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
@@ -39,6 +41,11 @@ public class DraftV4JsonSchemaGenerator extends BaseJsonSchemaGenerator implemen
private static final String EXTERNALDOCS = "externalDocs";
private static final String DEPRECATED = "deprecated";
+ private static final String ALLOF = "anyOf";
+ private static final String ONEOF = "oneOf";
+ private static final String ANYOF = "anyOf";
+
+
private static final String JSONSCHEMA = "jsonSchema";
private static final String TYPES = "types";
@@ -59,7 +66,7 @@ public class DraftV4JsonSchemaGenerator extends BaseJsonSchemaGenerator implemen
public static final String NULL = "null";
private boolean strict;
-
+
public DraftV4JsonSchemaGenerator(boolean strict) {
this.strict = strict;
}
@@ -67,27 +74,45 @@ public DraftV4JsonSchemaGenerator(boolean strict) {
private Map generateForObjects() throws Exception {
for (String ref : getMessageObjects()) {
String title = ref.replace(DEFINITIONS2, "");
- Map defs = (Map) ((HashMap) getObjectsDefinitions()).clone();
+ Map defs = (Map) ((HashMap) getObjectsDefinitions()).clone();
Schema