Skip to content

Commit 3b52b49

Browse files
fix Openapi dir resolving (#2941)
* Handle file URIs in OpenAPI directory resolution and add test for relative directory support. * Simplify OpenAPI directory resolution by reducing redundant code in `getOpenAPIFiles`.
1 parent 6662056 commit 3b52b49

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ private boolean toYesNo(OpenAPISpec.YesNoOpenAPIOption option) {
280280
}
281281

282282
private File[] getOpenAPIFiles(String directoryName) {
283-
File dir = new File(directoryName);
283+
File dir = new File(pathFromFileURI(resolve(directoryName)));
284284
if (!dir.exists() || !dir.isDirectory()) {
285285
throw new ConfigurationException(format("Cannot open directory %s. Please check the OpenAPI configuration of your API.", dir.getAbsolutePath()));
286286
}

core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordFactoryTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ void referencesDepth() {
123123
assertNotNull(getMail(rec));
124124
}
125125

126+
@Test
127+
void readsDirectoryRelativeToBaseLocation() {
128+
OpenAPISpec spec = new OpenAPISpec();
129+
spec.setDir("paths");
130+
131+
Map<String, OpenAPIRecord> recs = factory.create(singletonList(spec));
132+
133+
assertEquals(3, recs.size());
134+
assertTrue(recs.containsKey("api-b-path-foo-v1-0"));
135+
assertTrue(recs.keySet().stream().anyMatch(id -> id.startsWith("api-a-path-foo-v1-0")));
136+
}
137+
126138
@Test
127139
void getUniqueIdNoCollision() {
128140
assertEquals("customers-api-v1-0", factory.getUniqueId(new HashMap<>(), new OpenAPIRecord(getApi(this, "/openapi/specs/customers.yml"), null)));
@@ -134,4 +146,4 @@ void getUniqueIdCollision() {
134146
recs.put("customers-api-v1-0", new OpenAPIRecord());
135147
assertEquals("customers-api-v1-0-0", factory.getUniqueId(recs, new OpenAPIRecord(getApi(this, "/openapi/specs/customers.yml"), null)));
136148
}
137-
}
149+
}

0 commit comments

Comments
 (0)