From c4ec7e9a59464bbe1fba977c6da11177a8e44207 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martti=20K=C3=A4=C3=A4rik?= Date: Mon, 21 Oct 2024 17:54:40 +0300 Subject: [PATCH] Added support for inline schemas as operation bodies --- .../next/OpenAPI2TDLTranslatorNext.java | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) 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 2d7f94b7..5b316cc0 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> schemaOperations = new Hashtable<>(); + Set inlineSchemaOperations = new HashSet<>(); Set 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 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 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; } } -- GitLab