-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support reading from a configuration file. (#2)
* Support reading from a configuration file. * update docs for naming conventions
- Loading branch information
Showing
11 changed files
with
244 additions
and
82 deletions.
There are no files selected for viewing
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
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
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
56 changes: 22 additions & 34 deletions
56
src/main/scala/org/openapitools/openapistylevalidator/sbt/plugin/OpenApiStylePlugin.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
25 changes: 25 additions & 0 deletions
25
...main/scala/org/openapitools/openapistylevalidator/sbt/plugin/config/ConfigExtension.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,25 @@ | ||
package org.openapitools.openapistylevalidator.sbt.plugin.config | ||
|
||
import com.typesafe.config.Config | ||
|
||
private[plugin] object ConfigExtension { | ||
|
||
implicit class RichConfig(val underlying: Config) extends AnyVal { | ||
def getOptionalBoolean(path: String): Option[Boolean] = { | ||
if (underlying.hasPath(path)) { | ||
Some(underlying.getBoolean(path)) | ||
} else { | ||
None | ||
} | ||
} | ||
|
||
def getOptionalString(path: String): Option[String] = { | ||
if (underlying.hasPath(path)) { | ||
Some(underlying.getString(path)) | ||
} else { | ||
None | ||
} | ||
} | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
...la/org/openapitools/openapistylevalidator/sbt/plugin/tasks/OpenApiStyleValidateTask.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,19 @@ | ||
package org.openapitools.openapistylevalidator.sbt.plugin.tasks | ||
|
||
import org.openapitools.openapistylevalidator.sbt.plugin.OpenApiStyleKeys | ||
import sbt.Keys._ | ||
import sbt.{Def, Task} | ||
|
||
trait OpenApiStyleValidateTask extends OpenApiStyleKeys { | ||
|
||
def openApiStyleValidateTask(): Def.Initialize[Task[Unit]] = Def.task { | ||
val log = streams.value.log | ||
val errors = openApiStyleValidationResult.value | ||
|
||
if (errors.nonEmpty) { | ||
val report = errors.mkString("\n") | ||
sys.error("OpenAPI specification style validation failed.\n" + report) | ||
} else log.info("OpenAPI specification style validation passed.") | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
...penapitools/openapistylevalidator/sbt/plugin/tasks/OpenApiStyleValidationResultTask.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,31 @@ | ||
package org.openapitools.openapistylevalidator.sbt.plugin.tasks | ||
|
||
import io.swagger.v3.parser.OpenAPIV3Parser | ||
import org.openapitools.empoa.swagger.core.internal.SwAdapter | ||
import org.openapitools.openapistylevalidator.OpenApiSpecStyleValidator | ||
import org.openapitools.openapistylevalidator.sbt.plugin.OpenApiStyleKeys | ||
import org.openapitools.openapistylevalidator.styleerror.StyleError | ||
import sbt.{Def, Task} | ||
|
||
import java.util.function.Consumer | ||
import scala.collection.mutable.ListBuffer | ||
|
||
trait OpenApiStyleValidationResultTask extends OpenApiStyleKeys { | ||
|
||
def openApiStyleValidationResultTask(): Def.Initialize[Task[List[String]]] = Def.task { | ||
val parameters = openApiStyleValidatorParameters.value | ||
|
||
val swaggerOpenApiParser = new OpenAPIV3Parser() | ||
val swaggerOpenApi = swaggerOpenApiParser.read(openApiStyleSpec.value.getAbsolutePath) | ||
|
||
val openApi = SwAdapter.toOpenAPI(swaggerOpenApi) | ||
val validator = new OpenApiSpecStyleValidator(openApi) | ||
|
||
val errors = ListBuffer.empty[String] | ||
validator.validate(parameters).forEach(new Consumer[StyleError] { | ||
override def accept(error: StyleError): Unit = errors += error.toString | ||
}) | ||
errors.toList | ||
} | ||
|
||
} |
113 changes: 72 additions & 41 deletions
113
...apitools/openapistylevalidator/sbt/plugin/tasks/OpenApiStyleValidatorParametersTask.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
Oops, something went wrong.