From 6f81f6ee3c011571bf16bb89ac0e952dd316b767 Mon Sep 17 00:00:00 2001 From: Daniel Slapman Date: Mon, 1 Apr 2024 00:20:35 +0200 Subject: [PATCH] Remove xcdata extractor --- .../tcb/mockingbird/model/Extractor.scala | 17 ---------------- .../ru/tinkoff/tcb/predicatedsl/Keyword.scala | 1 - .../tcb/predicatedsl/xml/XmlPredicate.scala | 20 ------------------- .../predicatedsl/xml/XmlPredicateSpec.scala | 18 ----------------- readme.md | 13 ------------ readme_ru.md | 13 ------------ 6 files changed, 82 deletions(-) diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/Extractor.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/Extractor.scala index 5d4698f3..87b1e771 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/Extractor.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/Extractor.scala @@ -33,7 +33,6 @@ sealed trait XmlExtractor { } object XmlExtractor { val types: Map[String, String] = Map( - nameOfType[XMLCDataExtractor] -> "xcdata", nameOfType[JsonCDataExtractor] -> "jcdata", ).withDefault(identity) @@ -41,22 +40,6 @@ object XmlExtractor { TapirConfig.default.withDiscriminator("type").copy(toEncodedName = types) } -/** - * @param prefix - * Path to CDATA - * @param path - * Path inside CDATA - */ -@derive(decoder, encoder) -final case class XMLCDataExtractor(prefix: Xpath, path: Xpath) extends XmlExtractor { - def apply(node: Node): Either[XPathError, Json] = - node - .evalXPath[String](prefix.toXPathExpr) - .flatMap(_.trim().asNode) - .flatMap(_.evalXPath[String](path.toXPathExpr)) - .map(Json.fromString) -} - /** * @param prefix * Path to CDATA diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/predicatedsl/Keyword.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/predicatedsl/Keyword.scala index cc800e52..0125ed9d 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/predicatedsl/Keyword.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/predicatedsl/Keyword.scala @@ -41,7 +41,6 @@ object Keyword case object AllIn extends Keyword("&[_]", "$all") with JsonKeyword with FormKeyword case object Cdata extends Keyword("cdata", "") with XmlKeyword case object JCdata extends Keyword("jcdata", "") with XmlKeyword - case object XCdata extends Keyword("xcdata", "") with XmlKeyword val values = findValues diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/predicatedsl/xml/XmlPredicate.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/predicatedsl/xml/XmlPredicate.scala index dc2ded7d..e70114a6 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/predicatedsl/xml/XmlPredicate.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/predicatedsl/xml/XmlPredicate.scala @@ -154,26 +154,6 @@ object XmlPredicate { } yield jpred) .leftMap(NonEmptyList.one) .map(jpred => (op: Option[Node]) => op.exists(_.evalXPath[Json](xp"self::node()").map(jpred).getOrElse(false))) - case (XCdata, spec) => - Validated - .fromEither(for { - xspec <- spec - .as[Map[Xpath, Map[Keyword.Xml, Json]]] - .leftMap(_ => kwd.asInstanceOf[Keyword] -> spec) - xpred <- XmlPredicate(xspec).toEither.leftMap(errs => - kwd.asInstanceOf[Keyword] -> Json.fromString(errs.toList.mkString(", ")) - ) - } yield xpred) - .leftMap(NonEmptyList.one) - .map(xpred => - (op: Option[Node]) => - op.exists( - _.evalXPath[String](xp"self::node()") - .flatMap(_.trim().asNode) - .map(xpred) - .getOrElse(false) - ) - ) case (kwd, j) => Validated.invalidNel(kwd -> j) } diff --git a/backend/mockingbird/src/test/scala/ru/tinkoff/tcb/predicatedsl/xml/XmlPredicateSpec.scala b/backend/mockingbird/src/test/scala/ru/tinkoff/tcb/predicatedsl/xml/XmlPredicateSpec.scala index 9f1de24b..94cecd74 100644 --- a/backend/mockingbird/src/test/scala/ru/tinkoff/tcb/predicatedsl/xml/XmlPredicateSpec.scala +++ b/backend/mockingbird/src/test/scala/ru/tinkoff/tcb/predicatedsl/xml/XmlPredicateSpec.scala @@ -224,22 +224,4 @@ class XmlPredicateSpec extends AnyFunSuite with Matchers with EitherValues { sut.map(_(xml(""" """))) shouldBe Some(false) sut.map(_(xml(""" """))) shouldBe Some(false) } - - test("Check CDATA with XML") { - val spec = Json.obj( - "/xml" := Json.obj( - "xcdata" := Json.obj( - "/f" := Json.obj( - "==" := 42 - ) - ) - ) - ) - - val sut = XmlPredicate(spec.as[Map[Xpath, Map[Keyword.Xml, Json]]].value).toOption - - sut.map(_(xml(""" 42]]> """))) shouldBe Some(true) - sut.map(_(xml(""" 43]]> """))) shouldBe Some(false) - sut.map(_(xml(""" 42 """))) shouldBe Some(false) - } } diff --git a/readme.md b/readme.md index 1fe3aeca..31ebe5c3 100644 --- a/readme.md +++ b/readme.md @@ -264,19 +264,6 @@ Anything that needs to be extracted from the path should be done with a _named_ ### Extractors In some cases, it's necessary to insert into the response data that cannot be extracted by simple means. For these purposes, extractors have been added. -#### xcdata Extractor - -Extracts values from XML located within CDATA. - -Configuration: -```javascript -{ - "type": "xcdata", - "prefix": "/root/inner/tag", // Path to the tag with CDATA - "path": "/path/to" // Path to the desired tag -} -``` - #### jcdata Extractor Extracts values from JSON located within CDATA. diff --git a/readme_ru.md b/readme_ru.md index 6de67ffc..71e8dd41 100644 --- a/readme_ru.md +++ b/readme_ru.md @@ -267,19 +267,6 @@ HTTP заголовки валидируются на полное соотве ### Экстракторы В некоторых случаях нужно подставить в ответ данные, которые невозможно извлечь простыми средствами. Для этих целей были добавлены экстракторы -#### Экстрактор xcdata - -Достаёт значения из XML, лежащего в CDATA - -конфигурация: -```javascript -{ - "type": "xcdata", - "prefix": "/root/inner/tag", //Путь до тэга с CDATA - "path": "/path/to" //Путь до нужного тэга -} -``` - #### Экстрактор jcdata Достаёт значения из JSON, лежащего в CDATA