From 1ea6fc800261f5a9406d761910fd1f328ff4fc08 Mon Sep 17 00:00:00 2001 From: Eric Wittmann Date: Mon, 6 Jan 2025 14:11:52 -0500 Subject: [PATCH] Implemented DeleteAllResponsesCommand. --- .../datamodels/cmd/CommandFactory.java | 5 ++++ .../commands/DeleteAllParametersCommand.java | 16 ---------- .../commands/DeleteAllPropertiesCommand.java | 16 ---------- .../commands/DeleteAllResponsesCommand.java | 30 +++++++++++++++++++ .../apicurio/datamodels/util/CommandUtil.ts | 2 ++ src/test/resources/fixtures/cmd/tests.json | 4 ++- 6 files changed, 40 insertions(+), 33 deletions(-) create mode 100755 src/main/java/io/apicurio/datamodels/cmd/commands/DeleteAllResponsesCommand.java diff --git a/src/main/java/io/apicurio/datamodels/cmd/CommandFactory.java b/src/main/java/io/apicurio/datamodels/cmd/CommandFactory.java index c4a9042f..b33e586b 100644 --- a/src/main/java/io/apicurio/datamodels/cmd/CommandFactory.java +++ b/src/main/java/io/apicurio/datamodels/cmd/CommandFactory.java @@ -14,6 +14,7 @@ import io.apicurio.datamodels.cmd.commands.DeleteAllOperationsCommand; import io.apicurio.datamodels.cmd.commands.DeleteAllParametersCommand; import io.apicurio.datamodels.cmd.commands.DeleteAllPropertiesCommand; +import io.apicurio.datamodels.cmd.commands.DeleteAllResponsesCommand; import io.apicurio.datamodels.cmd.commands.DeleteContactCommand; import io.apicurio.datamodels.cmd.commands.DeleteExtensionCommand; import io.apicurio.datamodels.cmd.commands.DeleteLicenseCommand; @@ -120,4 +121,8 @@ public static final ICommand createDeleteAllPropertiesCommand(Schema schema) { return new DeleteAllPropertiesCommand(schema); } + public static final ICommand createDeleteAllResponsesCommand(OpenApiOperation operation) { + return new DeleteAllResponsesCommand(operation); + } + } diff --git a/src/main/java/io/apicurio/datamodels/cmd/commands/DeleteAllParametersCommand.java b/src/main/java/io/apicurio/datamodels/cmd/commands/DeleteAllParametersCommand.java index 3784862d..7fd5d939 100755 --- a/src/main/java/io/apicurio/datamodels/cmd/commands/DeleteAllParametersCommand.java +++ b/src/main/java/io/apicurio/datamodels/cmd/commands/DeleteAllParametersCommand.java @@ -1,19 +1,3 @@ -/* - * Copyright 2019 Red Hat - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package io.apicurio.datamodels.cmd.commands; import com.fasterxml.jackson.databind.node.ObjectNode; diff --git a/src/main/java/io/apicurio/datamodels/cmd/commands/DeleteAllPropertiesCommand.java b/src/main/java/io/apicurio/datamodels/cmd/commands/DeleteAllPropertiesCommand.java index edc6d364..11436eef 100755 --- a/src/main/java/io/apicurio/datamodels/cmd/commands/DeleteAllPropertiesCommand.java +++ b/src/main/java/io/apicurio/datamodels/cmd/commands/DeleteAllPropertiesCommand.java @@ -1,19 +1,3 @@ -/* - * Copyright 2019 Red Hat - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package io.apicurio.datamodels.cmd.commands; import com.fasterxml.jackson.databind.node.ObjectNode; diff --git a/src/main/java/io/apicurio/datamodels/cmd/commands/DeleteAllResponsesCommand.java b/src/main/java/io/apicurio/datamodels/cmd/commands/DeleteAllResponsesCommand.java new file mode 100755 index 00000000..1fc64715 --- /dev/null +++ b/src/main/java/io/apicurio/datamodels/cmd/commands/DeleteAllResponsesCommand.java @@ -0,0 +1,30 @@ +package io.apicurio.datamodels.cmd.commands; + +import com.fasterxml.jackson.databind.node.ObjectNode; +import io.apicurio.datamodels.Library; +import io.apicurio.datamodels.models.Document; +import io.apicurio.datamodels.models.openapi.OpenApiOperation; +import io.apicurio.datamodels.models.openapi.OpenApiResponses; +import io.apicurio.datamodels.paths.NodePathUtil; + +/** + * @author eric.wittmann@gmail.com + */ +public class DeleteAllResponsesCommand extends DeleteNodeCommand { + + public DeleteAllResponsesCommand() { + } + + public DeleteAllResponsesCommand(OpenApiOperation operation) { + super("responses", operation); + } + + @Override + protected OpenApiResponses readNode(Document doc, ObjectNode node) { + OpenApiOperation operation = (OpenApiOperation) NodePathUtil.resolveNodePath(this._parentPath, doc); + OpenApiResponses responses = operation.createResponses(); + Library.readNode(node, responses); + return responses; + } + +} diff --git a/src/main/ts/src/io/apicurio/datamodels/util/CommandUtil.ts b/src/main/ts/src/io/apicurio/datamodels/util/CommandUtil.ts index c68be767..4706e78d 100644 --- a/src/main/ts/src/io/apicurio/datamodels/util/CommandUtil.ts +++ b/src/main/ts/src/io/apicurio/datamodels/util/CommandUtil.ts @@ -18,6 +18,7 @@ import {DeleteAllHeadersCommand} from "../cmd/commands/DeleteAllHeadersCommand"; import {DeleteAllOperationsCommand} from "../cmd/commands/DeleteAllOperationsCommand"; import {DeleteAllParametersCommand} from "../cmd/commands/DeleteAllParametersCommand"; import {DeleteAllPropertiesCommand} from "../cmd/commands/DeleteAllPropertiesCommand"; +import {DeleteAllResponsesCommand} from "../cmd/commands/DeleteAllResponsesCommand"; import {DeleteContactCommand} from "../cmd/commands/DeleteContactCommand"; import {DeleteExtensionCommand} from "../cmd/commands/DeleteExtensionCommand"; import {DeleteLicenseCommand} from "../cmd/commands/DeleteLicenseCommand"; @@ -52,6 +53,7 @@ const commandSuppliers: { [key: string]: Supplier } = { "DeleteAllOperationsCommand": () => { return new DeleteAllOperationsCommand(); }, "DeleteAllParametersCommand": () => { return new DeleteAllParametersCommand(); }, "DeleteAllPropertiesCommand": () => { return new DeleteAllPropertiesCommand(); }, + "DeleteAllResponsesCommand": () => { return new DeleteAllResponsesCommand(); }, "DeleteContactCommand": () => { return new DeleteContactCommand(); }, "DeleteExtensionCommand": () => { return new DeleteExtensionCommand(); }, "DeleteLicenseCommand": () => { return new DeleteLicenseCommand(); }, diff --git a/src/test/resources/fixtures/cmd/tests.json b/src/test/resources/fixtures/cmd/tests.json index c50eb09e..679d820b 100755 --- a/src/test/resources/fixtures/cmd/tests.json +++ b/src/test/resources/fixtures/cmd/tests.json @@ -43,5 +43,7 @@ { "name": "[OpenAPI 3] {Delete All Params} - Delete All Params", "test" : "commands/delete-all-parameters/openapi-3/delete-all-parameters" }, { "name": "[OpenAPI 2] {Delete All Properties} - Delete All Properties", "test": "commands/delete-all-properties/openapi-2/delete-all-properties" }, { "name": "[OpenAPI 3] {Delete All Properties} - Delete All Properties", "test": "commands/delete-all-properties/openapi-3/delete-all-properties" }, - { "name": "[AsyncAPI 2] {Delete All Properties} - Delete All Properties", "test": "commands/delete-all-properties/asyncapi-2/delete-all-properties" } + { "name": "[AsyncAPI 2] {Delete All Properties} - Delete All Properties", "test": "commands/delete-all-properties/asyncapi-2/delete-all-properties" }, + { "name": "[OpenAPI 2] {Delete All Responses} - Delete All Responses", "test": "commands/delete-all-responses/openapi-2/delete-all-responses" }, + { "name": "[OpenAPI 3] {Delete All Responses} - Delete All Responses", "test": "commands/delete-all-responses/openapi-3/delete-all-responses" } ] \ No newline at end of file