-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1932 from aml-org/publish-5.4.8
W-13925199 Publish 5.4.8
- Loading branch information
Showing
330 changed files
with
19,477 additions
and
1,556 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...ed/src/main/scala/amf/apicontract/internal/spec/async/NotFinishedAsync20ParsePlugin.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package amf.apicontract.internal.spec.async | ||
|
||
import amf.apicontract.internal.spec.async.AsyncHeader._ | ||
import amf.apicontract.internal.spec.async.parser.context.{Async2WebApiContext, AsyncWebApiContext} | ||
import amf.apicontract.internal.spec.async.parser.document | ||
import amf.apicontract.internal.spec.common.AsyncWebApiDeclarations | ||
import amf.apicontract.internal.spec.oas.OasLikeParsePlugin | ||
import amf.apicontract.internal.spec.raml.Raml10ParsePlugin | ||
import amf.core.client.scala.config.ParsingOptions | ||
import amf.core.client.scala.exception.InvalidDocumentHeaderException | ||
import amf.core.client.scala.model.document.BaseUnit | ||
import amf.core.client.scala.parse.document.{EmptyFutureDeclarations, ParsedReference, ParserContext} | ||
import amf.core.internal.parser.Root | ||
import amf.core.internal.remote.{AsyncApi20, Mimes, Spec} | ||
|
||
/* | ||
* This plugin should be merged with Async20ParsePlugin after Async 2.x feature is finished | ||
*/ | ||
object NotFinishedAsync20ParsePlugin extends OasLikeParsePlugin { | ||
|
||
override def spec: Spec = AsyncApi20 | ||
|
||
override def applies(element: Root): Boolean = AsyncHeader(element).isDefined | ||
|
||
override def validSpecsToReference: Seq[Spec] = | ||
super.validSpecsToReference :+ Raml10ParsePlugin.spec | ||
|
||
override def mediaTypes: Seq[String] = Seq(Mimes.`application/yaml`, Mimes.`application/json`) | ||
|
||
override def parse(document: Root, ctx: ParserContext): BaseUnit = { | ||
val header = parseHeader(document) | ||
implicit val newCtx: AsyncWebApiContext = | ||
context(document.location, document.references, ctx.parsingOptions, ctx, spec = header.spec) | ||
restrictCrossSpecReferences(document, ctx) | ||
val parsed = parseAsyncUnit(header, document) | ||
promoteFragments(parsed, newCtx) | ||
} | ||
|
||
private def parseHeader(root: Root): AsyncHeader = | ||
AsyncHeader(root).getOrElse(throw new InvalidDocumentHeaderException(spec.id)) | ||
|
||
private def parseAsyncUnit(header: AsyncHeader, root: Root)(implicit ctx: AsyncWebApiContext): BaseUnit = { | ||
header match { | ||
case Async20Header => document.AsyncApi20DocumentParser(root).parseDocument() | ||
case Async21Header => document.AsyncApi21DocumentParser(root).parseDocument() | ||
case Async22Header => document.AsyncApi22DocumentParser(root).parseDocument() | ||
case Async23Header => document.AsyncApi23DocumentParser(root).parseDocument() | ||
case Async24Header => document.AsyncApi24DocumentParser(root).parseDocument() | ||
case Async25Header => document.AsyncApi25DocumentParser(root).parseDocument() | ||
case Async26Header => document.AsyncApi26DocumentParser(root).parseDocument() | ||
case _ => | ||
throw new InvalidDocumentHeaderException(spec.id) | ||
} | ||
} | ||
|
||
private def context( | ||
loc: String, | ||
refs: Seq[ParsedReference], | ||
options: ParsingOptions, | ||
wrapped: ParserContext, | ||
ds: Option[AsyncWebApiDeclarations] = None, | ||
spec: Spec | ||
): Async2WebApiContext = { | ||
// ensure unresolved references in external fragments are not resolved with main api definitions | ||
val cleanContext = wrapped.copy(futureDeclarations = EmptyFutureDeclarations()) | ||
cleanContext.globalSpace = wrapped.globalSpace | ||
Async2WebApiContext(loc, refs, cleanContext, ds, options, spec) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...f/apicontract/internal/spec/async/emitters/domain/AsyncApiDefaultContentTypeEmitter.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package amf.apicontract.internal.spec.async.emitters.domain | ||
|
||
import amf.core.client.scala.model.domain.{AmfArray, AmfScalar} | ||
import amf.core.internal.parser.domain.FieldEntry | ||
import amf.core.internal.render.BaseEmitters.pos | ||
import amf.core.internal.render.SpecOrdering | ||
import amf.core.internal.render.emitters.EntryEmitter | ||
import org.mulesoft.common.client.lexical.Position | ||
import org.yaml.model.{YDocument, YNode} | ||
|
||
case class DefaultContentTypeEmitter(f: FieldEntry, ordering: SpecOrdering) extends EntryEmitter { | ||
override def emit(b: YDocument.EntryBuilder): Unit = { | ||
val maybeString: Option[String] = getValue | ||
maybeString.foreach(contentType => b.entry("defaultContentType", YNode(contentType))) | ||
|
||
} | ||
|
||
private def getValue: Option[String] = { | ||
f.value.value match { | ||
case array: AmfArray => | ||
array.values | ||
.headOption | ||
.map(f => f.asInstanceOf[AmfScalar].value.toString) | ||
case _ => | ||
None | ||
} | ||
} | ||
|
||
override def position(): Position = pos(f.value.annotations) | ||
} |
Oops, something went wrong.