/** * Generated by API Builder - https://www.apibuilder.io * Service version: 0.0.1-dev * User agent: apibuilder app.apibuilder.io/apicollective/postman-generator-attributes/0.0.1-dev/play_2_x_scala_3_json */ package io.postman.generator.attributes.v0.models { /** * Attribute instructs the generator to add Basic Auth info to the whole Postman * collection. Attribute should be defined on the root level of the ApiBuilder * specification * * @param username Specifies the username to be used in Postman Collection auth definition. It may * be also a variable reference. * @param password Specified the password to be used in Postman Collection auth definition. It may * be also a variable reference. Leave this string empty, when only a username is * needed. */ final case class BasicAuth( username: String, password: String ) /** * Attribute instructs the generator to add a setup step with the referenced entity * creation. This attribute should be attached to the field (that holds an * identifier) inside model or to the resource object (that holds operations and a * path with an identifier param). * * @param relatedServiceNamespace ApiBuilder service's namespace, in which a target operation is specified. * @param resourceType Resource type, that holds a referenced operation. * @param operationMethod Referenced operation method. * @param operationPath Operation path corresponding with the selected {{operation_method}}. * @param identifierField A field name. When the referenced operation is called, identifier_field is used * to extract the corresponding field from the response JSON. If the response JSON * is an array, then a value is extracted from the first object. * @param queryParams Optionally, the specified query params will be used to execute a referenced * operation. * @param deleteOperationPath Optionally, the referenced entity's DELETE operation path can be put here. If * specified, the generator will add a cleanup step for the referenced object. */ final case class ObjectReference( relatedServiceNamespace: String, resourceType: String, operationMethod: io.apibuilder.spec.v0.models.Method, operationPath: String, identifierField: String, queryParams: _root_.scala.Option[Map[String, String]] = None, deleteOperationPath: _root_.scala.Option[String] = None ) /** * Attribute instructs the generator to substitute a field value (when generating * examples) with specified value or variable reference. Attribute should be * attached to a field inside model. * * @param substitute Value, which will be put into the field marked by this attribute. It may be also * a variable reference. */ final case class ValueSubstitute( substitute: String ) /** * A set of attribute names, that are recognized by Postman Generator */ sealed trait AttributeName extends _root_.scala.Product with _root_.scala.Serializable object AttributeName { case object PostmanBasicAuth extends AttributeName { override def toString = "postman-basic-auth" } case object ObjectReference extends AttributeName { override def toString = "object-reference" } case object ValueSubstitute extends AttributeName { override def toString = "value-substitute" } /** * UNDEFINED captures values that are sent either in error or * that were added by the server after this library was * generated. We want to make it easy and obvious to users of * this library to handle this case gracefully. * * We use all CAPS for the variable name to avoid collisions * with the camel cased values above. */ final case class UNDEFINED(override val toString: String) extends AttributeName /** * all returns a list of all the valid, known values. We use * lower case to avoid collisions with the camel cased values * above. */ val all: scala.List[AttributeName] = scala.List(PostmanBasicAuth, ObjectReference, ValueSubstitute) private val byName: Map[String, AttributeName] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): AttributeName = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[AttributeName] = byName.get(value.toLowerCase) } } package io.postman.generator.attributes.v0.models { package object json { import play.api.libs.json.__ import play.api.libs.json.JsString import play.api.libs.json.Writes import play.api.libs.functional.syntax._ import io.apibuilder.spec.v0.models.json._ import io.postman.generator.attributes.v0.models.json._ private[v0] implicit val jsonReadsUUID: play.api.libs.json.Reads[_root_.java.util.UUID] = __.read[String].map { str => _root_.java.util.UUID.fromString(str) } private[v0] implicit val jsonWritesUUID: play.api.libs.json.Writes[_root_.java.util.UUID] = (x: _root_.java.util.UUID) => play.api.libs.json.JsString(x.toString) private[v0] implicit val jsonReadsJodaDateTime: play.api.libs.json.Reads[_root_.org.joda.time.DateTime] = __.read[String].map { str => _root_.org.joda.time.format.ISODateTimeFormat.dateTimeParser.parseDateTime(str) } private[v0] implicit val jsonWritesJodaDateTime: play.api.libs.json.Writes[_root_.org.joda.time.DateTime] = (x: _root_.org.joda.time.DateTime) => { play.api.libs.json.JsString(_root_.org.joda.time.format.ISODateTimeFormat.dateTime.print(x)) } private[v0] implicit val jsonReadsJodaLocalDate: play.api.libs.json.Reads[_root_.org.joda.time.LocalDate] = __.read[String].map { str => _root_.org.joda.time.format.ISODateTimeFormat.dateTimeParser.parseLocalDate(str) } private[v0] implicit val jsonWritesJodaLocalDate: play.api.libs.json.Writes[_root_.org.joda.time.LocalDate] = (x: _root_.org.joda.time.LocalDate) => { play.api.libs.json.JsString(_root_.org.joda.time.format.ISODateTimeFormat.date.print(x)) } implicit val jsonReadsPostmanGeneratorAttributesAttributeName: play.api.libs.json.Reads[io.postman.generator.attributes.v0.models.AttributeName] = new play.api.libs.json.Reads[io.postman.generator.attributes.v0.models.AttributeName] { def reads(js: play.api.libs.json.JsValue): play.api.libs.json.JsResult[io.postman.generator.attributes.v0.models.AttributeName] = { js match { case v: play.api.libs.json.JsString => play.api.libs.json.JsSuccess(io.postman.generator.attributes.v0.models.AttributeName(v.value)) case _ => { (js \ "value").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(io.postman.generator.attributes.v0.models.AttributeName(v)) case _: play.api.libs.json.JsError => (js \ "attribute_name").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(io.postman.generator.attributes.v0.models.AttributeName(v)) case err: play.api.libs.json.JsError => err } } } } } } def jsonWritesPostmanGeneratorAttributesAttributeName(obj: io.postman.generator.attributes.v0.models.AttributeName) = { play.api.libs.json.JsString(obj.toString) } def jsObjectAttributeName(obj: io.postman.generator.attributes.v0.models.AttributeName) = { play.api.libs.json.Json.obj("value" -> play.api.libs.json.JsString(obj.toString)) } implicit def jsonWritesPostmanGeneratorAttributesAttributeName: play.api.libs.json.Writes[AttributeName] = { (obj: io.postman.generator.attributes.v0.models.AttributeName) => { io.postman.generator.attributes.v0.models.json.jsonWritesPostmanGeneratorAttributesAttributeName(obj) } } implicit def jsonReadsPostmanGeneratorAttributesBasicAuth: play.api.libs.json.Reads[io.postman.generator.attributes.v0.models.BasicAuth] = { for { username <- (__ \ "username").read[String] password <- (__ \ "password").read[String] } yield BasicAuth(username, password) } def jsObjectBasicAuth(obj: io.postman.generator.attributes.v0.models.BasicAuth): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "username" -> play.api.libs.json.JsString(obj.username), "password" -> play.api.libs.json.JsString(obj.password) ) } implicit def jsonWritesPostmanGeneratorAttributesBasicAuth: play.api.libs.json.Writes[BasicAuth] = { (obj: io.postman.generator.attributes.v0.models.BasicAuth) => { io.postman.generator.attributes.v0.models.json.jsObjectBasicAuth(obj) } } implicit def jsonReadsPostmanGeneratorAttributesObjectReference: play.api.libs.json.Reads[io.postman.generator.attributes.v0.models.ObjectReference] = { for { relatedServiceNamespace <- (__ \ "related_service_namespace").read[String] resourceType <- (__ \ "resource_type").read[String] operationMethod <- (__ \ "operation_method").read[io.apibuilder.spec.v0.models.Method] operationPath <- (__ \ "operation_path").read[String] identifierField <- (__ \ "identifier_field").read[String] queryParams <- (__ \ "query_params").readNullable[Map[String, String]] deleteOperationPath <- (__ \ "delete_operation_path").readNullable[String] } yield ObjectReference(relatedServiceNamespace, resourceType, operationMethod, operationPath, identifierField, queryParams, deleteOperationPath) } def jsObjectObjectReference(obj: io.postman.generator.attributes.v0.models.ObjectReference): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "related_service_namespace" -> play.api.libs.json.JsString(obj.relatedServiceNamespace), "resource_type" -> play.api.libs.json.JsString(obj.resourceType), "operation_method" -> play.api.libs.json.JsString(obj.operationMethod.toString), "operation_path" -> play.api.libs.json.JsString(obj.operationPath), "identifier_field" -> play.api.libs.json.JsString(obj.identifierField) ) ++ (obj.queryParams match { case None => play.api.libs.json.Json.obj() case Some(x) => play.api.libs.json.Json.obj("query_params" -> play.api.libs.json.Json.toJson(x)) }) ++ (obj.deleteOperationPath match { case None => play.api.libs.json.Json.obj() case Some(x) => play.api.libs.json.Json.obj("delete_operation_path" -> play.api.libs.json.JsString(x)) }) } implicit def jsonWritesPostmanGeneratorAttributesObjectReference: play.api.libs.json.Writes[ObjectReference] = { (obj: io.postman.generator.attributes.v0.models.ObjectReference) => { io.postman.generator.attributes.v0.models.json.jsObjectObjectReference(obj) } } implicit def jsonReadsPostmanGeneratorAttributesValueSubstitute: play.api.libs.json.Reads[io.postman.generator.attributes.v0.models.ValueSubstitute] = { (__ \ "substitute").read[String].map { x => ValueSubstitute(substitute = x) } } def jsObjectValueSubstitute(obj: io.postman.generator.attributes.v0.models.ValueSubstitute): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "substitute" -> play.api.libs.json.JsString(obj.substitute) ) } implicit def jsonWritesPostmanGeneratorAttributesValueSubstitute: play.api.libs.json.Writes[ValueSubstitute] = { (obj: io.postman.generator.attributes.v0.models.ValueSubstitute) => { io.postman.generator.attributes.v0.models.json.jsObjectValueSubstitute(obj) } } } } package io.postman.generator.attributes.v0 { object Bindables { import play.api.mvc.{PathBindable, QueryStringBindable} // import models directly for backwards compatibility with prior versions of the generator import Core._ import Models._ object Core { implicit def pathBindableDateTimeIso8601(implicit stringBinder: QueryStringBindable[String]): PathBindable[_root_.org.joda.time.DateTime] = ApibuilderPathBindable(ApibuilderTypes.dateTimeIso8601) implicit def queryStringBindableDateTimeIso8601(implicit stringBinder: QueryStringBindable[String]): QueryStringBindable[_root_.org.joda.time.DateTime] = ApibuilderQueryStringBindable(ApibuilderTypes.dateTimeIso8601) implicit def pathBindableDateIso8601(implicit stringBinder: QueryStringBindable[String]): PathBindable[_root_.org.joda.time.LocalDate] = ApibuilderPathBindable(ApibuilderTypes.dateIso8601) implicit def queryStringBindableDateIso8601(implicit stringBinder: QueryStringBindable[String]): QueryStringBindable[_root_.org.joda.time.LocalDate] = ApibuilderQueryStringBindable(ApibuilderTypes.dateIso8601) } object Models { import io.postman.generator.attributes.v0.models._ val attributeNameConverter: ApibuilderTypeConverter[io.postman.generator.attributes.v0.models.AttributeName] = new ApibuilderTypeConverter[io.postman.generator.attributes.v0.models.AttributeName] { override def convert(value: String): io.postman.generator.attributes.v0.models.AttributeName = io.postman.generator.attributes.v0.models.AttributeName(value) override def convert(value: io.postman.generator.attributes.v0.models.AttributeName): String = value.toString override def example: io.postman.generator.attributes.v0.models.AttributeName = io.postman.generator.attributes.v0.models.AttributeName.PostmanBasicAuth override def validValues: Seq[io.postman.generator.attributes.v0.models.AttributeName] = io.postman.generator.attributes.v0.models.AttributeName.all } implicit def pathBindableAttributeName(implicit stringBinder: QueryStringBindable[String]): PathBindable[io.postman.generator.attributes.v0.models.AttributeName] = ApibuilderPathBindable(attributeNameConverter) implicit def queryStringBindableAttributeName(implicit stringBinder: QueryStringBindable[String]): QueryStringBindable[io.postman.generator.attributes.v0.models.AttributeName] = ApibuilderQueryStringBindable(attributeNameConverter) } trait ApibuilderTypeConverter[T] { def convert(value: String): T def convert(value: T): String def example: T def validValues: Seq[T] = Nil def errorMessage(key: String, value: String, ex: java.lang.Exception): String = { val base = s"Invalid value '$value' for parameter '$key'. " validValues.toList match { case Nil => base + "Ex: " + convert(example) case values => base + ". Valid values are: " + values.mkString("'", "', '", "'") } } } object ApibuilderTypes { val dateTimeIso8601: ApibuilderTypeConverter[_root_.org.joda.time.DateTime] = new ApibuilderTypeConverter[_root_.org.joda.time.DateTime] { override def convert(value: String): _root_.org.joda.time.DateTime = _root_.org.joda.time.format.ISODateTimeFormat.dateTimeParser.parseDateTime(value) override def convert(value: _root_.org.joda.time.DateTime): String = _root_.org.joda.time.format.ISODateTimeFormat.dateTime.print(value) override def example: _root_.org.joda.time.DateTime = _root_.org.joda.time.DateTime.now } val dateIso8601: ApibuilderTypeConverter[_root_.org.joda.time.LocalDate] = new ApibuilderTypeConverter[_root_.org.joda.time.LocalDate] { override def convert(value: String): _root_.org.joda.time.LocalDate = _root_.org.joda.time.format.ISODateTimeFormat.dateTimeParser.parseLocalDate(value) override def convert(value: _root_.org.joda.time.LocalDate): String = _root_.org.joda.time.format.ISODateTimeFormat.date.print(value) override def example: _root_.org.joda.time.LocalDate = _root_.org.joda.time.LocalDate.now } } final case class ApibuilderQueryStringBindable[T]( converters: ApibuilderTypeConverter[T] ) extends QueryStringBindable[T] { override def bind(key: String, params: Map[String, Seq[String]]): _root_.scala.Option[_root_.scala.Either[String, T]] = { params.getOrElse(key, Nil).headOption.map { v => try { Right( converters.convert(v) ) } catch { case ex: java.lang.Exception => Left( converters.errorMessage(key, v, ex) ) } } } override def unbind(key: String, value: T): String = { s"$key=${converters.convert(value)}" } } final case class ApibuilderPathBindable[T]( converters: ApibuilderTypeConverter[T] ) extends PathBindable[T] { override def bind(key: String, value: String): _root_.scala.Either[String, T] = { try { Right( converters.convert(value) ) } catch { case ex: java.lang.Exception => Left( converters.errorMessage(key, value, ex) ) } } override def unbind(key: String, value: T): String = { converters.convert(value) } } } }