Skip to content

Commit

Permalink
Uses the first 2xx content media found es primary response type #239 (#…
Browse files Browse the repository at this point in the history
…243)

* Upgrade dependencies & linter
  • Loading branch information
averabaq authored Oct 11, 2023
1 parent 2231b9b commit dfa30a2
Show file tree
Hide file tree
Showing 15 changed files with 131 additions and 137 deletions.
23 changes: 13 additions & 10 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ repositories {
}

dependencies {
val jacksonVersion = "2.14.2"
val jacksonVersion = "2.15.1"

implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
Expand All @@ -53,24 +53,27 @@ dependencies {
implementation("com.squareup:kotlinpoet:1.14.2") { exclude(module = "kotlin-stdlib-jre7") }
implementation("com.google.flogger:flogger:0.7.4")

testImplementation("org.junit.jupiter:junit-jupiter-api:5.1.0")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.1.0")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.1.0")
testImplementation("org.assertj:assertj-core:3.14.0")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.2")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.9.2")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.9.2")
testImplementation("org.assertj:assertj-core:3.24.2")

// Below dependencies are solely present so code examples in the test resources dir compile
testImplementation("javax.validation:validation-api:2.0.1.Final")
testImplementation("jakarta.validation:jakarta.validation-api:3.0.2")
testImplementation("org.springframework:spring-webmvc:6.0.0")
testImplementation("org.springframework.security:spring-security-web:6.0.0")
testImplementation("org.springframework:spring-webmvc:6.0.9")
testImplementation("org.springframework.security:spring-security-web:6.1.0")
testImplementation("io.micronaut:micronaut-core:3.8.7")
testImplementation("io.micronaut:micronaut-http:3.8.7")
//testCompileOnly("io.micronaut.security:micronaut-security:3.8.7")
testImplementation("com.squareup.okhttp3:okhttp:4.10.0")
testImplementation("com.pinterest.ktlint:ktlint-core:0.48.2")
testImplementation("com.pinterest.ktlint:ktlint-ruleset-standard:0.48.2")
testImplementation("com.pinterest:ktlint:0.48.2")
testImplementation("org.openapitools:jackson-databind-nullable:0.2.6")

testImplementation(platform("com.pinterest.ktlint:ktlint-bom:0.49.0"))
testImplementation("com.pinterest:ktlint")
testImplementation("com.pinterest.ktlint:ktlint-core")
testImplementation("com.pinterest.ktlint:ktlint-rule-engine")
testImplementation("com.pinterest.ktlint:ktlint-ruleset-standard")
}

tasks {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,10 @@ object GeneratorUtils {

fun Operation.firstResponse(): Response? = this.getBodyResponses().firstOrNull()

fun Operation.getPrimaryContentMediaType(): Map.Entry<String, MediaType>? =
this.getBodyResponses().map { response -> response.getPrimaryContentMediaType() }.firstOrNull()
fun Operation.getPrimaryContentMediaType(): Map.Entry<String, MediaType>? {
val responses = getBodySuccessResponses().ifEmpty { getBodyResponses() }
return responses.map { response -> response.getPrimaryContentMediaType() }.firstOrNull()
}

fun Operation.getPrimaryContentMediaTypeKey(): String? = this.firstResponse()?.getPrimaryContentMediaType()?.key

Expand Down
6 changes: 3 additions & 3 deletions src/test/kotlin/com/cjbooms/fabrikt/util/Linter.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.cjbooms.fabrikt.util

import com.pinterest.ktlint.core.Code
import com.pinterest.ktlint.core.KtLintRuleEngine
import com.pinterest.ktlint.rule.engine.api.Code
import com.pinterest.ktlint.rule.engine.api.KtLintRuleEngine
import com.pinterest.ktlint.ruleset.standard.StandardRuleSetProvider

object Linter {

fun lintString(rawText: String): String {
val code = Code.CodeSnippet(rawText)
val code = Code.fromSnippet(rawText)
val result = KtLintRuleEngine(
ruleProviders = StandardRuleSetProvider().getRuleProviders(),
).format(code)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public interface ProhibitedController {
produces = [],
method = [RequestMethod.GET],
)
public fun testPath(@RequestParam(value = "testString", required = true) testString: String):
ResponseEntity<Unit>
public fun testPath(@RequestParam(value = "testString", required = true) testString: String): ResponseEntity<Unit>
}

@Controller
Expand Down Expand Up @@ -82,8 +81,7 @@ public interface NoneController {
produces = [],
method = [RequestMethod.GET],
)
public fun testPath(@RequestParam(value = "testString", required = true) testString: String):
ResponseEntity<Unit>
public fun testPath(@RequestParam(value = "testString", required = true) testString: String): ResponseEntity<Unit>
}

@Controller
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,5 @@ public interface BinaryDataController {
@Post(uri = "/binary-data")
@Consumes(value = ["application/octet-stream"])
@Produces(value = ["application/octet-stream"])
public fun postBinaryData(
@Body @Valid
applicationOctetStream: ByteArray,
): HttpResponse<ByteArray>
public fun postBinaryData(@Body @Valid applicationOctetStream: ByteArray): HttpResponse<ByteArray>
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,5 @@ public interface BinaryDataController {
method = [RequestMethod.POST],
consumes = ["application/octet-stream"],
)
public fun postBinaryData(
@RequestBody @Valid
applicationOctetStream: ByteArray,
):
ResponseEntity<ByteArray>
public fun postBinaryData(@RequestBody @Valid applicationOctetStream: ByteArray): ResponseEntity<ByteArray>
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ public interface InternalEventsController {
@Post(uri = "/internal/events")
@Consumes(value = ["application/json"])
@Produces(value = ["application/json", "application/problem+json"])
public fun post(
@Body @Valid
bulkEntityDetails: BulkEntityDetails,
): HttpResponse<EventResults>
public fun post(@Body @Valid bulkEntityDetails: BulkEntityDetails): HttpResponse<EventResults>
}

@Controller
Expand All @@ -69,10 +66,7 @@ public interface ContributorsController {
@Get(uri = "/contributors")
@Produces(value = ["application/json"])
public fun searchContributors(
@Min(1)
@Max(100)
@QueryValue(value = "limit", defaultValue = "10")
limit: Int,
@Min(1) @Max(100) @QueryValue(value = "limit", defaultValue = "10") limit: Int,
@Header(value = "X-Flow-Id") xFlowId: String?,
@QueryValue(value = "include_inactive") includeInactive: Boolean?,
@QueryValue(value = "cursor") cursor: String?,
Expand All @@ -97,8 +91,7 @@ public interface ContributorsController {
@Post(uri = "/contributors")
@Consumes(value = ["application/json"])
public fun createContributor(
@Body @Valid
contributor: Contributor,
@Body @Valid contributor: Contributor,
@Header(value = "X-Flow-Id") xFlowId: String?,
@Header(value = "Idempotency-Key") idempotencyKey: UUID?,
): HttpResponse<Unit>
Expand Down Expand Up @@ -152,8 +145,7 @@ public interface ContributorsController {
@Put(uri = "/contributors/{id}")
@Consumes(value = ["application/json"])
public fun putById(
@Body @Valid
contributor: Contributor,
@Body @Valid contributor: Contributor,
@PathVariable(value = "id") id: String,
@Header(value = "If-Match") ifMatch: String,
@Header(value = "X-Flow-Id") xFlowId: String?,
Expand Down Expand Up @@ -181,10 +173,7 @@ public interface OrganisationsController {
@Get(uri = "/organisations")
@Produces(value = ["application/json"])
public fun `get`(
@Min(1)
@Max(100)
@QueryValue(value = "limit", defaultValue = "10")
limit: Int,
@Min(1) @Max(100) @QueryValue(value = "limit", defaultValue = "10") limit: Int,
@Header(value = "X-Flow-Id") xFlowId: String?,
@QueryValue(value = "include_inactive") includeInactive: Boolean?,
@QueryValue(value = "cursor") cursor: String?,
Expand All @@ -209,8 +198,7 @@ public interface OrganisationsController {
@Post(uri = "/organisations")
@Consumes(value = ["application/json"])
public fun post(
@Body @Valid
organisation: Organisation,
@Body @Valid organisation: Organisation,
@Header(value = "X-Flow-Id") xFlowId: String?,
@Header(value = "Idempotency-Key") idempotencyKey: UUID?,
): HttpResponse<Unit>
Expand Down Expand Up @@ -264,8 +252,7 @@ public interface OrganisationsController {
@Put(uri = "/organisations/{id}")
@Consumes(value = ["application/json"])
public fun putById(
@Body @Valid
organisation: Organisation,
@Body @Valid organisation: Organisation,
@PathVariable(value = "id") id: String,
@Header(value = "If-Match") ifMatch: String,
@Header(value = "X-Flow-Id") xFlowId: String?,
Expand Down Expand Up @@ -296,10 +283,7 @@ public interface OrganisationsContributorsController {
@Produces(value = ["application/json"])
public fun `get`(
@PathVariable(value = "parent-id") parentId: String,
@Min(1)
@Max(100)
@QueryValue(value = "limit", defaultValue = "10")
limit: Int,
@Min(1) @Max(100) @QueryValue(value = "limit", defaultValue = "10") limit: Int,
@Header(value = "X-Flow-Id") xFlowId: String?,
@QueryValue(value = "include_inactive") includeInactive: Boolean?,
@QueryValue(value = "cursor") cursor: String?,
Expand Down Expand Up @@ -399,17 +383,10 @@ public interface RepositoriesController {
@Get(uri = "/repositories")
@Produces(value = ["application/json"])
public fun `get`(
@Min(1)
@Max(100)
@QueryValue(value = "limit", defaultValue = "10")
limit: Int,
@Min(1) @Max(100) @QueryValue(value = "limit", defaultValue = "10") limit: Int,
@Header(value = "X-Flow-Id") xFlowId: String?,
@Valid
@QueryValue(value = "slug")
slug: List<String>?,
@Valid
@QueryValue(value = "name")
name: List<String>?,
@Valid @QueryValue(value = "slug") slug: List<String>?,
@Valid @QueryValue(value = "name") name: List<String>?,
@QueryValue(value = "include_inactive") includeInactive: Boolean?,
@QueryValue(value = "cursor") cursor: String?,
): HttpResponse<RepositoryQueryResult>
Expand All @@ -433,8 +410,7 @@ public interface RepositoriesController {
@Post(uri = "/repositories")
@Consumes(value = ["application/json"])
public fun post(
@Body @Valid
repository: Repository,
@Body @Valid repository: Repository,
@Header(value = "X-Flow-Id") xFlowId: String?,
@Header(value = "Idempotency-Key") idempotencyKey: UUID?,
): HttpResponse<Unit>
Expand Down Expand Up @@ -488,8 +464,7 @@ public interface RepositoriesController {
@Put(uri = "/repositories/{id}")
@Consumes(value = ["application/json"])
public fun putById(
@Body @Valid
repository: Repository,
@Body @Valid repository: Repository,
@PathVariable(value = "id") id: String,
@Header(value = "If-Match") ifMatch: String,
@Header(value = "X-Flow-Id") xFlowId: String?,
Expand Down Expand Up @@ -520,10 +495,7 @@ public interface RepositoriesPullRequestsController {
@Produces(value = ["application/json"])
public fun `get`(
@PathVariable(value = "parent-id") parentId: String,
@Min(1)
@Max(100)
@QueryValue(value = "limit", defaultValue = "10")
limit: Int,
@Min(1) @Max(100) @QueryValue(value = "limit", defaultValue = "10") limit: Int,
@Header(value = "X-Flow-Id") xFlowId: String?,
@QueryValue(value = "include_inactive") includeInactive: Boolean?,
@QueryValue(value = "cursor") cursor: String?,
Expand All @@ -549,8 +521,7 @@ public interface RepositoriesPullRequestsController {
@Post(uri = "/repositories/{parent-id}/pull-requests")
@Consumes(value = ["application/json"])
public fun post(
@Body @Valid
pullRequest: PullRequest,
@Body @Valid pullRequest: PullRequest,
@PathVariable(value = "parent-id") parentId: String,
@Header(value = "X-Flow-Id") xFlowId: String?,
@Header(value = "Idempotency-Key") idempotencyKey: UUID?,
Expand Down Expand Up @@ -604,8 +575,7 @@ public interface RepositoriesPullRequestsController {
@Put(uri = "/repositories/{parent-id}/pull-requests/{id}")
@Consumes(value = ["application/json"])
public fun putById(
@Body @Valid
pullRequest: PullRequest,
@Body @Valid pullRequest: PullRequest,
@PathVariable(value = "parent-id") parentId: String,
@PathVariable(value = "id") id: String,
@Header(value = "If-Match") ifMatch: String,
Expand Down
Loading

0 comments on commit dfa30a2

Please sign in to comment.