Skip to content
Draft
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
68 changes: 38 additions & 30 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,50 @@ permissions:
jobs:
ci:
runs-on: ubuntu-latest
steps:
- name: Checkout current branch
uses: actions/checkout@v3
with:
submodules: 'true'
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
check-latest: true
cache: 'sbt'
- name: Run tests
run: sbt lint test
env:
# see https://stackoverflow.com/questions/69394632/webpack-build-failing-with-err-ossl-evp-unsupported
NODE_OPTIONS: "--openssl-legacy-provider"

publish:
runs-on: ubuntu-latest
needs: [ci]
if: github.event_name == 'release'
steps:
- name: Checkout current branch
uses: actions/checkout@v3
with:
submodules: 'true'
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
check-latest: true
cache: 'sbt'
- name: Release
run: sbt ci-release
check-latest: true
- uses: bleep-build/[email protected]
- uses: coursier/cache-action@v6
with:
extraFiles: bleep.yaml

- name: Scalafmt Check
run: bleep fmt --check

- name: Run tests
env:
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
PGP_SECRET: ${{ secrets.PGP_SECRET }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
CI: true
run: |
bleep compile
bleep test

# publish:
# runs-on: ubuntu-latest
# needs: [ci]
# if: github.event_name == 'release'
# steps:
# - name: Checkout current branch
# uses: actions/checkout@v3
# - name: Set up JDK 17
# uses: actions/setup-java@v3
# with:
# java-version: '17'
# distribution: 'temurin'
# check-latest: true
# cache: 'sbt'
# - name: Release
# run: sbt ci-release
# env:
# PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
# PGP_SECRET: ${{ secrets.PGP_SECRET }}
# SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
# SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ test-reports/
.bsp/
.metals/
metals.sbt
.bleep/

.idea
.vscode
File renamed without changes.
File renamed without changes.
File renamed without changes.
145 changes: 145 additions & 0 deletions bleep.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
$schema: https://raw.githubusercontent.com/oyvindberg/bleep/master/schema.json
$version: 0.0.2
projects:
scripts:
dependencies: build.bleep::bleep-core:${BLEEP_VERSION}
platform:
name: jvm
scala:
version: 3.3.0
typed-json:
dependsOn:
- typed-json-formats
- typed-json-macros
extends:
- template-common-main
- template-cross-all
typed-json-formats:
dependencies: io.github.cquiroz::scala-java-time:2.5.0
dependsOn: typed-json-parser
extends:
- template-common-main
- template-cross-all
folder: ./formats
typed-json-formats-test:
cross:
js3:
dependencies: org.scala-js:scalajs-test-bridge_2.13:${PLATFORM_VERSION}
dependsOn: typed-json-formats
extends:
- template-common-test
- template-cross-all
folder: ./formats
typed-json-js-export:
dependsOn: typed-json
extends:
- template-common-main
- template-js
typed-json-macros:
dependencies: io.github.frawa::inline-files:0.1.2+43-09b6826f-SNAPSHOT
dependsOn: typed-json-parser-jawn
extends:
- template-common-main
- template-jvm
folder: ./macros
typed-json-macros-test:
dependsOn: typed-json-macros
extends:
- template-common-test
- template-jvm
folder: ./macros
typed-json-parser:
extends:
- template-common-main
- template-cross-all
folder: ./parser
typed-json-parser-jawn:
dependencies: org.typelevel::jawn-parser:1.5.0
dependsOn: typed-json-parser
extends:
- template-common-main
- template-cross-all
folder: ./parser-jawn
typed-json-parser-jawn-test:
cross:
js3:
dependencies: org.scala-js:scalajs-test-bridge_2.13:${PLATFORM_VERSION}
dependsOn: typed-json-parser-jawn
extends:
- template-common-test
- template-cross-all
folder: ./parser-jawn
typed-json-parser-test:
cross:
js3:
dependencies: org.scala-js:scalajs-test-bridge_2.13:${PLATFORM_VERSION}
dependsOn: typed-json-parser
extends:
- template-common-test
- template-cross-all
folder: ./parser
typed-json-parser-zio:
dependencies: dev.zio::zio-json:0.5.0
dependsOn: typed-json-parser
extends:
- template-common-main
- template-cross-all
folder: ./parser-zio
typed-json-parser-zio-test:
cross:
js3:
dependencies: org.scala-js:scalajs-test-bridge_2.13:${PLATFORM_VERSION}
dependsOn: typed-json-parser-zio
extends:
- template-common-test
- template-cross-all
folder: ./parser-zio
typed-json-test:
cross:
js3:
dependencies: org.scala-js:scalajs-test-bridge_2.13:${PLATFORM_VERSION}
dependsOn: typed-json
extends:
- template-common-test
- template-cross-all
folder: ./typed-json
resolvers: https://s01.oss.sonatype.org/content/repositories/releases
templates:
template-common:
java:
options: -J--add-exports -Jjdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
-Jjdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED -Jjdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
-Jjdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED -Jjdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
-build-tool:sbt -sourceroot:${BUILD_DIR} -targetroot:${TARGET_DIR}/meta
scala:
options: -Xmigration -deprecation -feature -indent -new-syntax -unchecked
-Xmacro-settings:INLINE_HOME=${PROJECT_DIR}/..
version: 3.3.0
template-common-main:
extends: template-common
sbt-scope: main
template-common-test:
dependencies: org.scalameta::munit:1.0.0-M8
extends: template-common
isTestProject: true
sbt-scope: test
testFrameworks: zio.test.sbt.ZTestFramework
template-cross-all:
cross:
js3:
extends: template-js
jvm3:
extends: template-jvm
source-layout: sbt-matrix
template-js:
platform:
jsEmitSourceMaps: false
jsJsdom: false
jsKind: none
jsMode: debug
jsNodeVersion: 18.4.0
jsVersion: 1.13.1
name: js
template-jvm:
platform:
name: jvm
22 changes: 18 additions & 4 deletions macros/src/main/scala/frawa/typedjson/macros/Macros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,26 @@ import frawa.inlinefiles.compiletime.FileContents

import frawa.typedjson.parser.Value
import JsonUtils.{given, *}
import scala.annotation.experimental
import java.nio.file.Path
import java.nio.file.Paths

@experimental
object Macros:
import frawa.inlinefiles.InlineFilesWithHome.resolveHome

inline def inlineJsonContents(path: String, ext: String): Map[String, Value] = ${
inlineJsonContents_impl('path, 'ext)
inline def inlineJsonContents(path: String, ext: String)(homeSetting: String): Map[String, Value] = ${
inlineJsonContents_impl('path, 'ext, 'homeSetting)
}

def inlineJsonContents_impl(path: Expr[String], ext: Expr[String])(using Quotes): Expr[Map[String, Value]] =
Expr(FileContents.parseTextContentsIn(path.valueOrAbort, ext.valueOrAbort, true)(parseJsonValue))
def inlineJsonContents_impl(path: Expr[String], ext: Expr[String], homeSetting: Expr[String])(using
Quotes
): Expr[Map[String, Value]] =
Expr(
FileContents.parseTextContentsIn(
path.valueOrAbort,
ext.valueOrAbort,
true,
Some(resolveHome(homeSetting.valueOrAbort))
)(parseJsonValue)
)
6 changes: 6 additions & 0 deletions typed-json/src/main/scala/frawa/typedjson/TypedJson.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import frawa.typedjson.suggest.Suggest
import frawa.typedjson.output.OutputOps
import frawa.typedjson.suggest.SuggestOutput
import frawa.typedjson.keywords.KeywordLocation
import scala.annotation.experimental

case class TypedJson(private val state: Option[(Keywords, CacheState)]):
import TypedJson.*
Expand Down Expand Up @@ -97,6 +98,7 @@ object TypedJson:

def create(): TypedJson = new TypedJson(None)

@experimental
def create(
schemaJson: String
)(using parser: Parser): Either[InputError, TypedJson] =
Expand All @@ -107,18 +109,22 @@ object TypedJson:
.swap
.flatMap(create(_))

@experimental
def create(schema: Value): Either[InputError, TypedJson] =
createWithSchema(SchemaValue.root(schema))

@experimental
def create(schema: Offset.Value): Either[InputError, TypedJson] =
createWithSchema(SchemaValue.root(Offset.withoutOffset(schema)))

@experimental
def createWithMetaSchemas(): TypedJson =
val lazyResolver = MetaSchemas.lazyResolver
val base = MetaSchemas.draft202012
val Some(schema) = lazyResolver(base.resolve("schema")): @unchecked
createWithSchema(schema).getOrElse(throw new IllegalStateException("broken meta schemas"))

@experimental
def createWithSchema(schema: SchemaValue): Either[InputError, TypedJson] =
val lazyResolver = MetaSchemas.lazyResolver
val vocabulary = Vocabulary.specDialect()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,23 @@ import frawa.typedjson.macros.Macros
import frawa.typedjson.util.UriUtil.uri

import java.net.URI
import scala.annotation.experimental

object MetaSchemas:

val draft202012: URI = uri("https://json-schema.org/draft/2020-12/")

@experimental
def lazyResolver: LoadedSchemasResolver.LazyResolver = { uri =>
if uri.getSchemeSpecificPart.startsWith(draft202012.getSchemeSpecificPart) then
resolve202012(draft202012.relativize(uri))
else None
}

@experimental
private def resolve202012(relative: URI): Option[RootSchemaValue] =
val name = relative.getSchemeSpecificPart
metaSchemas.get(name + ".json").map(SchemaValue.root(_))

private val metaSchemas = Macros.inlineJsonContents("./metaSchemas", ".json")
@experimental
private val metaSchemas = Macros.inlineJsonContents("./metaSchemas", ".json")("INLINE_HOME")
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ import frawa.typedjson.eval.CacheState
import frawa.typedjson.output.SimpleOutput
import frawa.typedjson.output.SimpleOutput.given
import frawa.typedjson.util.WithPointer
import scala.annotation.experimental

@experimental
class EvalResolveTest extends FunSuite:

import Util.*
Expand Down Expand Up @@ -143,6 +145,7 @@ class EvalResolveTest extends FunSuite:
}

test("$ref to validation spec, with two '$ref's") {
@experimental
val lazyResolver = Some(MetaSchemas.lazyResolver)
withCompiledSchema(refToValidationSpec, lazyResolver) { fun =>
assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ import java.net.URI
import frawa.typedjson.meta.MetaSchemas
import frawa.typedjson.jsonSchemaTestSuite.Remotes
import frawa.typedjson.keywords.Ignored
import scala.annotation.experimental

@experimental
class EvalSpecDetailsTest extends FunSuite:

import Util.*
Expand Down Expand Up @@ -382,6 +384,7 @@ class EvalSpecDetailsTest extends FunSuite:
}

test("Location-independent identifier in remote ref") {
@experimental
val lazyResolver = (uri: URI) => MetaSchemas.lazyResolver(uri).orElse(Remotes.lazyResolver(uri))
withCompiledSchema(
"""|{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@

package frawa.typedjson.jsonSchemaTestSuite

import frawa.inlinefiles.InlineFiles.*
import frawa.typedjson.parser.*
import frawa.typedjson.testutil.TestUtil.{*, given}
import scala.annotation.experimental

@experimental
class Draft202012OptionalFormatTest extends JsonSchemaTestSuite:
import frawa.inlinefiles.InlineFilesWithHome.*

private val draft202012OptionalFormatFiles = draft202012.folder("optional/format").files()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@

package frawa.typedjson.jsonSchemaTestSuite

import frawa.inlinefiles.InlineFiles.*
import frawa.typedjson.macros.Macros
import frawa.typedjson.testutil.TestUtil.{*, given}
import scala.annotation.experimental

@experimental
class Draft202012OptionalTest extends JsonSchemaTestSuite:
import frawa.inlinefiles.InlineFilesWithHome.*

private val draft202012OptionalFiles = draft202012.folder("optional").files()

// override protected val onlyDescription: Option[String] =
Expand Down
Loading