diff --git a/plugins/org.etsi.mts.tdl.openapi2tdl.next/src/org/etsi/mts/tdl/openapi2tdl/next/OpenAPI2TDLTranslatorNext.java b/plugins/org.etsi.mts.tdl.openapi2tdl.next/src/org/etsi/mts/tdl/openapi2tdl/next/OpenAPI2TDLTranslatorNext.java index 2d7f94b7edafb6f1e1696a9d8e1992bb6fa6a520..5b316cc09a5ab8388e7708cce882c1ce81776828 100644 --- a/plugins/org.etsi.mts.tdl.openapi2tdl.next/src/org/etsi/mts/tdl/openapi2tdl/next/OpenAPI2TDLTranslatorNext.java +++ b/plugins/org.etsi.mts.tdl.openapi2tdl.next/src/org/etsi/mts/tdl/openapi2tdl/next/OpenAPI2TDLTranslatorNext.java @@ -1,6 +1,7 @@ package org.etsi.mts.tdl.openapi2tdl.next; import java.io.File; +import java.util.Collections; import java.util.HashSet; import java.util.Hashtable; import java.util.List; @@ -192,6 +193,7 @@ public class OpenAPI2TDLTranslatorNext extends AbstractTranslator { // Map operations to request body schemas so we can create wrappers later Map<String, Set<PathOperation>> schemaOperations = new Hashtable<>(); + Set<PathOperation> inlineSchemaOperations = new HashSet<>(); Set<PathOperation> noContentOperations = new HashSet<>(); Paths paths = model.getPaths(); for (String pathUri: paths.keySet()) { @@ -210,16 +212,20 @@ public class OpenAPI2TDLTranslatorNext extends AbstractTranslator { array = true; } String schemaName = schema.get$ref(); - schemaName = schemaName.replace("#/components/schemas/", ""); - Set<PathOperation> set = schemaOperations.get(schemaName); - if (set == null) { - set = new HashSet<>(); - schemaOperations.put(schemaName, set); + if (schemaName == null) { + inlineSchemaOperations.add(new PathOperation(pathUri, method, op, array, schema)); + } else { + schemaName = schemaName.replace("#/components/schemas/", ""); + Set<PathOperation> set = schemaOperations.get(schemaName); + if (set == null) { + set = new HashSet<>(); + schemaOperations.put(schemaName, set); + } + set.add(new PathOperation(pathUri, method, op, array, null)); } - set.add(new PathOperation(pathUri, method, op, array)); } } else { - noContentOperations.add(new PathOperation(pathUri, method, op, false)); + noContentOperations.add(new PathOperation(pathUri, method, op, false, null)); } } } @@ -249,6 +255,14 @@ public class OpenAPI2TDLTranslatorNext extends AbstractTranslator { if (useMessageBasedApi) { createOperationWrapper(noContentOperations, httpRequest, httpMethodEnum, httpRequestParameters, httpParameterLocationEnum); } + for (PathOperation op : inlineSchemaOperations) { + Schema<?> schema = op.inlineSchema; + schema.setName(op.path.substring(1) + "_body"); + DataType dataType = translate(schema, "", messageBody); + if (useMessageBasedApi) { + createOperationWrapper(Collections.singleton(op), httpRequest, httpMethodEnum, httpRequestParameters, httpParameterLocationEnum); + } + } for (String schemaName : model.getComponents().getSchemas().keySet()) { Schema<?> schema = model.getComponents().getSchemas().get(schemaName); schema.setName(schemaName); @@ -575,11 +589,13 @@ public class OpenAPI2TDLTranslatorNext extends AbstractTranslator { String path; HttpMethod method; Operation operation; + Schema<?> inlineSchema; boolean array; - public PathOperation(String path, HttpMethod method, Operation operation, boolean array) { + public PathOperation(String path, HttpMethod method, Operation operation, boolean array, Schema<?> inlineSchema) { this.path = path; this.method = method; this.operation = operation; + this.inlineSchema = inlineSchema; this.array = array; } }