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-16124325 -Avro interfaces #2015

Merged
merged 3 commits into from
Jul 3, 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
@@ -1,14 +1,14 @@
package amf.apicontract.client.platform

import amf.aml.client.platform.model.document.Dialect
import amf.aml.client.platform.model.document.DialectInstance
import amf.aml.client.platform.model.document.{Dialect, DialectInstance}
import amf.aml.internal.convert.VocabulariesClientConverter.DialectConverter
import amf.apicontract.client.scala.{
APIConfiguration => InternalAPIConfiguration,
AsyncAPIConfiguration => InternalAsyncAPIConfiguration,
OASConfiguration => InternalOASConfiguration,
RAMLConfiguration => InternalRAMLConfiguration,
WebAPIConfiguration => InternalWebAPIConfiguration
WebAPIConfiguration => InternalWebAPIConfiguration,
AvroConfiguration => InternalAvroConfiguration
}
import amf.apicontract.internal.convert.ApiClientConverters._
import amf.core.client.platform.config.{AMFEventListener, ParsingOptions, RenderOptions}
Expand All @@ -21,8 +21,7 @@ import amf.core.internal.convert.TransformationPipelineConverter._

import scala.scalajs.js.annotation.{JSExportAll, JSExportTopLevel}
import amf.apicontract.client.scala
import amf.core.client.platform.AMFGraphConfiguration
import amf.core.client.platform.adoption.{IdAdopter, IdAdopterProvider}
import amf.core.client.platform.adoption.IdAdopterProvider
import amf.core.client.platform.execution.BaseExecutionEnvironment
import amf.core.client.platform.validation.payload.AMFShapePayloadValidationPlugin
import amf.core.internal.convert.PayloadValidationPluginConverter.PayloadValidationPluginMatcher
Expand Down Expand Up @@ -220,3 +219,10 @@ object APIConfiguration {
def API(): AMFConfiguration = InternalAPIConfiguration.API()
def fromSpec(spec: Spec): AMFConfiguration = InternalAPIConfiguration.fromSpec(spec)
}

// AVRO is in alpha support mode
@JSExportAll
@JSExportTopLevel("AvroConfiguration")
object AvroConfiguration {
def Avro(): AMFConfiguration = InternalAvroConfiguration.Avro()
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ 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
Expand Down
12 changes: 12 additions & 0 deletions amf-cli/js/typings/amf-client-js.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1443,6 +1443,9 @@ declare module "amf-client-js" {
writeOnly: BoolField;
xmlSerialization: XMLSerializer;
xone: Array<Shape>;
namespace: StrField;
aliases: Array<StrField>;
size: IntField;

constructor();

Expand Down Expand Up @@ -1531,6 +1534,12 @@ declare module "amf-client-js" {
withXMLSerialization(xmlSerialization: XMLSerializer): this;

withXone(subShapes: Array<Shape>): this;

withNamespace(namespace: string): this;

withAliases(aliases: Array<string>): this;

withSize(size: number): this;
}
export class Api<A> implements DomainElement {
accepts: Array<StrField>;
Expand Down Expand Up @@ -1716,6 +1725,9 @@ declare module "amf-client-js" {

withVersion(version: string): this;
}
export class AvroConfiguration {
static Avro(): AMFConfiguration;
}
export class BaseAMLBaseUnitClient extends AMFGraphBaseUnitClient {
parseDialect(url: string): Promise<AMLDialectResult>;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package amf.shapes.client.platform.model.domain

import amf.core.client.platform.model.domain.Shape
import amf.core.client.platform.model.StrField
import amf.core.client.platform.model.{IntField, StrField}
import amf.core.internal.unsafe.PlatformSecrets

import scala.scalajs.js.annotation.{JSExport, JSExportTopLevel}
Expand All @@ -21,6 +21,12 @@ class AnyShape(override private[amf] val _internal: InternalAnyShape) extends Sh
def examples: ClientList[Example] = _internal.examples.asClient
@JSExport
def comment: StrField = _internal.comment
@JSExport
def namespace: StrField = _internal.namespace
@JSExport
def aliases: ClientList[StrField] = _internal.aliases.asClient
@JSExport
def size: IntField = _internal.size

@JSExport
def withDocumentation(documentation: CreativeWork): this.type = {
Expand Down Expand Up @@ -70,4 +76,22 @@ class AnyShape(override private[amf] val _internal: InternalAnyShape) extends Sh
// Aux method to know if the shape has the annotation of [[InlineDefinition]]
@JSExport
def inlined(): Boolean = _internal.inlined

@JSExport
def withNamespace(namespace: String): this.type = {
_internal.withNamespace(namespace)
this
}

@JSExport
def withAliases(aliases: Seq[String]): this.type = {
_internal.withAliases(aliases)
this
}

@JSExport
def withSize(size: Int): this.type = {
_internal.withSize(size)
this
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class AnyShape private[amf] (val fields: Fields, val annotations: Annotations =
with ExternalSourceElement
with InheritanceChain
with DocumentedElement
with ExemplifiedDomainElement {
with ExemplifiedDomainElement
with AvroShapeFields {

// This is used in ShapeNormalization to know if a Shape should go through the AnyShapeAdjuster
private[amf] val isConcreteShape: Boolean = false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package amf.shapes.client.scala.model.domain

import amf.core.client.scala.model.domain.Shape
import amf.core.client.scala.model.{IntField, StrField}
import amf.shapes.internal.domain.metamodel.AnyShapeModel._

protected[amf] trait AvroShapeFields { self: Shape =>

def namespace: StrField = fields.field(AvroNamespace)
def aliases: Seq[StrField] = fields.field(Aliases)
def size: IntField = fields.field(Size)

def withNamespace(namespace: String): this.type = set(AvroNamespace, namespace)
def withAliases(aliases: Seq[String]): this.type = set(Aliases, aliases)
def withSize(size: Int): this.type = set(Size, size)

}