-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
1,284 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/main/scala/org/openapitools/generator/sbt/plugin/OpenApiDiffKeys.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/scala/org/openapitools/generator/sbt/plugin/OpenApiDiffPlugin.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
() | ||
} | ||
) |
Oops, something went wrong.