From 69f8ca01c5bcc4a6a756cf185ca726e9067c365a Mon Sep 17 00:00:00 2001 From: Jerre van Veluw Date: Fri, 17 Jan 2025 10:58:13 +0100 Subject: [PATCH] context dependency injection --- examples/gradle-ktor/build.gradle.kts | 3 +- kotlin-js-store/yarn.lock | 512 ++++++++++++++++++ .../flock/wirespec/compiler/core/Compiler.kt | 48 +- .../wirespec/compiler/core/LanguageSpec.kt | 4 + .../compiler/core/emit/JavaEmitter.kt | 3 +- .../compiler/core/emit/KotlinEmitter.kt | 3 +- .../compiler/core/emit/ScalaEmitter.kt | 19 +- .../compiler/core/emit/TypeScriptEmitter.kt | 11 +- .../compiler/core/emit/WirespecEmitter.kt | 16 +- .../compiler/core/emit/common/Emitter.kt | 4 + .../flock/wirespec/compiler/utils/Logger.kt | 4 + .../compiler/core/CompileChannelTest.kt | 10 +- .../wirespec/compiler/core/CompileEnumTest.kt | 10 +- .../compiler/core/CompileFullEndpointTest.kt | 10 +- .../core/CompileMinimalEndpointTest.kt | 10 +- .../compiler/core/CompileRefinedTest.kt | 10 +- .../wirespec/compiler/core/CompileTypeTest.kt | 10 +- .../compiler/core/CompileUnionTest.kt | 10 +- .../flock/wirespec/compiler/core/TestUtils.kt | 9 +- .../compiler/core/emit/JavaEmitterTest.kt | 7 +- .../compiler/core/emit/KotlinEmitterTest.kt | 7 +- .../compiler/core/parse/ParseChannelTest.kt | 6 +- .../compiler/core/parse/ParseEndpointTest.kt | 6 +- .../wirespec/compiler/core/parse/ParseTest.kt | 6 +- .../compiler/core/parse/ParseTypeTest.kt | 6 +- .../core/parse/ParserReferenceTest.kt | 6 +- .../flock/wirespec/compiler/lib/TestLib.kt | 9 +- .../wirespec/openapi/v2/OpenApiV2Emitter.kt | 4 +- .../openapi/convert/ConvertAndCompile.kt | 15 +- .../jackson/kotlin/GenerateTestClasses.kt | 11 +- .../spring/kotlin/emit/SpringKotlinEmitter.kt | 3 +- .../spring/kotlin/GenerateTestClasses.kt | 4 +- .../flock/wirespec/plugin/CompilerUtil.kt | 17 +- .../flock/wirespec/plugin/cli/Main.kt | 13 +- .../flock/wirespec/plugin/cli/Cli.kt | 11 +- .../flock/wirespec/plugin/npm/MainTest.kt | 8 +- .../flock/wirespec/plugin/npm/Main.kt | 28 +- .../flock/wirespec/generator/GeneratorTest.kt | 14 +- 38 files changed, 741 insertions(+), 146 deletions(-) create mode 100644 kotlin-js-store/yarn.lock diff --git a/examples/gradle-ktor/build.gradle.kts b/examples/gradle-ktor/build.gradle.kts index 9ffa5df44..587e1cc04 100644 --- a/examples/gradle-ktor/build.gradle.kts +++ b/examples/gradle-ktor/build.gradle.kts @@ -3,6 +3,7 @@ import community.flock.wirespec.compiler.core.emit.shared.KotlinShared import community.flock.wirespec.compiler.core.parse.AST import community.flock.wirespec.compiler.core.parse.Refined import community.flock.wirespec.compiler.core.parse.Type +import community.flock.wirespec.compiler.utils.noLogger import community.flock.wirespec.plugin.FileExtension import community.flock.wirespec.plugin.Language import community.flock.wirespec.plugin.gradle.CompileWirespecTask @@ -80,7 +81,7 @@ tasks.register("wirespec-typescript") { languages = listOf(Language.TypeScript) } -class KotlinSerializableEmitter : KotlinEmitter("community.flock.wirespec.generated.kotlin") { +class KotlinSerializableEmitter : KotlinEmitter("community.flock.wirespec.generated.kotlin", noLogger) { override fun emit(type: Type, ast: AST): String = """ |@kotlinx.serialization.Serializable diff --git a/kotlin-js-store/yarn.lock b/kotlin-js-store/yarn.lock new file mode 100644 index 000000000..90157442f --- /dev/null +++ b/kotlin-js-store/yarn.lock @@ -0,0 +1,512 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +ansi-colors@^4.1.3: + version "4.1.3" + resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.3.tgz#37611340eb2243e70cc604cad35d63270d48781b" + integrity sha512-/6w/C21Pm1A7aZitlI5Ni/2J6FFQN8i1Cvz3kHABAAbw93v/NlvKdVOqz7CCWz/3iv/JplRSEEZ83XION15ovw== + +ansi-regex@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304" + integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ== + +ansi-styles@^4.0.0, ansi-styles@^4.1.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-4.3.0.tgz#edd803628ae71c04c85ae7a0906edad34b648937" + integrity sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg== + dependencies: + color-convert "^2.0.1" + +anymatch@~3.1.2: + version "3.1.3" + resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-3.1.3.tgz#790c58b19ba1720a84205b57c618d5ad8524973e" + integrity sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw== + dependencies: + normalize-path "^3.0.0" + picomatch "^2.0.4" + +argparse@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38" + integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q== + +balanced-match@^1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee" + integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw== + +binary-extensions@^2.0.0: + version "2.3.0" + resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.3.0.tgz#f6e14a97858d327252200242d4ccfe522c445522" + integrity sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw== + +brace-expansion@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-2.0.1.tgz#1edc459e0f0c548486ecf9fc99f2221364b9a0ae" + integrity sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA== + dependencies: + balanced-match "^1.0.0" + +braces@~3.0.2: + version "3.0.3" + resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.3.tgz#490332f40919452272d55a8480adc0c441358789" + integrity sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA== + dependencies: + fill-range "^7.1.1" + +browser-stdout@^1.3.1: + version "1.3.1" + resolved "https://registry.yarnpkg.com/browser-stdout/-/browser-stdout-1.3.1.tgz#baa559ee14ced73452229bad7326467c61fabd60" + integrity sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw== + +buffer-from@^1.0.0: + version "1.1.2" + resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.2.tgz#2b146a6fd72e80b4f55d255f35ed59a3a9a41bd5" + integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ== + +camelcase@^6.0.0: + version "6.3.0" + resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.3.0.tgz#5685b95eb209ac9c0c177467778c9c84df58ba9a" + integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA== + +chalk@^4.1.0: + version "4.1.2" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01" + integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA== + dependencies: + ansi-styles "^4.1.0" + supports-color "^7.1.0" + +chokidar@^3.5.3: + version "3.6.0" + resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.6.0.tgz#197c6cc669ef2a8dc5e7b4d97ee4e092c3eb0d5b" + integrity sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw== + dependencies: + anymatch "~3.1.2" + braces "~3.0.2" + glob-parent "~5.1.2" + is-binary-path "~2.1.0" + is-glob "~4.0.1" + normalize-path "~3.0.0" + readdirp "~3.6.0" + optionalDependencies: + fsevents "~2.3.2" + +cliui@^7.0.2: + version "7.0.4" + resolved "https://registry.yarnpkg.com/cliui/-/cliui-7.0.4.tgz#a0265ee655476fc807aea9df3df8df7783808b4f" + integrity sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ== + dependencies: + string-width "^4.2.0" + strip-ansi "^6.0.0" + wrap-ansi "^7.0.0" + +color-convert@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-2.0.1.tgz#72d3a68d598c9bdb3af2ad1e84f21d896abd4de3" + integrity sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ== + dependencies: + color-name "~1.1.4" + +color-name@~1.1.4: + version "1.1.4" + resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" + integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== + +debug@^4.3.5: + version "4.4.0" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.4.0.tgz#2b3f2aea2ffeb776477460267377dc8710faba8a" + integrity sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA== + dependencies: + ms "^2.1.3" + +decamelize@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-4.0.0.tgz#aa472d7bf660eb15f3494efd531cab7f2a709837" + integrity sha512-9iE1PgSik9HeIIw2JO94IidnE3eBoQrFJ3w7sFuzSX4DpmZ3v5sZpUiV5Swcf6mQEF+Y0ru8Neo+p+nyh2J+hQ== + +diff@^5.2.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/diff/-/diff-5.2.0.tgz#26ded047cd1179b78b9537d5ef725503ce1ae531" + integrity sha512-uIFDxqpRZGZ6ThOk84hEfqWoHx2devRFvpTZcTHur85vImfaxUbTW9Ryh4CpCuDnToOP1CEtXKIgytHBPVff5A== + +emoji-regex@^8.0.0: + version "8.0.0" + resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37" + integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A== + +escalade@^3.1.1: + version "3.2.0" + resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.2.0.tgz#011a3f69856ba189dffa7dc8fcce99d2a87903e5" + integrity sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA== + +escape-string-regexp@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34" + integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA== + +fill-range@^7.1.1: + version "7.1.1" + resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.1.1.tgz#44265d3cac07e3ea7dc247516380643754a05292" + integrity sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg== + dependencies: + to-regex-range "^5.0.1" + +find-up@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/find-up/-/find-up-5.0.0.tgz#4c92819ecb7083561e4f4a240a86be5198f536fc" + integrity sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng== + dependencies: + locate-path "^6.0.0" + path-exists "^4.0.0" + +flat@^5.0.2: + version "5.0.2" + resolved "https://registry.yarnpkg.com/flat/-/flat-5.0.2.tgz#8ca6fe332069ffa9d324c327198c598259ceb241" + integrity sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ== + +format-util@^1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/format-util/-/format-util-1.0.5.tgz#1ffb450c8a03e7bccffe40643180918cc297d271" + integrity sha512-varLbTj0e0yVyRpqQhuWV+8hlePAgaoFRhNFj50BNjEIrw1/DphHSObtqwskVCPWNgzwPoQrZAbfa/SBiicNeg== + +fs.realpath@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" + integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw== + +fsevents@~2.3.2: + version "2.3.3" + resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.3.tgz#cac6407785d03675a2a5e1a5305c697b347d90d6" + integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw== + +get-caller-file@^2.0.5: + version "2.0.5" + resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e" + integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg== + +glob-parent@~5.1.2: + version "5.1.2" + resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.1.2.tgz#869832c58034fe68a4093c17dc15e8340d8401c4" + integrity sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow== + dependencies: + is-glob "^4.0.1" + +glob@^8.1.0: + version "8.1.0" + resolved "https://registry.yarnpkg.com/glob/-/glob-8.1.0.tgz#d388f656593ef708ee3e34640fdfb99a9fd1c33e" + integrity sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ== + dependencies: + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^5.0.1" + once "^1.3.0" + +has-flag@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b" + integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ== + +he@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f" + integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw== + +inflight@^1.0.4: + version "1.0.6" + resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" + integrity sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA== + dependencies: + once "^1.3.0" + wrappy "1" + +inherits@2: + version "2.0.4" + resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" + integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== + +is-binary-path@~2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/is-binary-path/-/is-binary-path-2.1.0.tgz#ea1f7f3b80f064236e83470f86c09c254fb45b09" + integrity sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw== + dependencies: + binary-extensions "^2.0.0" + +is-extglob@^2.1.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-2.1.1.tgz#a88c02535791f02ed37c76a1b9ea9773c833f8c2" + integrity sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ== + +is-fullwidth-code-point@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz#f116f8064fe90b3f7844a38997c0b75051269f1d" + integrity sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg== + +is-glob@^4.0.1, is-glob@~4.0.1: + version "4.0.3" + resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.3.tgz#64f61e42cbbb2eec2071a9dac0b28ba1e65d5084" + integrity sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg== + dependencies: + is-extglob "^2.1.1" + +is-number@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/is-number/-/is-number-7.0.0.tgz#7535345b896734d5f80c4d06c50955527a14f12b" + integrity sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng== + +is-plain-obj@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/is-plain-obj/-/is-plain-obj-2.1.0.tgz#45e42e37fccf1f40da8e5f76ee21515840c09287" + integrity sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA== + +is-unicode-supported@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz#3f26c76a809593b52bfa2ecb5710ed2779b522a7" + integrity sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw== + +js-yaml@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.1.0.tgz#c1fb65f8f5017901cdd2c951864ba18458a10602" + integrity sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA== + dependencies: + argparse "^2.0.1" + +locate-path@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-6.0.0.tgz#55321eb309febbc59c4801d931a72452a681d286" + integrity sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw== + dependencies: + p-locate "^5.0.0" + +log-symbols@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-4.1.0.tgz#3fbdbb95b4683ac9fc785111e792e558d4abd503" + integrity sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg== + dependencies: + chalk "^4.1.0" + is-unicode-supported "^0.1.0" + +minimatch@^5.0.1, minimatch@^5.1.6: + version "5.1.6" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-5.1.6.tgz#1cfcb8cf5522ea69952cd2af95ae09477f122a96" + integrity sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g== + dependencies: + brace-expansion "^2.0.1" + +mocha@10.7.0: + version "10.7.0" + resolved "https://registry.yarnpkg.com/mocha/-/mocha-10.7.0.tgz#9e5cbed8fa9b37537a25bd1f7fb4f6fc45458b9a" + integrity sha512-v8/rBWr2VO5YkspYINnvu81inSz2y3ODJrhO175/Exzor1RcEZZkizgE2A+w/CAXXoESS8Kys5E62dOHGHzULA== + dependencies: + ansi-colors "^4.1.3" + browser-stdout "^1.3.1" + chokidar "^3.5.3" + debug "^4.3.5" + diff "^5.2.0" + escape-string-regexp "^4.0.0" + find-up "^5.0.0" + glob "^8.1.0" + he "^1.2.0" + js-yaml "^4.1.0" + log-symbols "^4.1.0" + minimatch "^5.1.6" + ms "^2.1.3" + serialize-javascript "^6.0.2" + strip-json-comments "^3.1.1" + supports-color "^8.1.1" + workerpool "^6.5.1" + yargs "^16.2.0" + yargs-parser "^20.2.9" + yargs-unparser "^2.0.0" + +ms@^2.1.3: + version "2.1.3" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" + integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== + +normalize-path@^3.0.0, normalize-path@~3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65" + integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA== + +once@^1.3.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" + integrity sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w== + dependencies: + wrappy "1" + +p-limit@^3.0.2: + version "3.1.0" + resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-3.1.0.tgz#e1daccbe78d0d1388ca18c64fea38e3e57e3706b" + integrity sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ== + dependencies: + yocto-queue "^0.1.0" + +p-locate@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-5.0.0.tgz#83c8315c6785005e3bd021839411c9e110e6d834" + integrity sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw== + dependencies: + p-limit "^3.0.2" + +path-exists@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-4.0.0.tgz#513bdbe2d3b95d7762e8c1137efa195c6c61b5b3" + integrity sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w== + +picomatch@^2.0.4, picomatch@^2.2.1: + version "2.3.1" + resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42" + integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA== + +randombytes@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/randombytes/-/randombytes-2.1.0.tgz#df6f84372f0270dc65cdf6291349ab7a473d4f2a" + integrity sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ== + dependencies: + safe-buffer "^5.1.0" + +readdirp@~3.6.0: + version "3.6.0" + resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-3.6.0.tgz#74a370bd857116e245b29cc97340cd431a02a6c7" + integrity sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA== + dependencies: + picomatch "^2.2.1" + +require-directory@^2.1.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42" + integrity sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q== + +safe-buffer@^5.1.0: + version "5.2.1" + resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6" + integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ== + +serialize-javascript@^6.0.2: + version "6.0.2" + resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-6.0.2.tgz#defa1e055c83bf6d59ea805d8da862254eb6a6c2" + integrity sha512-Saa1xPByTTq2gdeFZYLLo+RFE35NHZkAbqZeWNd3BpzppeVisAqpDjcp8dyf6uIvEqJRd46jemmyA4iFIeVk8g== + dependencies: + randombytes "^2.1.0" + +source-map-support@0.5.21: + version "0.5.21" + resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.21.tgz#04fe7c7f9e1ed2d662233c28cb2b35b9f63f6e4f" + integrity sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w== + dependencies: + buffer-from "^1.0.0" + source-map "^0.6.0" + +source-map@^0.6.0: + version "0.6.1" + resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" + integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== + +string-width@^4.1.0, string-width@^4.2.0: + version "4.2.3" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" + integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== + dependencies: + emoji-regex "^8.0.0" + is-fullwidth-code-point "^3.0.0" + strip-ansi "^6.0.1" + +strip-ansi@^6.0.0, strip-ansi@^6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" + integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== + dependencies: + ansi-regex "^5.0.1" + +strip-json-comments@^3.1.1: + version "3.1.1" + resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.1.1.tgz#31f1281b3832630434831c310c01cccda8cbe006" + integrity sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig== + +supports-color@^7.1.0: + version "7.2.0" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.2.0.tgz#1b7dcdcb32b8138801b3e478ba6a51caa89648da" + integrity sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw== + dependencies: + has-flag "^4.0.0" + +supports-color@^8.1.1: + version "8.1.1" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-8.1.1.tgz#cd6fc17e28500cff56c1b86c0a7fd4a54a73005c" + integrity sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q== + dependencies: + has-flag "^4.0.0" + +to-regex-range@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/to-regex-range/-/to-regex-range-5.0.1.tgz#1648c44aae7c8d988a326018ed72f5b4dd0392e4" + integrity sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ== + dependencies: + is-number "^7.0.0" + +typescript@5.5.4: + version "5.5.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.5.4.tgz#d9852d6c82bad2d2eda4fd74a5762a8f5909e9ba" + integrity sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q== + +workerpool@^6.5.1: + version "6.5.1" + resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.5.1.tgz#060f73b39d0caf97c6db64da004cd01b4c099544" + integrity sha512-Fs4dNYcsdpYSAfVxhnl1L5zTksjvOJxtC5hzMNl+1t9B8hTJTdKDyZ5ju7ztgPy+ft9tBFXoOlDNiOT9WUXZlA== + +wrap-ansi@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" + integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== + dependencies: + ansi-styles "^4.0.0" + string-width "^4.1.0" + strip-ansi "^6.0.0" + +wrappy@1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" + integrity sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ== + +y18n@^5.0.5: + version "5.0.8" + resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.8.tgz#7f4934d0f7ca8c56f95314939ddcd2dd91ce1d55" + integrity sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA== + +yargs-parser@^20.2.2, yargs-parser@^20.2.9: + version "20.2.9" + resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.9.tgz#2eb7dc3b0289718fc295f362753845c41a0c94ee" + integrity sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w== + +yargs-unparser@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/yargs-unparser/-/yargs-unparser-2.0.0.tgz#f131f9226911ae5d9ad38c432fe809366c2325eb" + integrity sha512-7pRTIA9Qc1caZ0bZ6RYRGbHJthJWuakf+WmHK0rVeLkNrrGhfoabBNdue6kdINI6r4if7ocq9aD/n7xwKOdzOA== + dependencies: + camelcase "^6.0.0" + decamelize "^4.0.0" + flat "^5.0.2" + is-plain-obj "^2.1.0" + +yargs@^16.2.0: + version "16.2.0" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-16.2.0.tgz#1c82bf0f6b6a66eafce7ef30e376f49a12477f66" + integrity sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw== + dependencies: + cliui "^7.0.2" + escalade "^3.1.1" + get-caller-file "^2.0.5" + require-directory "^2.1.1" + string-width "^4.2.0" + y18n "^5.0.5" + yargs-parser "^20.2.2" + +yocto-queue@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b" + integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== diff --git a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/Compiler.kt b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/Compiler.kt index b2cfa0186..1e1f7f54d 100644 --- a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/Compiler.kt +++ b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/Compiler.kt @@ -3,42 +3,40 @@ package community.flock.wirespec.compiler.core import arrow.core.Either import arrow.core.Nel import arrow.core.NonEmptyList -import community.flock.wirespec.compiler.core.Reported.EMITTED -import community.flock.wirespec.compiler.core.Reported.PARSED -import community.flock.wirespec.compiler.core.Reported.TOKENIZED -import community.flock.wirespec.compiler.core.Reported.VALIDATED +import community.flock.wirespec.compiler.core.Stage.EMITTED +import community.flock.wirespec.compiler.core.Stage.PARSED +import community.flock.wirespec.compiler.core.Stage.TOKENIZED +import community.flock.wirespec.compiler.core.Stage.VALIDATED import community.flock.wirespec.compiler.core.emit.common.Emitted -import community.flock.wirespec.compiler.core.emit.common.Emitter +import community.flock.wirespec.compiler.core.emit.common.HasEmitter import community.flock.wirespec.compiler.core.exceptions.WirespecException import community.flock.wirespec.compiler.core.parse.AST import community.flock.wirespec.compiler.core.parse.Parser import community.flock.wirespec.compiler.core.tokenize.tokenize import community.flock.wirespec.compiler.core.validate.validate -import community.flock.wirespec.compiler.utils.Logger +import community.flock.wirespec.compiler.utils.HasLogger -fun LanguageSpec.parse(source: String): (Logger) -> Either, AST> = - { logger -> - tokenize(source) - .also((TOKENIZED::report)(logger)) - .let(Parser(logger)::parse) - .also((PARSED::report)(logger)) - .map { it.validate() } - .also((VALIDATED::report)(logger)) - } +interface CompilationContext : ParseContext, HasEmitter -fun LanguageSpec.compile(source: String): (Logger) -> (Emitter) -> Either, List> = - { logger -> - { emitter -> - parse(source)(logger) - .map(emitter::emit) - .also((EMITTED::report)(logger)) - } - } +fun CompilationContext.compile(source: String): Either, List> = + parse(source) + .map(emitter::emit) + .also(EMITTED::log) + +interface ParseContext : HasLanguageSpec, HasLogger + +fun ParseContext.parse(source: String): Either, AST> = + spec.tokenize(source) + .also(TOKENIZED::log) + .let(Parser(logger)::parse) + .also(PARSED::log) + .map { it.validate() } + .also(VALIDATED::log) -private enum class Reported { +private enum class Stage { TOKENIZED, PARSED, VALIDATED, EMITTED; - fun report(logger: Logger): (Any) -> Unit = { + fun log(it: Any): HasLogger.() -> Unit = { logger.info("********** $name **********\n$it\n########## $name ##########") } } diff --git a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/LanguageSpec.kt b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/LanguageSpec.kt index fbc10a4c0..c40751517 100644 --- a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/LanguageSpec.kt +++ b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/LanguageSpec.kt @@ -41,6 +41,10 @@ interface LanguageSpec { val orderedMatchers: List } +interface HasLanguageSpec { + val spec: LanguageSpec get() = WirespecSpec +} + object WirespecSpec : LanguageSpec { override val customType = WsCustomType override val orderedMatchers = listOf( diff --git a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/JavaEmitter.kt b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/JavaEmitter.kt index 928a2a842..5112935d8 100644 --- a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/JavaEmitter.kt +++ b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/JavaEmitter.kt @@ -23,11 +23,10 @@ import community.flock.wirespec.compiler.core.parse.Refined import community.flock.wirespec.compiler.core.parse.Type import community.flock.wirespec.compiler.core.parse.Union import community.flock.wirespec.compiler.utils.Logger -import community.flock.wirespec.compiler.utils.noLogger open class JavaEmitter( val packageName: String = DEFAULT_GENERATED_PACKAGE_STRING, - logger: Logger = noLogger, + logger: Logger, ) : DefinitionModelEmitter, Emitter(logger, true) { open val import = """ diff --git a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/KotlinEmitter.kt b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/KotlinEmitter.kt index f5b8e59e8..9b10a5ba7 100644 --- a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/KotlinEmitter.kt +++ b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/KotlinEmitter.kt @@ -24,11 +24,10 @@ import community.flock.wirespec.compiler.core.parse.Refined import community.flock.wirespec.compiler.core.parse.Type import community.flock.wirespec.compiler.core.parse.Union import community.flock.wirespec.compiler.utils.Logger -import community.flock.wirespec.compiler.utils.noLogger open class KotlinEmitter( private val packageName: String = DEFAULT_GENERATED_PACKAGE_STRING, - logger: Logger = noLogger, + logger: Logger, ) : DefinitionModelEmitter, Emitter(logger, false) { open val import = """ diff --git a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/ScalaEmitter.kt b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/ScalaEmitter.kt index 88d694ca9..5e59dbd21 100644 --- a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/ScalaEmitter.kt +++ b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/ScalaEmitter.kt @@ -20,11 +20,10 @@ import community.flock.wirespec.compiler.core.parse.Refined import community.flock.wirespec.compiler.core.parse.Type import community.flock.wirespec.compiler.core.parse.Union import community.flock.wirespec.compiler.utils.Logger -import community.flock.wirespec.compiler.utils.noLogger open class ScalaEmitter( private val packageName: String = DEFAULT_GENERATED_PACKAGE_STRING, - logger: Logger = noLogger + logger: Logger, ) : DefinitionModelEmitter, Emitter(logger) { open val import = """ @@ -79,14 +78,16 @@ open class ScalaEmitter( is Reference.Custom -> value is Reference.Primitive -> when (type) { is Reference.Primitive.Type.String -> "String" - is Reference.Primitive.Type.Integer -> when(type.precision){ + is Reference.Primitive.Type.Integer -> when (type.precision) { Reference.Primitive.Type.Precision.P32 -> "Int" Reference.Primitive.Type.Precision.P64 -> "Long" } - is Reference.Primitive.Type.Number -> when(type.precision){ + + is Reference.Primitive.Type.Number -> when (type.precision) { Reference.Primitive.Type.Precision.P32 -> "Float" Reference.Primitive.Type.Precision.P64 -> "Double" } + is Reference.Primitive.Type.Boolean -> "Boolean" is Reference.Primitive.Type.Bytes -> "Array[Byte]" } @@ -99,7 +100,15 @@ open class ScalaEmitter( """ |sealed abstract class ${emitName()}(val label: String) |object ${emit(identifier)} { - |${entries.joinToString("\n") { """${Spacer}final case object ${it.sanitize().uppercase()} extends ${emit(identifier)}(label = "$it")""" }} + |${ + entries.joinToString("\n") { + """${Spacer}final case object ${it.sanitize().uppercase()} extends ${ + emit( + identifier + ) + }(label = "$it")""" + } + } |} |""".trimMargin() } diff --git a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/TypeScriptEmitter.kt b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/TypeScriptEmitter.kt index 25ef440b8..a7b97a1b5 100644 --- a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/TypeScriptEmitter.kt +++ b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/TypeScriptEmitter.kt @@ -17,9 +17,8 @@ import community.flock.wirespec.compiler.core.parse.Refined import community.flock.wirespec.compiler.core.parse.Type import community.flock.wirespec.compiler.core.parse.Union import community.flock.wirespec.compiler.utils.Logger -import community.flock.wirespec.compiler.utils.noLogger -open class TypeScriptEmitter(logger: Logger = noLogger) : DefinitionModelEmitter, Emitter(logger) { +open class TypeScriptEmitter(logger: Logger) : DefinitionModelEmitter, Emitter(logger) { override fun Definition.emitName(): String = when (this) { is Endpoint -> emit(identifier) @@ -149,7 +148,9 @@ open class TypeScriptEmitter(logger: Logger = noLogger) : DefinitionModelEmitter """.trimIndent() private fun Endpoint.Request.emitFunction(endpoint: Endpoint) = """ - |${Spacer}export const request = (${paramList(endpoint).takeIf { it.isNotEmpty() }?.let { "props: ${it.joinToObject { it.emit() }}" }.orEmpty()}): Request => ({ + |${Spacer}export const request = (${ + paramList(endpoint).takeIf { it.isNotEmpty() }?.let { "props: ${it.joinToObject { it.emit() }}" }.orEmpty() + }): Request => ({ |${Spacer(2)}path: ${endpoint.pathParams.joinToObject { "${emit(it.identifier)}: props.${emit(it.identifier)}" }}, |${Spacer(2)}method: "${endpoint.method}", |${Spacer(2)}queries: ${endpoint.queries.joinToObject { "${emit(it.identifier)}: props.${emit(it.identifier)}" }}, @@ -159,7 +160,9 @@ open class TypeScriptEmitter(logger: Logger = noLogger) : DefinitionModelEmitter """.trimIndent() private fun Endpoint.Response.emitFunction(endpoint: Endpoint) = """ - |${Spacer}export const response${status.firstToUpper()} = (${paramList().takeIf { it.isNotEmpty() }?.let { "props: ${it.joinToObject { it.emit() }}" }.orEmpty()}): Response${status.firstToUpper()} => ({ + |${Spacer}export const response${status.firstToUpper()} = (${ + paramList().takeIf { it.isNotEmpty() }?.let { "props: ${it.joinToObject { it.emit() }}" }.orEmpty() + }): Response${status.firstToUpper()} => ({ |${Spacer(2)}status: ${status}, |${Spacer(2)}headers: ${endpoint.headers.joinToObject { "${emit(it.identifier)}: props.${emit(it.identifier)}" }}, |${Spacer(2)}body: ${content?.let { "props.body" } ?: "undefined"}, diff --git a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/WirespecEmitter.kt b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/WirespecEmitter.kt index 2e6c5b8c9..4c9979e8c 100644 --- a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/WirespecEmitter.kt +++ b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/WirespecEmitter.kt @@ -19,9 +19,8 @@ import community.flock.wirespec.compiler.core.parse.Refined import community.flock.wirespec.compiler.core.parse.Type import community.flock.wirespec.compiler.core.parse.Union import community.flock.wirespec.compiler.utils.Logger -import community.flock.wirespec.compiler.utils.noLogger -open class WirespecEmitter(logger: Logger = noLogger) : DefinitionModelEmitter, Emitter(logger) { +open class WirespecEmitter(logger: Logger) : DefinitionModelEmitter, Emitter(logger) { override fun Definition.emitName(): String = when (this) { is Endpoint -> emit(identifier) @@ -46,9 +45,11 @@ open class WirespecEmitter(logger: Logger = noLogger) : DefinitionModelEmitter, override fun Field.emit() = "${emit(identifier)}: ${reference.emit()}${if (isNullable) "?" else ""}" - override fun emit(identifier: Identifier) = when(identifier){ - is DefinitionIdentifier -> identifier.run { if (value in reservedKeywords) value.addBackticks() else value } - is FieldIdentifier -> identifier.run { if (value in reservedKeywords || value.first().isUpperCase()) value.addBackticks() else value } + override fun emit(identifier: Identifier) = when (identifier) { + is DefinitionIdentifier -> identifier.run { if (value in reservedKeywords) value.addBackticks() else value } + is FieldIdentifier -> identifier.run { + if (value in reservedKeywords || value.first().isUpperCase()) value.addBackticks() else value + } } override fun emit(channel: Channel): String = @@ -62,11 +63,12 @@ open class WirespecEmitter(logger: Logger = noLogger) : DefinitionModelEmitter, is Reference.Primitive.Type.String -> "String" is Reference.Primitive.Type.Boolean -> "Boolean" is Reference.Primitive.Type.Bytes -> "Bytes" - is Reference.Primitive.Type.Integer -> when(type.precision){ + is Reference.Primitive.Type.Integer -> when (type.precision) { Reference.Primitive.Type.Precision.P32 -> "Integer32" Reference.Primitive.Type.Precision.P64 -> "Integer" } - is Reference.Primitive.Type.Number -> when(type.precision){ + + is Reference.Primitive.Type.Number -> when (type.precision) { Reference.Primitive.Type.Precision.P32 -> "Number32" Reference.Primitive.Type.Precision.P64 -> "Number" } diff --git a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/common/Emitter.kt b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/common/Emitter.kt index 3d37b63d9..c9be569a4 100644 --- a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/common/Emitter.kt +++ b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/common/Emitter.kt @@ -125,3 +125,7 @@ abstract class Emitter( ) } } + +interface HasEmitter { + val emitter: Emitter +} diff --git a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/utils/Logger.kt b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/utils/Logger.kt index 40878fae9..7ae73b279 100644 --- a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/utils/Logger.kt +++ b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/utils/Logger.kt @@ -43,4 +43,8 @@ open class Logger(logLevel: Level?) { } } +interface HasLogger { + val logger: Logger +} + val noLogger = object : Logger(logLevel = null) {} diff --git a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/CompileChannelTest.kt b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/CompileChannelTest.kt index 052c4a4c1..e5e7c90a3 100644 --- a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/CompileChannelTest.kt +++ b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/CompileChannelTest.kt @@ -25,7 +25,7 @@ class CompileChannelTest { | """.trimMargin() - compiler(KotlinEmitter()) shouldBeRight kotlin + compiler { KotlinEmitter(logger = it) } shouldBeRight kotlin } @Test @@ -39,7 +39,7 @@ class CompileChannelTest { | """.trimMargin() - compiler(JavaEmitter()) shouldBeRight java + compiler { JavaEmitter(logger = it) } shouldBeRight java } @Test @@ -51,7 +51,7 @@ class CompileChannelTest { | """.trimMargin() - compiler(ScalaEmitter()) shouldBeRight scala + compiler { ScalaEmitter(logger = it) } shouldBeRight scala } @Test @@ -61,7 +61,7 @@ class CompileChannelTest { | """.trimMargin() - compiler(TypeScriptEmitter()) shouldBeRight ts + compiler { TypeScriptEmitter(logger = it) } shouldBeRight ts } @Test @@ -70,6 +70,6 @@ class CompileChannelTest { |channel Queue -> String """.trimMargin() - compiler(WirespecEmitter()) shouldBeRight wirespec + compiler { WirespecEmitter(logger = it) } shouldBeRight wirespec } } diff --git a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/CompileEnumTest.kt b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/CompileEnumTest.kt index 2683d5e7f..3c2b98ba8 100644 --- a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/CompileEnumTest.kt +++ b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/CompileEnumTest.kt @@ -36,7 +36,7 @@ class CompileEnumTest { | """.trimMargin() - compiler(KotlinEmitter()) shouldBeRight kotlin + compiler { KotlinEmitter(logger = it) } shouldBeRight kotlin } @Test @@ -67,7 +67,7 @@ class CompileEnumTest { | """.trimMargin() - compiler(JavaEmitter()) shouldBeRight java + compiler { JavaEmitter(logger = it) } shouldBeRight java } @Test @@ -87,7 +87,7 @@ class CompileEnumTest { | """.trimMargin() - compiler(ScalaEmitter()) shouldBeRight scala + compiler { ScalaEmitter(logger = it) } shouldBeRight scala } @Test @@ -97,7 +97,7 @@ class CompileEnumTest { | """.trimMargin() - compiler(TypeScriptEmitter()) shouldBeRight ts + compiler { TypeScriptEmitter(logger = it) } shouldBeRight ts } @Test @@ -109,6 +109,6 @@ class CompileEnumTest { | """.trimMargin() - compiler(WirespecEmitter()) shouldBeRight wirespec + compiler { WirespecEmitter(logger = it) } shouldBeRight wirespec } } diff --git a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/CompileFullEndpointTest.kt b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/CompileFullEndpointTest.kt index ed217564d..37630cc47 100644 --- a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/CompileFullEndpointTest.kt +++ b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/CompileFullEndpointTest.kt @@ -169,7 +169,7 @@ class CompileFullEndpointTest { | """.trimMargin() - compiler(KotlinEmitter()) shouldBeRight kotlin + compiler { KotlinEmitter(logger = it) } shouldBeRight kotlin } @Test @@ -292,7 +292,7 @@ class CompileFullEndpointTest { | """.trimMargin() - compiler(JavaEmitter()) shouldBeRight java + compiler { JavaEmitter(logger = it) } shouldBeRight java } @Test @@ -326,7 +326,7 @@ class CompileFullEndpointTest { | """.trimMargin() - compiler(ScalaEmitter()) shouldBeRight scala + compiler { ScalaEmitter(logger = it) } shouldBeRight scala } @Test @@ -476,7 +476,7 @@ class CompileFullEndpointTest { | """.trimMargin() - compiler(TypeScriptEmitter()) shouldBeRight ts + compiler { TypeScriptEmitter(logger = it) } shouldBeRight ts } @Test @@ -509,6 +509,6 @@ class CompileFullEndpointTest { | """.trimMargin() - compiler(WirespecEmitter()) shouldBeRight wirespec + compiler { WirespecEmitter(logger = it) } shouldBeRight wirespec } } diff --git a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/CompileMinimalEndpointTest.kt b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/CompileMinimalEndpointTest.kt index 181645881..262337150 100644 --- a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/CompileMinimalEndpointTest.kt +++ b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/CompileMinimalEndpointTest.kt @@ -106,7 +106,7 @@ class CompileMinimalEndpointTest { | """.trimMargin() - compiler(KotlinEmitter()) shouldBeRight kotlin + compiler { KotlinEmitter(logger = it) } shouldBeRight kotlin } @Test @@ -206,7 +206,7 @@ class CompileMinimalEndpointTest { | """.trimMargin() - compiler(JavaEmitter()) shouldBeRight java + compiler { JavaEmitter(logger = it) } shouldBeRight java } @Test @@ -224,7 +224,7 @@ class CompileMinimalEndpointTest { | """.trimMargin() - compiler(ScalaEmitter()) shouldBeRight scala + compiler { ScalaEmitter(logger = it) } shouldBeRight scala } @Test @@ -333,7 +333,7 @@ class CompileMinimalEndpointTest { | """.trimMargin() - compiler(TypeScriptEmitter()) shouldBeRight ts + compiler { TypeScriptEmitter(logger = it) } shouldBeRight ts } @Test @@ -349,6 +349,6 @@ class CompileMinimalEndpointTest { | """.trimMargin() - compiler(WirespecEmitter()) shouldBeRight wirespec + compiler { WirespecEmitter(logger = it) } shouldBeRight wirespec } } diff --git a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/CompileRefinedTest.kt b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/CompileRefinedTest.kt index d61972f95..46e899c79 100644 --- a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/CompileRefinedTest.kt +++ b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/CompileRefinedTest.kt @@ -30,7 +30,7 @@ class CompileRefinedTest { | """.trimMargin() - compiler(KotlinEmitter()) shouldBeRight kotlin + compiler { KotlinEmitter(logger = it) } shouldBeRight kotlin } @Test @@ -52,7 +52,7 @@ class CompileRefinedTest { | """.trimMargin() - compiler(JavaEmitter()) shouldBeRight java + compiler { JavaEmitter(logger = it) } shouldBeRight java } @Test @@ -71,7 +71,7 @@ class CompileRefinedTest { | """.trimMargin() - compiler(ScalaEmitter()) shouldBeRight scala + compiler { ScalaEmitter(logger = it) } shouldBeRight scala } @Test @@ -84,7 +84,7 @@ class CompileRefinedTest { | """.trimMargin() - compiler(TypeScriptEmitter()) shouldBeRight ts + compiler { TypeScriptEmitter(logger = it) } shouldBeRight ts } @Test @@ -94,6 +94,6 @@ class CompileRefinedTest { | """.trimMargin() - compiler(WirespecEmitter()) shouldBeRight wirespec + compiler { WirespecEmitter(logger = it) } shouldBeRight wirespec } } diff --git a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/CompileTypeTest.kt b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/CompileTypeTest.kt index 01473de9a..96cfdb950 100644 --- a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/CompileTypeTest.kt +++ b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/CompileTypeTest.kt @@ -35,7 +35,7 @@ class CompileTypeTest { | """.trimMargin() - compiler(KotlinEmitter()) shouldBeRight kotlin + compiler { KotlinEmitter(logger = it) } shouldBeRight kotlin } @Test @@ -54,7 +54,7 @@ class CompileTypeTest { | """.trimMargin() - compiler(JavaEmitter()) shouldBeRight java + compiler { JavaEmitter(logger = it) } shouldBeRight java } @Test @@ -72,7 +72,7 @@ class CompileTypeTest { | """.trimMargin() - compiler(ScalaEmitter()) shouldBeRight scala + compiler { ScalaEmitter(logger = it) } shouldBeRight scala } @Test @@ -89,7 +89,7 @@ class CompileTypeTest { | """.trimMargin() - compiler(TypeScriptEmitter()) shouldBeRight ts + compiler { TypeScriptEmitter(logger = it) } shouldBeRight ts } @Test @@ -105,6 +105,6 @@ class CompileTypeTest { | """.trimMargin() - compiler(WirespecEmitter()) shouldBeRight wirespec + compiler { WirespecEmitter(logger = it) } shouldBeRight wirespec } } diff --git a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/CompileUnionTest.kt b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/CompileUnionTest.kt index 70d73eca2..fbb04a453 100644 --- a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/CompileUnionTest.kt +++ b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/CompileUnionTest.kt @@ -48,7 +48,7 @@ class CompileUnionTest { | """.trimMargin() - compiler(KotlinEmitter()) shouldBeRight expected + compiler { KotlinEmitter(logger = it) } shouldBeRight expected } @Test @@ -60,7 +60,7 @@ class CompileUnionTest { | """.trimMargin() - compiler(JavaEmitter()) shouldBeRight java + compiler { JavaEmitter(logger = it) } shouldBeRight java } @Test @@ -86,7 +86,7 @@ class CompileUnionTest { | """.trimMargin() - compiler(ScalaEmitter()) shouldBeRight scala + compiler { ScalaEmitter(logger = it) } shouldBeRight scala } @Test @@ -113,7 +113,7 @@ class CompileUnionTest { | """.trimMargin() - compiler(TypeScriptEmitter()) shouldBeRight ts + compiler { TypeScriptEmitter(logger = it) } shouldBeRight ts } @Test @@ -137,6 +137,6 @@ class CompileUnionTest { | """.trimMargin() - compiler(WirespecEmitter()) shouldBeRight wirespec + compiler { WirespecEmitter(logger = it) } shouldBeRight wirespec } } diff --git a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/TestUtils.kt b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/TestUtils.kt index 154ee3ded..58186f70b 100644 --- a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/TestUtils.kt +++ b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/TestUtils.kt @@ -1,10 +1,15 @@ package community.flock.wirespec.compiler.core import community.flock.wirespec.compiler.core.emit.common.Emitter +import community.flock.wirespec.compiler.utils.Logger import community.flock.wirespec.compiler.utils.noLogger -fun compile(source: String) = { emitter: Emitter -> - WirespecSpec.compile(source)(noLogger)(emitter) +fun compile(source: String) = { emitter: (Logger) -> Emitter -> + object : CompilationContext { + override val spec = WirespecSpec + override val logger = noLogger + override val emitter = emitter(logger) + }.compile(source) .map { it.first().result } .onLeft(::println) } diff --git a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/emit/JavaEmitterTest.kt b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/emit/JavaEmitterTest.kt index 13889b3b7..099d6760d 100644 --- a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/emit/JavaEmitterTest.kt +++ b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/emit/JavaEmitterTest.kt @@ -1,14 +1,19 @@ package community.flock.wirespec.compiler.core.emit +import community.flock.wirespec.compiler.core.CompilationContext import community.flock.wirespec.compiler.core.emit.common.Emitter import community.flock.wirespec.compiler.core.fixture.NodeFixtures import community.flock.wirespec.compiler.core.parse.Node +import community.flock.wirespec.compiler.utils.noLogger import io.kotest.matchers.shouldBe import kotlin.test.Test class JavaEmitterTest { - private val emitter = JavaEmitter() + private val emitter = object : CompilationContext { + override val logger = noLogger + override val emitter = JavaEmitter(logger = logger) + }.emitter @Test fun testEmitterType() { diff --git a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/emit/KotlinEmitterTest.kt b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/emit/KotlinEmitterTest.kt index 4f722264d..4dd336630 100644 --- a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/emit/KotlinEmitterTest.kt +++ b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/emit/KotlinEmitterTest.kt @@ -1,14 +1,19 @@ package community.flock.wirespec.compiler.core.emit +import community.flock.wirespec.compiler.core.CompilationContext import community.flock.wirespec.compiler.core.emit.common.Emitter import community.flock.wirespec.compiler.core.fixture.NodeFixtures import community.flock.wirespec.compiler.core.parse.Node +import community.flock.wirespec.compiler.utils.noLogger import io.kotest.matchers.shouldBe import kotlin.test.Test class KotlinEmitterTest { - private val emitter = KotlinEmitter() + private val emitter = object : CompilationContext { + override val logger = noLogger + override val emitter = KotlinEmitter(logger = logger) + }.emitter @Test fun testEmitterType() { diff --git a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/parse/ParseChannelTest.kt b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/parse/ParseChannelTest.kt index 3296afdb6..b9c9df909 100644 --- a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/parse/ParseChannelTest.kt +++ b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/parse/ParseChannelTest.kt @@ -1,5 +1,6 @@ package community.flock.wirespec.compiler.core.parse +import community.flock.wirespec.compiler.core.ParseContext import community.flock.wirespec.compiler.core.WirespecSpec import community.flock.wirespec.compiler.core.parse import community.flock.wirespec.compiler.utils.noLogger @@ -10,7 +11,10 @@ import kotlin.test.Test class ParseChannelTest { - private fun parser(source: String) = WirespecSpec.parse(source)(noLogger) + private fun parser(source: String) = object : ParseContext { + override val spec = WirespecSpec + override val logger = noLogger + }.parse(source) @Test fun testChannelParser() { diff --git a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/parse/ParseEndpointTest.kt b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/parse/ParseEndpointTest.kt index 2b263867d..e09528800 100644 --- a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/parse/ParseEndpointTest.kt +++ b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/parse/ParseEndpointTest.kt @@ -1,5 +1,6 @@ package community.flock.wirespec.compiler.core.parse +import community.flock.wirespec.compiler.core.ParseContext import community.flock.wirespec.compiler.core.WirespecSpec import community.flock.wirespec.compiler.core.parse import community.flock.wirespec.compiler.core.parse.Endpoint.Method.GET @@ -16,7 +17,10 @@ import kotlin.test.Test class ParseEndpointTest { - private fun parser(source: String) = WirespecSpec.parse(source)(noLogger) + private fun parser(source: String) = object : ParseContext { + override val spec = WirespecSpec + override val logger = noLogger + }.parse(source) @Test fun testEndpointParser() { diff --git a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/parse/ParseTest.kt b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/parse/ParseTest.kt index b4c4d05f4..63d93754d 100644 --- a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/parse/ParseTest.kt +++ b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/parse/ParseTest.kt @@ -1,5 +1,6 @@ package community.flock.wirespec.compiler.core.parse +import community.flock.wirespec.compiler.core.ParseContext import community.flock.wirespec.compiler.core.WirespecSpec import community.flock.wirespec.compiler.core.parse import community.flock.wirespec.compiler.utils.noLogger @@ -10,7 +11,10 @@ import kotlin.test.Test class ParseTest { - private fun parser(source: String) = WirespecSpec.parse(source)(noLogger) + private fun parser(source: String) = object : ParseContext { + override val spec = WirespecSpec + override val logger = noLogger + }.parse(source) @Test fun testParserWithCorrectInput() { diff --git a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/parse/ParseTypeTest.kt b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/parse/ParseTypeTest.kt index f311509d0..0d68f4921 100644 --- a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/parse/ParseTypeTest.kt +++ b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/parse/ParseTypeTest.kt @@ -1,5 +1,6 @@ package community.flock.wirespec.compiler.core.parse +import community.flock.wirespec.compiler.core.ParseContext import community.flock.wirespec.compiler.core.WirespecSpec import community.flock.wirespec.compiler.core.parse import community.flock.wirespec.compiler.utils.noLogger @@ -10,7 +11,10 @@ import kotlin.test.Test class ParseTypeTest { - private fun parser(source: String) = WirespecSpec.parse(source)(noLogger) + private fun parser(source: String) = object : ParseContext { + override val spec = WirespecSpec + override val logger = noLogger + }.parse(source) @Test fun testTypeParser() { diff --git a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/parse/ParserReferenceTest.kt b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/parse/ParserReferenceTest.kt index 1b88bf435..a23f7e169 100644 --- a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/parse/ParserReferenceTest.kt +++ b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/parse/ParserReferenceTest.kt @@ -1,5 +1,6 @@ package community.flock.wirespec.compiler.core.parse +import community.flock.wirespec.compiler.core.ParseContext import community.flock.wirespec.compiler.core.WirespecSpec import community.flock.wirespec.compiler.core.parse import community.flock.wirespec.compiler.utils.noLogger @@ -10,7 +11,10 @@ import kotlin.test.Test class ParserReferenceTest { - private fun parser(source: String) = WirespecSpec.parse(source)(noLogger) + private fun parser(source: String) = object : ParseContext { + override val spec = WirespecSpec + override val logger = noLogger + }.parse(source) @Test fun shouldHaveSelfRef() { diff --git a/src/compiler/lib/src/jsTest/kotlin/community/flock/wirespec/compiler/lib/TestLib.kt b/src/compiler/lib/src/jsTest/kotlin/community/flock/wirespec/compiler/lib/TestLib.kt index 170e0200a..9f09cfa6b 100644 --- a/src/compiler/lib/src/jsTest/kotlin/community/flock/wirespec/compiler/lib/TestLib.kt +++ b/src/compiler/lib/src/jsTest/kotlin/community/flock/wirespec/compiler/lib/TestLib.kt @@ -1,6 +1,7 @@ package community.flock.wirespec.compiler.lib import com.goncalossilva.resources.Resource +import community.flock.wirespec.compiler.core.ParseContext import community.flock.wirespec.compiler.core.WirespecSpec import community.flock.wirespec.compiler.core.parse import community.flock.wirespec.compiler.utils.noLogger @@ -10,11 +11,13 @@ import kotlin.test.assertEquals class TestLib { @Test - fun testProduceConsume(){ + fun testProduceConsume() { val source = Resource("src/jsTest/resources/person.ws").readText() println(source) - val res = WirespecSpec.parse(source)(noLogger) - res.map { ast -> + object : ParseContext { + override val spec = WirespecSpec + override val logger = noLogger + }.parse(source).map { ast -> val output = ast.produce() val input = output.map { it.consume() } assertEquals(input, ast) diff --git a/src/converter/openapi/src/commonMain/kotlin/community/flock/wirespec/openapi/v2/OpenApiV2Emitter.kt b/src/converter/openapi/src/commonMain/kotlin/community/flock/wirespec/openapi/v2/OpenApiV2Emitter.kt index 26959cd1b..21bddab9f 100644 --- a/src/converter/openapi/src/commonMain/kotlin/community/flock/wirespec/openapi/v2/OpenApiV2Emitter.kt +++ b/src/converter/openapi/src/commonMain/kotlin/community/flock/wirespec/openapi/v2/OpenApiV2Emitter.kt @@ -32,7 +32,7 @@ import kotlinx.serialization.encodeToString import kotlinx.serialization.json.JsonPrimitive import community.flock.kotlinx.openapi.bindings.v2.Type as OpenApiType -object OpenApiV2Emitter: Emitter(noLogger) { +object OpenApiV2Emitter : Emitter(noLogger) { override val singleLineComment = "" @@ -184,7 +184,7 @@ object OpenApiV2Emitter: Emitter(noLogger) { fun Reference.emit(): SchemaOrReferenceObject = when (this) { is Reference.Custom -> ReferenceObject(ref = Ref("#/definitions/${value}")) - is Reference.Primitive ->SchemaObject(type = type.emitType(), format = emitFormat()) + is Reference.Primitive -> SchemaObject(type = type.emitType(), format = emitFormat()) is Reference.Any -> error("Cannot map Any") is Reference.Unit -> error("Cannot map Unit") }.let { if (isIterable) SchemaObject(type = OpenApiType.ARRAY, items = it) else it } diff --git a/src/converter/openapi/src/commonTest/kotlin/community/flock/wirespec/openapi/convert/ConvertAndCompile.kt b/src/converter/openapi/src/commonTest/kotlin/community/flock/wirespec/openapi/convert/ConvertAndCompile.kt index 05129c6dd..1a9d5ec8b 100644 --- a/src/converter/openapi/src/commonTest/kotlin/community/flock/wirespec/openapi/convert/ConvertAndCompile.kt +++ b/src/converter/openapi/src/commonTest/kotlin/community/flock/wirespec/openapi/convert/ConvertAndCompile.kt @@ -1,7 +1,7 @@ package community.flock.wirespec.openapi.convert import com.goncalossilva.resources.Resource -import community.flock.wirespec.compiler.core.WirespecSpec +import community.flock.wirespec.compiler.core.CompilationContext import community.flock.wirespec.compiler.core.compile import community.flock.wirespec.compiler.core.emit.KotlinEmitter import community.flock.wirespec.compiler.core.emit.WirespecEmitter @@ -17,15 +17,20 @@ class ConvertAndCompile { fun testV2ConversionAndCompilation() { val input = Resource("src/commonTest/resources/v2/petstore.json").readText() val ast = OpenApiV2Parser.parse(input, true) - val wirespec = WirespecEmitter().emit(ast).joinToString("\n") { it.result } - WirespecSpec.compile(wirespec)(noLogger)(KotlinEmitter()).shouldBeRight() + val wirespec = WirespecEmitter(noLogger).emit(ast).joinToString("\n") { it.result } + compiler(wirespec).shouldBeRight() } @Test fun testV3ConversionAndCompilation() { val input = Resource("src/commonTest/resources/v3/petstore.json").readText() val ast = OpenApiV3Parser.parse(input, true) - val wirespec = WirespecEmitter().emit(ast).joinToString("\n") { it.result } - WirespecSpec.compile(wirespec)(noLogger)(KotlinEmitter()).shouldBeRight() + val wirespec = WirespecEmitter(noLogger).emit(ast).joinToString("\n") { it.result } + compiler(wirespec).shouldBeRight() } + + private fun compiler(source: String) = object : CompilationContext { + override val logger = noLogger + override val emitter = KotlinEmitter(logger = logger) + }.compile(source) } diff --git a/src/integration/jackson/src/jvmTest/kotlin/community/flock/wirespec/integration/jackson/kotlin/GenerateTestClasses.kt b/src/integration/jackson/src/jvmTest/kotlin/community/flock/wirespec/integration/jackson/kotlin/GenerateTestClasses.kt index ea63bd775..26719aa7b 100644 --- a/src/integration/jackson/src/jvmTest/kotlin/community/flock/wirespec/integration/jackson/kotlin/GenerateTestClasses.kt +++ b/src/integration/jackson/src/jvmTest/kotlin/community/flock/wirespec/integration/jackson/kotlin/GenerateTestClasses.kt @@ -1,5 +1,6 @@ package community.flock.wirespec.integration.jackson.kotlin +import community.flock.wirespec.compiler.core.ParseContext import community.flock.wirespec.compiler.core.WirespecSpec import community.flock.wirespec.compiler.core.emit.JavaEmitter import community.flock.wirespec.compiler.core.emit.KotlinEmitter @@ -15,8 +16,8 @@ class GenerateTestClasses { private val javaPkg = "${basePkg}.java.generated" private val kotlinPkg = "${basePkg}.kotlin.generated" - private val javaEmitter = JavaEmitter(javaPkg) - private val kotlinEmitter = KotlinEmitter(kotlinPkg) + private val javaEmitter = JavaEmitter(javaPkg, noLogger) + private val kotlinEmitter = KotlinEmitter(kotlinPkg, noLogger) private fun pkgToPath(pkg: String) = pkg.split(".").joinToString("/") @@ -27,7 +28,10 @@ class GenerateTestClasses { @Test fun generate() { val todoFile = File("src/commonTest/resources/wirespec/todos.ws").readText() - val ast = WirespecSpec.parse(todoFile)(noLogger) + val ast = object : ParseContext { + override val spec = WirespecSpec + override val logger = noLogger + }.parse(todoFile) .fold({ error("Cannot parse wirespec: ${it.first().message}") }, { it }) .filterIsInstance() @@ -45,4 +49,3 @@ class GenerateTestClasses { } } } - diff --git a/src/integration/spring/src/jvmMain/kotlin/community/flock/wirespec/integration/spring/kotlin/emit/SpringKotlinEmitter.kt b/src/integration/spring/src/jvmMain/kotlin/community/flock/wirespec/integration/spring/kotlin/emit/SpringKotlinEmitter.kt index f9538b502..b042de141 100644 --- a/src/integration/spring/src/jvmMain/kotlin/community/flock/wirespec/integration/spring/kotlin/emit/SpringKotlinEmitter.kt +++ b/src/integration/spring/src/jvmMain/kotlin/community/flock/wirespec/integration/spring/kotlin/emit/SpringKotlinEmitter.kt @@ -3,9 +3,8 @@ package community.flock.wirespec.integration.spring.kotlin.emit import community.flock.wirespec.compiler.core.emit.KotlinEmitter import community.flock.wirespec.compiler.core.parse.Endpoint import community.flock.wirespec.compiler.utils.Logger -import community.flock.wirespec.compiler.utils.noLogger -class SpringKotlinEmitter(packageName: String, logger: Logger = noLogger) : KotlinEmitter(packageName, logger) { +class SpringKotlinEmitter(packageName: String, logger: Logger) : KotlinEmitter(packageName, logger) { override fun emitHandleFunction(endpoint: Endpoint): String { val path = "/${endpoint.path.joinToString("/") { it.emit() }}" val annotation = when (endpoint.method) { diff --git a/src/integration/spring/src/jvmTest/kotlin/community/flock/wirespec/integration/spring/kotlin/GenerateTestClasses.kt b/src/integration/spring/src/jvmTest/kotlin/community/flock/wirespec/integration/spring/kotlin/GenerateTestClasses.kt index 1e2bf3a75..fdecc3bae 100644 --- a/src/integration/spring/src/jvmTest/kotlin/community/flock/wirespec/integration/spring/kotlin/GenerateTestClasses.kt +++ b/src/integration/spring/src/jvmTest/kotlin/community/flock/wirespec/integration/spring/kotlin/GenerateTestClasses.kt @@ -1,5 +1,6 @@ package community.flock.wirespec.integration.spring.kotlin +import community.flock.wirespec.compiler.utils.noLogger import community.flock.wirespec.integration.spring.kotlin.emit.SpringKotlinEmitter import community.flock.wirespec.openapi.v3.OpenApiV3Parser import java.io.File @@ -10,7 +11,7 @@ class GenerateTestClasses { private val basePkg = "community.flock.wirespec.integration.spring.kotlin" private val kotlinPkg = "${basePkg}.generated" - private val kotlinEmitter = SpringKotlinEmitter(kotlinPkg) + private val kotlinEmitter = SpringKotlinEmitter(kotlinPkg, noLogger) private fun pkgToPath(pkg: String) = pkg.split(".").joinToString("/") @@ -29,4 +30,3 @@ class GenerateTestClasses { } } } - diff --git a/src/plugin/arguments/src/commonMain/kotlin/community/flock/wirespec/plugin/CompilerUtil.kt b/src/plugin/arguments/src/commonMain/kotlin/community/flock/wirespec/plugin/CompilerUtil.kt index 12525ede9..f1ad5ecb2 100644 --- a/src/plugin/arguments/src/commonMain/kotlin/community/flock/wirespec/plugin/CompilerUtil.kt +++ b/src/plugin/arguments/src/commonMain/kotlin/community/flock/wirespec/plugin/CompilerUtil.kt @@ -1,6 +1,7 @@ package community.flock.wirespec.plugin import arrow.core.Either +import community.flock.wirespec.compiler.core.ParseContext import community.flock.wirespec.compiler.core.WirespecSpec import community.flock.wirespec.compiler.core.emit.JavaEmitter import community.flock.wirespec.compiler.core.emit.KotlinEmitter @@ -30,13 +31,17 @@ import community.flock.wirespec.plugin.Language.Wirespec typealias FilesContent = List> fun FilesContent.parse(logger: Logger): List>> = - map { (name, source) -> name to WirespecSpec.parse(source)(logger) } - .map { (name, result) -> - name to when (result) { - is Either.Right -> result.value - is Either.Left -> error("compile error: ${result.value}") - } + map { (name, source) -> + name to object : ParseContext { + override val spec = WirespecSpec + override val logger = logger + }.parse(source) + }.map { (name, result) -> + name to when (result) { + is Either.Right -> result.value + is Either.Left -> error("compile error: ${result.value}") } + } fun FilesContent.compile(logger: Logger, emitter: Emitter) = parse(logger) diff --git a/src/plugin/cli/src/commonMain/kotlin/community/flock/wirespec/plugin/cli/Main.kt b/src/plugin/cli/src/commonMain/kotlin/community/flock/wirespec/plugin/cli/Main.kt index ac64593c0..0d23295a6 100644 --- a/src/plugin/cli/src/commonMain/kotlin/community/flock/wirespec/plugin/cli/Main.kt +++ b/src/plugin/cli/src/commonMain/kotlin/community/flock/wirespec/plugin/cli/Main.kt @@ -5,7 +5,7 @@ import arrow.core.NonEmptyList import arrow.core.left import arrow.core.nel import arrow.core.right -import community.flock.wirespec.compiler.core.WirespecSpec +import community.flock.wirespec.compiler.core.CompilationContext import community.flock.wirespec.compiler.core.compile import community.flock.wirespec.compiler.core.component1 import community.flock.wirespec.compiler.core.emit.JavaEmitter @@ -58,7 +58,8 @@ fun main(args: Array) { .let(WirespecCli.provide(::compile, ::convert, ::write)) } -fun convert(arguments: CompilerArguments): List, Pair, File?>>> = compile(arguments) +fun convert(arguments: CompilerArguments): List, Pair, File?>>> = + compile(arguments) fun compile(arguments: CompilerArguments): List, Pair, File?>>> { @@ -120,10 +121,12 @@ private fun Reader.wirespec( path: (FileExtension) -> FullFilePath, logger: Logger ) = read() - .let(WirespecSpec::compile)(logger) - .let { compiler -> + .let { source -> languages.emitters(packageName, path, logger).map { (emitter, file) -> - val results = compiler(emitter) + val results = object : CompilationContext { + override val logger = logger + override val emitter = emitter + }.compile(source) if (!emitter.split) results.map { listOf( Emitted( diff --git a/src/plugin/cli/src/jsMain/kotlin/community/flock/wirespec/plugin/cli/Cli.kt b/src/plugin/cli/src/jsMain/kotlin/community/flock/wirespec/plugin/cli/Cli.kt index c60108979..6f17c6b61 100644 --- a/src/plugin/cli/src/jsMain/kotlin/community/flock/wirespec/plugin/cli/Cli.kt +++ b/src/plugin/cli/src/jsMain/kotlin/community/flock/wirespec/plugin/cli/Cli.kt @@ -2,12 +2,11 @@ package community.flock.wirespec.plugin.cli -import community.flock.wirespec.compiler.core.WirespecSpec +import community.flock.wirespec.compiler.core.ParseContext import community.flock.wirespec.compiler.core.parse import community.flock.wirespec.compiler.core.parse.Definition import community.flock.wirespec.compiler.lib.WsNode import community.flock.wirespec.compiler.lib.produce - import community.flock.wirespec.compiler.utils.noLogger @JsExport @@ -16,11 +15,11 @@ fun cli(args: Array) { } @JsExport -fun parser(source: String): Array { - return WirespecSpec.parse(source)(noLogger).getOrNull() +fun parser(source: String): Array = + object : ParseContext { + override val logger = noLogger + }.parse(source).getOrNull() ?.filterIsInstance() ?.map { it.produce() } ?.toTypedArray() ?: error("Cannot parse source") -} - diff --git a/src/plugin/npm/src/commonTest/kotlin/community/flock/wirespec/plugin/npm/MainTest.kt b/src/plugin/npm/src/commonTest/kotlin/community/flock/wirespec/plugin/npm/MainTest.kt index 7884f823a..9eba29c61 100644 --- a/src/plugin/npm/src/commonTest/kotlin/community/flock/wirespec/plugin/npm/MainTest.kt +++ b/src/plugin/npm/src/commonTest/kotlin/community/flock/wirespec/plugin/npm/MainTest.kt @@ -1,6 +1,7 @@ package community.flock.wirespec.plugin.npm import com.goncalossilva.resources.Resource +import community.flock.wirespec.compiler.core.ParseContext import community.flock.wirespec.compiler.core.WirespecSpec import community.flock.wirespec.compiler.core.parse import community.flock.wirespec.compiler.lib.produce @@ -14,11 +15,14 @@ class MainTest { @Test fun testEmit() { val file = Resource("src/commonTest/resources/person.ws").readText() - val res = WirespecSpec.parse(file)(noLogger).getOrNull() + val res = object : ParseContext { + override val spec = WirespecSpec + override val logger = noLogger + }.parse(file).getOrNull() assertNotNull(res) val openApiV2 = emit(res.produce(), Emitters.OPENAPI_V2, "") val openApiV3 = emit(res.produce(), Emitters.OPENAPI_V3, "") assertEquals("""{"swagger":"2.0"""", openApiV2.first().result.substring(0, 16)) assertEquals("""{"openapi":"3.0.0"""", openApiV3.first().result.substring(0, 18)) } -} \ No newline at end of file +} diff --git a/src/plugin/npm/src/jsMain/kotlin/community/flock/wirespec/plugin/npm/Main.kt b/src/plugin/npm/src/jsMain/kotlin/community/flock/wirespec/plugin/npm/Main.kt index 761e69db2..df66a5af7 100644 --- a/src/plugin/npm/src/jsMain/kotlin/community/flock/wirespec/plugin/npm/Main.kt +++ b/src/plugin/npm/src/jsMain/kotlin/community/flock/wirespec/plugin/npm/Main.kt @@ -5,6 +5,7 @@ package community.flock.wirespec.plugin.npm import arrow.core.curried import community.flock.kotlinx.openapi.bindings.v2.SwaggerObject import community.flock.kotlinx.openapi.bindings.v3.OpenAPIObject +import community.flock.wirespec.compiler.core.ParseContext import community.flock.wirespec.compiler.core.WirespecSpec import community.flock.wirespec.compiler.core.emit.JavaEmitter import community.flock.wirespec.compiler.core.emit.KotlinEmitter @@ -12,7 +13,7 @@ import community.flock.wirespec.compiler.core.emit.ScalaEmitter import community.flock.wirespec.compiler.core.emit.TypeScriptEmitter import community.flock.wirespec.compiler.core.emit.WirespecEmitter import community.flock.wirespec.compiler.core.emit.common.Emitted -import community.flock.wirespec.compiler.core.parse.Parser +import community.flock.wirespec.compiler.core.parse import community.flock.wirespec.compiler.core.tokenize.tokenize import community.flock.wirespec.compiler.lib.WsNode import community.flock.wirespec.compiler.lib.WsStringResult @@ -55,10 +56,9 @@ fun tokenize(source: String) = WirespecSpec .toTypedArray() @JsExport -fun parse(source: String) = WirespecSpec - .tokenize(source) - .let(Parser(noLogger)::parse) - .produce() +fun parse(source: String) = object : ParseContext { + override val logger = noLogger +}.parse(source).produce() @JsExport fun convert(source: String, converters: Converters) = when (converters) { @@ -67,9 +67,9 @@ fun convert(source: String, converters: Converters) = when (converters) { } @JsExport -fun generate(source: String, type: String): WsStringResult = WirespecSpec - .tokenize(source) - .let(Parser(noLogger)::parse) +fun generate(source: String, type: String): WsStringResult = object : ParseContext { + override val logger = noLogger +}.parse(source) .map { it.generate(type).toString() } .produce() @@ -78,18 +78,18 @@ fun emit(ast: Array, emitter: Emitters, packageName: String) = ast .map { it.consume() } .let { when (emitter) { - Emitters.WIRESPEC -> WirespecEmitter().emit(it) - Emitters.TYPESCRIPT -> TypeScriptEmitter().emit(it) - Emitters.JAVA -> JavaEmitter(packageName).emit(it) - Emitters.KOTLIN -> KotlinEmitter(packageName).emit(it) - Emitters.SCALA -> ScalaEmitter(packageName).emit(it) + Emitters.WIRESPEC -> WirespecEmitter(logger = noLogger).emit(it) + Emitters.TYPESCRIPT -> TypeScriptEmitter(logger = noLogger).emit(it) + Emitters.JAVA -> JavaEmitter(packageName, logger = noLogger).emit(it) + Emitters.KOTLIN -> KotlinEmitter(packageName, logger = noLogger).emit(it) + Emitters.SCALA -> ScalaEmitter(packageName, logger = noLogger).emit(it) Emitters.OPENAPI_V2 -> listOf(it) .map(OpenApiV2Emitter::emitSwaggerObject) .map(encode(SwaggerObject.serializer())) .map(::Emitted.curried()("openapi")::invoke) Emitters.OPENAPI_V3 -> listOf(it) - .map{ast -> OpenApiV3Emitter.emitOpenAPIObject(ast, null)} + .map { ast -> OpenApiV3Emitter.emitOpenAPIObject(ast, null) } .map(encode(OpenAPIObject.serializer())) .map(::Emitted.curried()("openapi")::invoke) } diff --git a/src/tools/generator/src/commonTest/kotlin/community/flock/wirespec/generator/GeneratorTest.kt b/src/tools/generator/src/commonTest/kotlin/community/flock/wirespec/generator/GeneratorTest.kt index b8857833f..8e24282d5 100644 --- a/src/tools/generator/src/commonTest/kotlin/community/flock/wirespec/generator/GeneratorTest.kt +++ b/src/tools/generator/src/commonTest/kotlin/community/flock/wirespec/generator/GeneratorTest.kt @@ -1,17 +1,18 @@ package community.flock.wirespec.generator import arrow.core.getOrElse +import community.flock.wirespec.compiler.core.ParseContext import community.flock.wirespec.compiler.core.WirespecSpec import community.flock.wirespec.compiler.core.parse import community.flock.wirespec.compiler.core.parse.Reference.Primitive import community.flock.wirespec.compiler.core.parse.Reference.Primitive.Type import community.flock.wirespec.compiler.utils.noLogger -import kotlinx.serialization.json.jsonArray -import kotlinx.serialization.json.jsonPrimitive import kotlin.random.Random import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotEquals +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonPrimitive class GeneratorTest { @@ -44,9 +45,6 @@ class GeneratorTest { |} """.trimMargin() - private fun parser(source: String) = - WirespecSpec.parse(source)(noLogger).getOrElse { e -> error("Cannot parse: ${e.map { it.message }}") } - @Test fun generateAddress() { val ast = parser(src) @@ -85,4 +83,10 @@ class GeneratorTest { assertEquals(5, res.jsonArray.size) } + private fun parser(source: String) = + object : ParseContext { + override val spec = WirespecSpec + override val logger = noLogger + }.parse(source).getOrElse { e -> error("Cannot parse: ${e.map { it.message }}") } + }