-
@Override
-public Collection<Contract> convertFrom(File file) {
- try {
- YamlContract yamlContract = new Yaml().loadAs(new FileInputStream(file), YamlContract.class)
- return [Contract.make {
- request {
- method(yamlContract?.request?.method)
- url(yamlContract?.request?.url)
- headers {
- yamlContract?.request?.headers?.each { String key, Object value ->
- header(key, value)
- }
- }
- body(yamlContract?.request?.body)
- }
- response {
- status(yamlContract?.response?.status)
- headers {
- yamlContract?.response?.headers?.each { String key, Object value ->
- header(key, value)
- }
- }
- body(yamlContract?.response?.body)
- }
- }]
+class YamlContractConverter implements ContractConverter<List<YamlContract>> {
+
+ @Override
+ public boolean isAccepted(File file) {
+ String name = file.getName()
+ return name.endsWith(".yml") || name.endsWith(".yaml")
}
- catch (FileNotFoundException e) {
- throw new IllegalStateException(e)
+
+ @Override
+ public Collection<Contract> convertFrom(File file) {
+ try {
+ YamlContract yamlContract = new Yaml().loadAs(new FileInputStream(file), YamlContract.class)
+ return [Contract.make {
+ request {
+ method(yamlContract?.request?.method)
+ url(yamlContract?.request?.url)
+ headers {
+ yamlContract?.request?.headers?.each { String key, Object value ->
+ header(key, value)
+ }
+ }
+ body(yamlContract?.request?.body)
+ }
+ response {
+ status(yamlContract?.response?.status)
+ headers {
+ yamlContract?.response?.headers?.each { String key, Object value ->
+ header(key, value)
+ }
+ }
+ body(yamlContract?.response?.body)
+ }
+ }]
+ }
+ catch (FileNotFoundException e) {
+ throw new IllegalStateException(e)
+ }
}
-}
-