Skip to content

Commit

Permalink
initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jrouly committed Jan 26, 2021
1 parent 0e41fdd commit 647236f
Show file tree
Hide file tree
Showing 9 changed files with 1,284 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2020 OpenAPI-Generator Contributors (https://openapi-generator.tech)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.openapitools.generator.sbt.plugin

import org.openapitools.openapidiff.core.model.ChangedOpenApi
import sbt._

trait OpenApiDiffKeys {

final val openApiDiff = taskKey[ChangedOpenApi]("Compute the OpenAPI diff.")

final val openApiDiffFiles = taskKey[(File, File)]("OpenAPI specification files to diff.")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2020 OpenAPI-Generator Contributors (https://openapi-generator.tech)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.openapitools.generator.sbt.plugin

import org.openapitools.openapidiff.core.OpenApiCompare
import sbt.Def
import sbt.plugins.JvmPlugin

object OpenApiDiffPlugin extends sbt.AutoPlugin with OpenApiDiffKeys {
self =>

override def requires: JvmPlugin.type = sbt.plugins.JvmPlugin

override def trigger: sbt.PluginTrigger = noTrigger

object autoImport extends OpenApiDiffKeys

override lazy val projectSettings: Seq[Def.Setting[_]] = Seq(
openApiDiffFiles := {
sys.error("openApiDiffFiles is undefined. Did you forget to set it?")
},
openApiDiff := {
val (doc1, doc2) = openApiDiffFiles.value
OpenApiCompare.fromFiles(doc1, doc2)
}
)
}
21 changes: 21 additions & 0 deletions src/sbt-test/sbt-openapi-generator/simple/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
lazy val noop = project

lazy val same = project
.enablePlugins(OpenApiDiffPlugin)
.settings(openApiDiffFiles := (file("petstore.v1.yaml"), file("petstore.v1.yaml")))
.settings(
TaskKey[Unit]("check") := {
if (openApiDiff.value.isDifferent) sys.error("OpenAPI specs were not the same")
()
}
)

lazy val incompatible = project
.enablePlugins(OpenApiDiffPlugin)
.settings(openApiDiffFiles := (file("petstore.v1.yaml"), file("petstore.v2.yaml")))
.settings(
TaskKey[Unit]("check") := {
if (openApiDiff.value.isCompatible) sys.error("OpenAPI specs were compatible")
()
}
)
Loading

0 comments on commit 647236f

Please sign in to comment.