Skip to content

Commit

Permalink
Merge pull request #1117 from aml-org/publish-beta-4
Browse files Browse the repository at this point in the history
APIMF-3342: Publish beta 4
  • Loading branch information
tomsfernandez committed Sep 1, 2021
2 parents 68c751c + fa1fa9d commit 28dd609
Show file tree
Hide file tree
Showing 393 changed files with 55,236 additions and 108,936 deletions.
7 changes: 5 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ def headerFlavour = "WARNING"

pipeline {
agent {
dockerfile true
dockerfile {
filename 'Dockerfile'
registryCredentialsId 'dockerhub-pro-credentials'
}
}
environment {
NEXUS = credentials('exchange-nexus')
Expand Down Expand Up @@ -161,7 +164,7 @@ pipeline {
}
def newAmfVersion = getAmfVersion()
echo "Starting ApiQuery hook API-Query/api-query-amf-integration/master with amf version: ${newAmfVersion}"
build job: "API-Query/api-query-amf-integration/master", wait: false, parameters: [[$class: 'StringParameterValue', name: 'AMF_NEW_VERSION', value: newAmfVersion]]
build job: "API-Query-new/api-query-amf-integration/master", wait: false, parameters: [[$class: 'StringParameterValue', name: 'AMF_NEW_VERSION', value: newAmfVersion]]
}
} catch(ignored) {
failedStage = failedStage + " JOBS TRIGGER "
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ The **only** guaranteed output of AMF is the JSON-LD "AMF model". Any other outp

## Documentation
- [The AML Project](https://a.ml)
- [What is AMF?](https://a.ml/docbook/overview_amf.html)
- [What is AMF?](https://a.ml/docs)
- [AMF model documentation](documentation/model.md)
- [Validation insights](./documentation/validation.md)
- [Basic use cases - parsing & validating an API](documentation/basic_use_cases.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package amf.antlr.client.scala.parse.document

import amf.core.client.scala.parse.document.ParsedDocument
import org.mulesoft.antlrast.ast.AST

case class AntlrParsedDocument(ast: AST, override val comment: Option[String] = None) extends ParsedDocument
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package amf.antlr.client.scala.parse.syntax

import amf.apicontract.internal.validation.definitions.ParserSideValidations
import amf.core.client.scala.parse.document.ParserContext
import amf.core.internal.annotations.LexicalInformation
import amf.core.internal.parser.domain.Annotations
import org.mulesoft.antlrast.ast.{ASTElement, Node, Terminal}

trait AntlrASTParserHelper {
def find(node: Node, name: String): Seq[ASTElement] = node.children.filter(_.name == name)

def collect(node: ASTElement, names: Seq[String]): Seq[ASTElement] = {
if (names.isEmpty) {
Seq(node)
} else {
val nextName = names.head
node match {
case n: Node =>
find(n, nextName).flatMap { nested =>
collect(nested, names.tail)
}
case _ => Nil
}
}
}

def path(node: ASTElement, names: Seq[String]): Option[ASTElement] = {
if (names.isEmpty) {
Some(node)
} else {
val nextName = names.head
node match {
case n: Node =>
find(n, nextName) match {
case found: Seq[ASTElement] if found.length == 1 =>
path(found.head, names.tail)
case _ =>
None
}
case _ =>
None
}
}
}

def withNode[T](element: ASTElement)(f: Node => T)(implicit ctx: ParserContext): T = element match {
case node: Node => f(node)
case _ => throw new Exception(s"Unexpected AST terminal token $element")
}

def withOptTerminal[T](element: ASTElement)(f: Option[Terminal] => T)(implicit ctx: ParserContext): T = element match {
case node: Node if node.children.length == 1 && node.children.head.isInstanceOf[Terminal] =>
f(Some(node.children.head.asInstanceOf[Terminal]))
case _ =>
f(None)
}

def toAnnotations(elem: ASTElement): Annotations = {
val lexInfo = LexicalInformation(elem.start.line, elem.start.column, elem.end.line, elem.end.column)
Annotations() ++= Set(lexInfo)
}

def astError(id: String, message: String, annotations: Annotations)(implicit ctx: ParserContext): Unit = {
ctx.eh.violation(ParserSideValidations.InvalidAst, id, message, annotations)
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package amf.antlr.internal.plugins.syntax

import amf.antlr.client.scala.parse.document.AntlrParsedDocument
import amf.core.client.common.{HighPriority, PluginPriority}
import amf.core.client.scala.parse.AMFSyntaxParsePlugin
import amf.core.client.scala.parse.document.{ParsedDocument, ParserContext}
import amf.core.internal.remote.Mimes.`application/x-protobuf`
import amf.core.internal.remote.Syntax
import org.mulesoft.antlrast.platform.PlatformProtobuf3Parser

object AntlrSyntaxParsePlugin extends AMFSyntaxParsePlugin {

override def parse(text: CharSequence, mediaType: String, ctx: ParserContext): ParsedDocument = {
val input = text.toString
val ast = new PlatformProtobuf3Parser().parse(ctx.rootContextDocument, input)
AntlrParsedDocument(ast, None)
}

override def mediaTypes: Seq[String] = Syntax.proto3Mimes.toSeq ++ Syntax.graphQLMimes.toSeq

override val id: String = "antlr-ast-parse"

override def applies(element: CharSequence): Boolean = {
val text = element.toString
val isJSONObject = text.startsWith("{") && text.endsWith("}")
val isJSONArray = text.startsWith("[") && text.endsWith("]")
val isYamlHash = text.startsWith("#")
val containsProto = text.contains("proto3")
containsProto && !isJSONArray && !isJSONObject && !isYamlHash
}

override def priority: PluginPriority = HighPriority

override def mainMediaType: String = `application/x-protobuf`
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package amf.antlr.internal.plugins.syntax

import amf.antlr.client.scala.parse.document.AntlrParsedDocument
import amf.core.client.common.{NormalPriority, PluginPriority}
import amf.core.client.scala.parse.document.{ParsedDocument, StringParsedDocument}
import amf.core.client.scala.render.AMFSyntaxRenderPlugin
import amf.core.internal.remote.Syntax
import org.mulesoft.common.io.Output
import org.mulesoft.common.io.Output.OutputOps

object AntlrSyntaxRenderPlugin extends AMFSyntaxRenderPlugin {

override def emit[W: Output](mediaType: String, ast: ParsedDocument, writer: W): Option[W] = {
ast match {
case str: StringParsedDocument =>
writer.append(str.ast.builder.toString)
Some(writer)
case _ => None
}
}

/**
* media types which specifies vendors that are parsed by this plugin.
*/
override def mediaTypes: Seq[String] = Syntax.proto3Mimes.toSeq ++ Syntax.graphQLMimes.toSeq

override val id: String = "antlr-ast-render"

override def applies(element: ParsedDocument): Boolean = element.isInstanceOf[StringParsedDocument]

override def priority: PluginPriority = NormalPriority
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@ 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.execution.BaseExecutionEnvironment
import amf.core.client.platform.validation.payload.AMFShapePayloadValidationPlugin
import amf.core.internal.convert.PayloadValidationPluginConverter.PayloadValidationPluginMatcher
import amf.core.internal.remote.Spec
import amf.shapes.client.platform.BaseShapesConfiguration

@JSExportAll
class AMFConfiguration private[amf] (private[amf] override val _internal: scala.AMFConfiguration)
extends BaseAMLConfiguration(_internal) {
extends BaseShapesConfiguration(_internal) {

override def baseUnitClient(): AMFBaseUnitClient = new AMFBaseUnitClient(this)
def elementClient(): AMFElementClient = new AMFElementClient(this)
override def elementClient(): AMFElementClient = new AMFElementClient(this)
def configurationState(): AMFConfigurationState = new AMFConfigurationState(this)

override def withParsingOptions(parsingOptions: ParsingOptions): AMFConfiguration =
Expand Down Expand Up @@ -79,9 +80,10 @@ class AMFConfiguration private[amf] (private[amf] override val _internal: scala.
@JSExportAll
@JSExportTopLevel("RAMLConfiguration")
object RAMLConfiguration {
def RAML10(): AMFConfiguration = InternalRAMLConfiguration.RAML10()
def RAML08(): AMFConfiguration = InternalRAMLConfiguration.RAML08()
def RAML(): AMFConfiguration = InternalRAMLConfiguration.RAML()
def RAML10(): AMFConfiguration = InternalRAMLConfiguration.RAML10()
def RAML08(): AMFConfiguration = InternalRAMLConfiguration.RAML08()
def RAML(): AMFConfiguration = InternalRAMLConfiguration.RAML()
def fromSpec(spec: Spec): AMFConfiguration = InternalRAMLConfiguration.fromSpec(spec)
}

/**
Expand All @@ -93,16 +95,18 @@ object RAMLConfiguration {
@JSExportAll
@JSExportTopLevel("OASConfiguration")
object OASConfiguration {
def OAS20(): AMFConfiguration = InternalOASConfiguration.OAS20()
def OAS30(): AMFConfiguration = InternalOASConfiguration.OAS30()
def OAS(): AMFConfiguration = InternalOASConfiguration.OAS()
def OAS20(): AMFConfiguration = InternalOASConfiguration.OAS20()
def OAS30(): AMFConfiguration = InternalOASConfiguration.OAS30()
def OAS(): AMFConfiguration = InternalOASConfiguration.OAS()
def fromSpec(spec: Spec): AMFConfiguration = InternalOASConfiguration.fromSpec(spec)
}

/** Merged [[OASConfiguration]] and [[RAMLConfiguration]] configurations */
@JSExportAll
@JSExportTopLevel("WebAPIConfiguration")
object WebAPIConfiguration {
def WebAPI(): AMFConfiguration = InternalWebAPIConfiguration.WebAPI()
def WebAPI(): AMFConfiguration = InternalWebAPIConfiguration.WebAPI()
def fromSpec(spec: Spec): AMFConfiguration = InternalWebAPIConfiguration.fromSpec(spec)
}

/**
Expand All @@ -120,5 +124,6 @@ object AsyncAPIConfiguration {
@JSExportAll
@JSExportTopLevel("APIConfiguration")
object APIConfiguration {
def API(): AMFConfiguration = InternalAPIConfiguration.API()
def API(): AMFConfiguration = InternalAPIConfiguration.API()
def fromSpec(spec: Spec): AMFConfiguration = InternalAPIConfiguration.fromSpec(spec)
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package amf.apicontract.client.platform

import amf.aml.client.platform.BaseAMLElementClient
import amf.aml.client.platform.model.document.Dialect
import amf.aml.client.platform.render.AmlDomainElementEmitter
import amf.apicontract.client.platform.model.domain.templates.{ResourceType, Trait}
import amf.apicontract.client.platform.model.domain.{EndPoint, Operation}
import amf.apicontract.client.platform.transform.AbstractElementTransformer
Expand All @@ -14,16 +11,15 @@ import amf.core.client.platform.model.document.BaseUnit
import amf.core.client.platform.model.domain.DomainElement
import amf.core.client.platform.render.AMFElementRenderer
import amf.core.internal.convert.ClientErrorHandlerConverter._
import amf.shapes.client.platform.model.domain.AnyShape
import amf.shapes.client.platform.render.{JsonSchemaShapeRenderer, RamlShapeRenderer}
import amf.shapes.client.platform.BaseShapesElementClient
import org.yaml.builder.DocBuilder

import scala.scalajs.js.annotation.JSExportAll

/** Contains common AML operations not related to document. */
@JSExportAll
class AMFElementClient private[amf] (private val _internal: InternalAMFElementClient)
extends BaseAMLElementClient(_internal) {
extends BaseShapesElementClient(_internal) {

private[amf] def this(configuration: AMFConfiguration) = {
this(new InternalAMFElementClient(configuration))
Expand All @@ -33,20 +29,16 @@ class AMFElementClient private[amf] (private val _internal: InternalAMFElementCl

private def obtainEH: ClientErrorHandler = getConfiguration()._internal.errorHandlerProvider.errorHandler()

def toJsonSchema(element: AnyShape): String = JsonSchemaShapeRenderer.toJsonSchema(element, getConfiguration())
def buildJsonSchema(element: AnyShape): String = JsonSchemaShapeRenderer.buildJsonSchema(element, getConfiguration())

def toRamlDatatype(element: AnyShape): String = RamlShapeRenderer.toRamlDatatype(element, getConfiguration())

override def renderToBuilder[T](element: DomainElement, builder: DocBuilder[T]): Unit =
AMFElementRenderer.renderToBuilder(element, builder, getConfiguration())

// TODO ARM: Replace profile for spec
/** Get this resource type as an endpoint. No variables will be replaced. Pass the BaseUnit that contains this trait to use its declarations and the profile ProfileNames.RAML08 if this is from a raml08 unit. */
def asEndpoint[T <: BaseUnit](unit: T, rt: ResourceType, profile: ProfileName = Raml10Profile): EndPoint =
AbstractElementTransformer.asEndpoint(unit, rt, obtainEH, profile)

// TODO ARM: Replace profile for spec
/** Get this trait as an operation. No variables will be replaced. Pass the BaseUnit that contains this trait to use its declarations and the profile ProfileNames.RAML08 if this is from a raml08 unit. */
def asOperation[T <: BaseUnit](unit: T, tr: Trait, profile: ProfileName = Raml10Profile): Operation =
AbstractElementTransformer.asOperation(unit, tr, obtainEH, profile)

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import amf.core.client.scala.{AMFParseResult, AMFResult}
import amf.core.client.scala.model.document.{BaseUnit, Document, Module}
import amf.core.client.scala.parse.{AMFParser, InvalidBaseUnitTypeException}
import amf.core.internal.metamodel.document.{DocumentModel, ModuleModel}
import amf.shapes.client.scala.ShapesBaseUnitClient

import scala.concurrent.{ExecutionContext, Future}

Expand All @@ -15,7 +16,7 @@ import scala.concurrent.{ExecutionContext, Future}
* For more complex uses see [[AMFParser]] or [[amf.core.client.scala.render.AMFRenderer]]
*/
class AMFBaseUnitClient private[amf] (override protected val configuration: AMFConfiguration)
extends AMLBaseUnitClient(configuration) {
extends ShapesBaseUnitClient(configuration) {

override implicit val exec: ExecutionContext = configuration.getExecutionContext

Expand Down
Loading

0 comments on commit 28dd609

Please sign in to comment.