Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

W-15633231: add AVRO basic resolution pipelines #2023

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import amf.apicontract.internal.convert.ApiRegister
import amf.apicontract.internal.entities.{APIEntities, FragmentEntities}
import amf.apicontract.internal.plugins.ApiContractFallbackPlugin
import amf.apicontract.internal.spec.async.{Async20ElementRenderPlugin, Async20ParsePlugin, Async20RenderPlugin}
import amf.apicontract.internal.spec.avro.transformation.{
AvroSchemaCachePipeline,
AvroSchemaEditingPipeline,
AvroSchemaTransformationPipeline
}
import amf.apicontract.internal.spec.avro.AvroParsePlugin
import amf.apicontract.internal.spec.oas._
import amf.apicontract.internal.spec.raml._
Expand Down Expand Up @@ -159,8 +164,17 @@ object RAMLConfiguration extends APIConfigurationBuilder {

// AVRO is in alpha support mode
object AvroConfiguration extends APIConfigurationBuilder {
def Avro(): AMFConfiguration =
common().withPlugins(List(AvroParsePlugin)) // TODO: add validation profiles and serialization
def Avro(): AMFConfiguration = {
common()
.withPlugins(List(AvroParsePlugin)) // TODO: add validation profiles and serialization
.withTransformationPipelines(
List(
AvroSchemaTransformationPipeline(),
AvroSchemaEditingPipeline(),
AvroSchemaCachePipeline()
)
)
}
}

/** [[APIConfigurationBuilder.common common()]] configuration with all configurations needed for OAS like:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package amf.apicontract.internal.spec.avro.transformation

import amf.core.client.common.transform._
import amf.core.client.common.validation.ProfileNames.AVROSCHEMA
import amf.core.client.scala.transform.{TransformationPipeline, TransformationStep}
import amf.core.internal.transform.stages.{ReferenceResolutionStage, SourceInformationStage, UrlShortenerStage}
import amf.shapes.internal.domain.resolution.ShapeNormalizationForUnitStage

class AvroSchemaEditingPipeline private (urlShortening: Boolean = true, val name: String)
extends TransformationPipeline {

private def url: Option[UrlShortenerStage] = if (urlShortening) Some(new UrlShortenerStage()) else None

override def steps: Seq[TransformationStep] = Seq()
// Seq(
// new ReferenceResolutionStage(true),
// new ShapeNormalizationForUnitStage(AVROSCHEMA, keepEditingInfo = true)
// ) ++ url :+ SourceInformationStage
}

object AvroSchemaEditingPipeline {
def apply() = new AvroSchemaEditingPipeline(true, name)
private[amf] def cachePipeline = new AvroSchemaEditingPipeline(false, PipelineId.Editing)
val name: String = PipelineId.Editing
}

object AvroSchemaCachePipeline {
val name: String = PipelineId.Cache
private[amf] def apply(): AvroSchemaEditingPipeline = AvroSchemaEditingPipeline.cachePipeline
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package amf.apicontract.internal.spec.avro.transformation

import amf.core.client.common.transform.PipelineId
import amf.core.client.common.validation.AvroSchemaProfile
import amf.core.client.scala.transform.{TransformationPipeline, TransformationStep}
import amf.core.internal.transform.stages.{
CleanReferencesStage,
ExternalSourceRemovalStage,
ReferenceResolutionStage,
SourceInformationStage
}
import amf.shapes.internal.domain.resolution.ShapeNormalizationForUnitStage

class AvroSchemaTransformationPipeline private (override val name: String) extends TransformationPipeline() {
def references = new ReferenceResolutionStage(false)

// in theory we don't need any transformation step, but i'll leave here the common ones
override def steps: Seq[TransformationStep] =
Seq(
// references,
// new ExternalSourceRemovalStage,
// new ShapeNormalizationForUnitStage(AvroSchemaProfile, keepEditingInfo = false),
// new CleanReferencesStage(),
// SourceInformationStage
)
}

object AvroSchemaTransformationPipeline {
def apply() = new AvroSchemaTransformationPipeline(name)
val name: String = PipelineId.Default
}
Original file line number Diff line number Diff line change
Expand Up @@ -1220,14 +1220,16 @@ object APIRawValidations extends CommonValidationDefinitions {
value = "direct,persistent"
),
AMFValidation(
message = "Invalid 'maxMsgSpoolSize' value. It should be a string representing the maximum size of the message spool.",
message =
"Invalid 'maxMsgSpoolSize' value. It should be a string representing the maximum size of the message spool.",
owlClass = apiBinding("SolaceOperationQueue030"),
owlProperty = apiBinding("maxMsgSpoolSize"),
constraint = sh("datatype"),
value = "xsd:string"
),
AMFValidation(
message = "Invalid 'maxMsgSpoolSize' value. It should be a string representing the maximum size of the message spool.",
message =
"Invalid 'maxMsgSpoolSize' value. It should be a string representing the maximum size of the message spool.",
owlClass = apiBinding("SolaceOperationQueue040"),
owlProperty = apiBinding("maxMsgSpoolSize"),
constraint = sh("datatype"),
Expand Down Expand Up @@ -1672,7 +1674,8 @@ object APIRawValidations extends CommonValidationDefinitions {
Oas20Profile -> forProfile(Oas20Profile),
Oas30Profile -> forProfile(Oas30Profile),
Async20Profile -> forProfile(Async20Profile),
JsonSchemaProfile -> forProfile(JsonSchemaProfile)
JsonSchemaProfile -> forProfile(JsonSchemaProfile),
AvroSchemaProfile -> forProfile(AvroSchemaProfile)
)

override def forProfile(p: ProfileName): ProfileValidations = {
Expand All @@ -1683,6 +1686,7 @@ object APIRawValidations extends CommonValidationDefinitions {
case Oas30Profile => Oas30Validations
case Async20Profile => Async20Validations
case JsonSchemaProfile => ShapeValidations
case AvroSchemaProfile => ShapeValidations // todo: should we do ShapeValidations?
case AmfProfile => AmfValidations
case _ =>
() => Seq.empty
Expand Down