From 0c7d87dda6c7c1bf914e89a1ed10674fde1221d2 Mon Sep 17 00:00:00 2001 From: Simon Redfern Date: Wed, 11 Oct 2023 18:31:31 +0200 Subject: [PATCH] Adding getGlossaryItemSimple and tweaking Resource Docs for JSON Schema Validation POST and PUT --- .../main/scala/code/api/util/Glossary.scala | 39 ++++++++++++++----- .../scala/code/api/v4_0_0/APIMethods400.scala | 15 +++++-- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/obp-api/src/main/scala/code/api/util/Glossary.scala b/obp-api/src/main/scala/code/api/util/Glossary.scala index 8274ecf5b3..6fa87c761d 100644 --- a/obp-api/src/main/scala/code/api/util/Glossary.scala +++ b/obp-api/src/main/scala/code/api/util/Glossary.scala @@ -32,14 +32,33 @@ object Glossary extends MdcLoggable { | | ${foundItem.htmlDescription} | + | |

|""".stripMargin - case None => "" + case None => "glossary-item-not-found" } //logger.debug(s"getGlossaryItem says the text to return is $something") something } + def getGlossaryItemSimple(title: String): String = { + // This function just returns a string without Title and collapsable element. + // Can use this if getGlossaryItem is problematic with a certain glossary item (e.g. JSON Schema Validation Glossary Item) or just want a simple inclusion of text. + + //logger.debug(s"getGlossaryItemSimple says Hello. title to find is: $title") + + val something = glossaryItems.find(_.title.toLowerCase == title.toLowerCase) match { + case Some(foundItem) => + s""" + | ${foundItem.htmlDescription} + |""".stripMargin + case None => "glossary-item-simple-not-found" + } + //logger.debug(s"getGlossaryItemSimple says the text to return is $something") + something + } + + // reason of description is function: because we want make description is dynamic, so description can read // webui_ props dynamic instead of a constant string. case class GlossaryItem( @@ -3052,21 +3071,23 @@ object Glossary extends MdcLoggable { title = "JSON Schema Validation", description = s""" + | |JSON Schema is "a vocabulary that allows you to annotate and validate JSON documents". | - |By applying JSON Schema Validation to your endpoints you can constrain POST and PUT request bodies. For example, you can set minimum / maximum lengths of fields and constrain values to certain lists or regular expressions. + |By applying JSON Schema Validation to your OBP endpoints you can constrain POST and PUT request bodies. For example, you can set minimum / maximum lengths of fields and constrain values to certain lists or regular expressions. | - |See [JSONSchema.org](https://json-schema.org/) for more information about the standard. + |See [JSONSchema.org](https://json-schema.org/) for more information about the JSON Schema standard. +| +|To create a JSON Schema from an any JSON Request body you can use [JSON Schema Net](https://jsonschema.net/app/schemas/0) +| +|(The video link below shows how to use that) | - |Note that Dynamic Entities also use JSON Schema Validation so you don't need to additionally wrap the resulting endpoints with extra JSON Schema Validation but you could do. + |Note: OBP Dynamic Entities also use JSON Schema Validation so you don't need to additionally wrap the resulting endpoints with extra JSON Schema Validation but you could do. | - + | You can apply JSON schema validations to any OBP endpoint's request body using the POST and PUT endpoints listed in the link below. | - | We provide the schema validations over the endpoints. - | All the OBP endpoints request/response body fields can be validated by the schema. + |PLEASE SEE the following video explanation: [JSON schema validation of request for Static and Dynamic Endpoints and Entities](https://vimeo.com/485287014) | - |The following videos are available: - |* [JSON schema validation of request for Static and Dynamic Endpoints and Entities] (https://vimeo.com/485287014) |""".stripMargin) diff --git a/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala b/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala index 47ef589523..a61f0d7709 100644 --- a/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala +++ b/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala @@ -22,7 +22,7 @@ import code.api.util.ApiTag._ import code.api.util.DynamicUtil.Validation import code.api.util.ErrorMessages.{BankNotFound, _} import code.api.util.ExampleValue._ -import code.api.util.Glossary.getGlossaryItem +import code.api.util.Glossary.{getGlossaryItem,getGlossaryItemSimple} import code.api.util.NewStyle.HttpCode import code.api.util.NewStyle.function.{isValidCurrencyISOCode => isValidCurrencyISOCodeNS, _} import code.api.util._ @@ -9594,7 +9594,12 @@ trait APIMethods400 { "Create a JSON Schema Validation", s"""Create a JSON Schema Validation. | - |Please supply a json-schema as request body. + |Introduction: + |${Glossary.getGlossaryItemSimple("JSON Schema Validation")} + | + |To use this endpoint, please supply a valid json-schema in the request body. + | + |Note: It might take a few minutes for the newly created JSON Schema to take effect! |""", postOrPutJsonSchemaV400, responseJsonSchema, @@ -9640,7 +9645,11 @@ trait APIMethods400 { "Update a JSON Schema Validation", s"""Update a JSON Schema Validation. | - |Please supply a json-schema as request body + |Introduction: + |${Glossary.getGlossaryItemSimple("JSON Schema Validation")} + | + |To use this endpoint, please supply a valid json-schema in the request body. + | |""", postOrPutJsonSchemaV400, responseJsonSchema,