pact-foundation / pact-jvm

JVM version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://docs.pact.io
Apache License 2.0
1.08k stars 479 forks source link

Provide an artifact with only the model types #1793

Open tomasbjerre opened 5 months ago

tomasbjerre commented 5 months ago

Use case

I am currently depending on au.com.dius.pact.core:model to get the types. To be exact, I currently use these (but will likely need others in the future):

import au.com.dius.pact.core.model.Consumer;
import au.com.dius.pact.core.model.IRequest;
import au.com.dius.pact.core.model.IResponse;
import au.com.dius.pact.core.model.Interaction;
import au.com.dius.pact.core.model.OptionalBody;
import au.com.dius.pact.core.model.OptionalBody.State;
import au.com.dius.pact.core.model.PactSpecVersion;
import au.com.dius.pact.core.model.Provider;
import au.com.dius.pact.core.model.ProviderState;
import au.com.dius.pact.core.model.SynchronousRequestResponse;
import au.com.dius.pact.core.model.V4Interaction.SynchronousHttp;
import au.com.dius.pact.core.model.V4Pact;

I need to generate valid v4 JSON and that is why I need these types.

Problem

The au.com.dius.pact.core:model artifact adds a lot of transitives to the classpath. And that results in problems like ClassNotFoundException, MethodNotFoundException, ... classic classpath issues.

I found the JsonSchema spec but I need Java code and the only code generator I can find does not support anyOf.

|    \--- au.com.dius.pact.core:model:4.6.9
|         +--- org.jetbrains.kotlin:kotlin-bom:1.8.22
|         |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.8.22 (c)
|         |    +--- org.jetbrains.kotlin:kotlin-reflect:1.8.22 (c)
|         |    +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.8.22 (c)
|         |    +--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.22 (c)
|         |    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.22 (c)
|         +--- org.jetbrains.kotlin:kotlin-stdlib:1.8.22
|         |    +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.8.22
|         |    \--- org.jetbrains:annotations:13.0 -> 23.0.0
|         +--- org.jetbrains.kotlin:kotlin-reflect:1.8.22
|         |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.8.22 (*)
|         +--- org.apache.commons:commons-lang3 -> 3.12.0
|         +--- org.apache.commons:commons-collections4 -> 4.4
|         +--- commons-codec:commons-codec -> 1.15
|         +--- org.slf4j:slf4j-api -> 2.0.9
|         +--- com.github.mifmif:generex:1.0.2
|         |    \--- dk.brics.automaton:automaton:1.11-8
|         +--- javax.mail:mail:1.5.0-b01
|         |    \--- javax.activation:activation:1.1
|         +--- io.ktor:ktor-http-jvm -> 2.3.8
|         |    +--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.22
|         |    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.8.22 (*)
|         |    +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.22
|         |    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.8.22 (*)
|         |    |    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.22 (*)
|         |    +--- org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.7.1
|         |    |    +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1
|         |    |    |    \--- org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.7.1
|         |    |    |         +--- org.jetbrains:annotations:23.0.0
|         |    |    |         +--- org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.7.1
|         |    |    |         |    +--- org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.7.1 (c)
|         |    |    |         |    +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1 (c)
|         |    |    |         |    \--- org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.7.1 (c)
|         |    |    |         \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.8.20 -> 1.8.22
|         |    |    \--- org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.7.1 (*)
|         |    +--- org.slf4j:slf4j-api:1.7.36 -> 2.0.9
|         |    +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1 (*)
|         |    +--- io.ktor:ktor-utils:2.3.8
|         |    |    \--- io.ktor:ktor-utils-jvm:2.3.8
|         |    |         +--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.22 (*)
|         |    |         +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.22 (*)
|         |    |         +--- org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.7.1 (*)
|         |    |         +--- org.slf4j:slf4j-api:1.7.36 -> 2.0.9
|         |    |         +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1 (*)
|         |    |         +--- io.ktor:ktor-io:2.3.8
|         |    |         |    \--- io.ktor:ktor-io-jvm:2.3.8
|         |    |         |         +--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.22 (*)
|         |    |         |         +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.22 (*)
|         |    |         |         +--- org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.7.1 (*)
|         |    |         |         +--- org.slf4j:slf4j-api:1.7.36 -> 2.0.9
|         |    |         |         +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1 (*)
|         |    |         |         \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.8.22
|         |    |         \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.8.22
|         |    \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.8.22
|         +--- commons-beanutils:commons-beanutils:1.9.4
|         |    +--- commons-logging:commons-logging:1.2
|         |    \--- commons-collections:commons-collections:3.2.2
|         +--- au.com.dius.pact.core:support:4.6.9
|         |    +--- org.jetbrains.kotlin:kotlin-bom:1.8.22 (*)
|         |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.8.22 (*)
|         |    +--- org.jetbrains.kotlin:kotlin-reflect:1.8.22 (*)
|         |    +--- org.apache.commons:commons-text -> 1.10.0
|         |    |    \--- org.apache.commons:commons-lang3:3.12.0
|         |    +--- commons-codec:commons-codec -> 1.15
|         |    +--- io.github.oshai:kotlin-logging-jvm -> 5.1.4
|         |    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.22 (*)
|         |    |    \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.8.22
|         |    +--- org.apache.httpcomponents.client5:httpclient5 -> 5.2.1
|         |    |    +--- org.apache.httpcomponents.core5:httpcore5:5.2
|         |    |    +--- org.apache.httpcomponents.core5:httpcore5-h2:5.2
|         |    |    |    \--- org.apache.httpcomponents.core5:httpcore5:5.2
|         |    |    \--- org.slf4j:slf4j-api:1.7.36 -> 2.0.9
|         |    +--- org.apache.httpcomponents.client5:httpclient5-fluent -> 5.2.1
|         |    |    +--- org.apache.httpcomponents.client5:httpclient5:5.2.1 (*)
|         |    |    \--- org.slf4j:slf4j-api:1.7.36 -> 2.0.9
|         |    +--- org.jetbrains.kotlin:kotlin-stdlib -> 1.8.22 (c)
|         |    +--- org.apache.commons:commons-lang3:3.12.0 (c)
|         |    +--- org.apache.commons:commons-text:1.10.0 (c)
|         |    +--- org.apache.commons:commons-collections4:4.4 (c)
|         |    +--- org.apache.tika:tika-core:2.9.1 (c)
|         |    +--- org.slf4j:slf4j-api:1.7.36 -> 2.0.9 (c)
|         |    +--- io.ktor:ktor-http-jvm:2.3.8 (c)
|         |    +--- commons-codec:commons-codec:1.15 (c)
|         |    +--- io.github.oshai:kotlin-logging-jvm:5.1.4 (c)
|         |    +--- org.apache.httpcomponents.client5:httpclient5:5.2.1 (c)
|         |    +--- org.apache.httpcomponents.client5:httpclient5-fluent:5.2.1 (c)
|         |    \--- com.google.guava:guava:31.1-jre (c)
|         +--- au.com.dius.pact.core:pactbroker:4.6.9
|         |    +--- org.jetbrains.kotlin:kotlin-bom:1.8.22 (*)
|         |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.8.22 (*)
|         |    +--- org.jetbrains.kotlin:kotlin-reflect:1.8.22 (*)
|         |    +--- org.apache.commons:commons-lang3 -> 3.12.0
|         |    +--- com.google.guava:guava -> 31.1-jre
|         |    |    +--- com.google.guava:failureaccess:1.0.1
|         |    |    +--- com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
|         |    |    +--- com.google.code.findbugs:jsr305:3.0.2
|         |    |    +--- org.checkerframework:checker-qual:3.12.0
|         |    |    +--- com.google.errorprone:error_prone_annotations:2.11.0
|         |    |    \--- com.google.j2objc:j2objc-annotations:1.3
|         |    +--- org.slf4j:slf4j-api -> 2.0.9
|         |    +--- au.com.dius.pact.core:support:4.6.9 (*)
|         |    +--- io.github.oshai:kotlin-logging-jvm -> 5.1.4 (*)
|         |    +--- org.apache.httpcomponents.client5:httpclient5 -> 5.2.1 (*)
|         |    +--- org.jetbrains.kotlin:kotlin-stdlib -> 1.8.22 (c)
|         |    +--- org.apache.commons:commons-lang3:3.12.0 (c)
|         |    +--- org.apache.commons:commons-text:1.10.0 (c)
|         |    +--- org.apache.commons:commons-collections4:4.4 (c)
|         |    +--- org.apache.tika:tika-core:2.9.1 (c)
|         |    +--- com.google.guava:guava:31.1-jre (c)
|         |    +--- org.slf4j:slf4j-api:1.7.36 -> 2.0.9 (c)
|         |    +--- io.ktor:ktor-http-jvm:2.3.8 (c)
|         |    +--- commons-codec:commons-codec:1.15 (c)
|         |    +--- io.github.oshai:kotlin-logging-jvm:5.1.4 (c)
|         |    +--- org.apache.httpcomponents.client5:httpclient5:5.2.1 (c)
|         |    \--- org.apache.httpcomponents.client5:httpclient5-fluent:5.2.1 (c)
|         +--- org.apache.tika:tika-core -> 2.9.1
|         |    +--- org.slf4j:slf4j-api:2.0.9
|         |    \--- commons-io:commons-io:2.14.0
|         +--- org.jetbrains.kotlin:kotlin-stdlib -> 1.8.22 (c)
|         +--- org.apache.commons:commons-lang3:3.12.0 (c)
|         +--- org.apache.commons:commons-collections4:4.4 (c)
|         +--- org.apache.tika:tika-core:2.9.1 (c)
|         +--- org.slf4j:slf4j-api:1.7.36 -> 2.0.9 (c)
|         +--- io.ktor:ktor-http-jvm:2.3.8 (c)
|         +--- commons-codec:commons-codec:1.15 (c)
|         +--- org.apache.commons:commons-text:1.10.0 (c)
|         +--- io.github.oshai:kotlin-logging-jvm:5.1.4 (c)
|         +--- org.apache.httpcomponents.client5:httpclient5:5.2.1 (c)
|         +--- org.apache.httpcomponents.client5:httpclient5-fluent:5.2.1 (c)
|         \--- com.google.guava:guava:31.1-jre (c)

Proposed solution

Move the types into its own artifact. Would be nice if it can have zero dependencies, not even Kotlin, but as few as possible would help.

Also the JSON serialization would be nice to have separated. I was a bit surprised that the body is not "content": "{ \"a\": \"b\" }" but it is instead "content": { "a": "b" }, such logic would be nice to have separated.

Workaround

I might just package a fat jar from model and relocate stuff so that it has zero dependencies.