Skip to content

Commit d433af7

Browse files
committed
use mapping.yaml in integration tests
1 parent 9432abb commit d433af7

11 files changed

Lines changed: 45 additions & 18 deletions

File tree

src/main/groovy/com/github/hauner/openapi/spring/converter/ApiOptions.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ApiOptions {
4444
* - interfaces => "${packageName}.api"
4545
* - models => "${packageName}.model"
4646
*/
47-
String packageName
47+
String packageName = 'generatr'
4848

4949
/**
5050
* provide enabling Bean Validation (JSR303) annotations. Default is false (disabled)
@@ -62,6 +62,6 @@ class ApiOptions {
6262
* override parameter/response type mappings or to add additional parameters on a single
6363
* endpoint.
6464
*/
65-
List<Mapping> typeMappings
65+
List<Mapping> typeMappings = []
6666

6767
}

src/testInt/groovy/com/github/hauner/openapi/generatr/GeneratrEndToEndTest.groovy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package com.github.hauner.openapi.generatr
1919
import org.junit.runner.RunWith
2020
import org.junit.runners.Parameterized
2121

22-
2322
/**
2423
* using Junit so IDEA adds a "<Click to see difference>" when using assertEquals().
2524
*/
@@ -44,7 +43,7 @@ class GeneratrEndToEndTest extends GeneratrTestBase {
4443
new TestSet(name: 'response-array-data-type-mapping'),
4544
new TestSet(name: 'response-complex-data-types'),
4645
new TestSet(name: 'response-simple-data-types'),
47-
new TestSet(name: 'bean-validation', beanValidation: true)
46+
new TestSet(name: 'bean-validation')
4847
]
4948
}
5049

src/testInt/groovy/com/github/hauner/openapi/generatr/GeneratrTestBase.groovy

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 the original authors
2+
* Copyright 2019-2020 the original authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,7 +18,9 @@ package com.github.hauner.openapi.generatr
1818

1919
import com.github.difflib.DiffUtils
2020
import com.github.difflib.UnifiedDiffUtils
21+
import com.github.hauner.openapi.spring.generatr.MappingReader
2122
import com.github.hauner.openapi.spring.generatr.SpringGeneratr
23+
import com.github.hauner.openapi.spring.generatr.mapping.Mapping
2224
import groovy.io.FileType
2325
import org.junit.Rule
2426
import org.junit.Test
@@ -32,6 +34,11 @@ abstract class GeneratrTestBase {
3234
@Rule
3335
public TemporaryFolder folder = new TemporaryFolder()
3436

37+
String DEFAULT_OPTIONS = """\
38+
options:
39+
package-name: generated
40+
""";
41+
3542
TestSet testSet
3643

3744
GeneratrTestBase(TestSet testSet) {
@@ -41,23 +48,27 @@ abstract class GeneratrTestBase {
4148
@Test
4249
void "generatr creates expected files for api set "() {
4350
def source = testSet.name
44-
def packageName = 'generated'
45-
def expectedPath = ['.', 'src', 'testInt', 'resources', source, packageName].join(File.separator)
46-
def generatedPath = [folder.root.absolutePath, packageName].join(File.separator)
4751

4852
def generatr = new SpringGeneratr()
4953
def options = [
5054
apiPath: "./src/testInt/resources/${source}/openapi.yaml",
51-
targetDir: folder.root,
52-
packageName: packageName,
53-
beanValidation: testSet.beanValidation
55+
targetDir: folder.root
5456
]
5557

56-
def mapping = new File("./src/testInt/resources/${source}/mapping.yaml")
57-
if(mapping.exists ()) {
58-
options.typeMappings = mapping
58+
def mappingYaml = new File("./src/testInt/resources/${source}/mapping.yaml")
59+
if(mappingYaml.exists ()) {
60+
options.mapping = mappingYaml
61+
} else {
62+
options.mapping = DEFAULT_OPTIONS
5963
}
6064

65+
def reader = new MappingReader ()
66+
Mapping mapping = reader.read (options.mapping as String)
67+
68+
def packageName = mapping.options.packageName
69+
def expectedPath = ['.', 'src', 'testInt', 'resources', source, packageName].join(File.separator)
70+
def generatedPath = [folder.root.absolutePath, packageName].join(File.separator)
71+
6172
when:
6273
generatr.run (options)
6374

src/testInt/groovy/com/github/hauner/openapi/generatr/TestSet.groovy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package com.github.hauner.openapi.generatr
1818

1919
class TestSet {
2020
String name
21-
boolean beanValidation = false
2221

2322
@Override
2423
String toString () {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
options:
2+
package-name: generated
3+
bean-validation: true

src/testInt/resources/endpoint-exclude/mapping.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
options:
2+
package-name: generated
3+
14
map:
25
paths:
36
/endpoint-exclude/{foo}:

src/testInt/resources/params-additional/mapping.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
options:
2+
package-name: generated
3+
14
map:
25
paths:
36
/foo:

src/testInt/resources/params-complex-data-types/mapping.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
map:
1+
options:
2+
package-name: generated
23

4+
map:
35
paths:
46

57
/endpoint-map:
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
map:
1+
options:
2+
package-name: generated
23

4+
map:
35
types:
46
- from: string:binary
57
to: org.springframework.web.multipart.MultipartFile

src/testInt/resources/params-spring-pageable-mapping/mapping.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
map:
1+
options:
2+
package-name: generated
23

4+
map:
35
types:
46
- from: Pageable
57
to: org.springframework.data.domain.Pageable

0 commit comments

Comments
 (0)