Skip to content

Commit

Permalink
feat #178
Browse files Browse the repository at this point in the history
- support relative base url
  • Loading branch information
BalloonWen committed Apr 12, 2021
1 parent 957da5c commit 9461c4b
Show file tree
Hide file tree
Showing 3 changed files with 870 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@

import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.BiFunction;

/**
Expand Down Expand Up @@ -144,9 +147,14 @@ private String getBasePath() {
if (url != null) {
// find "://" index
int protocolIndex = url.indexOf("://");
int pathIndex = url.indexOf('/', protocolIndex + 3);
if (pathIndex > 0) {
basePath = url.substring(pathIndex);
if (protocolIndex != -1) {
int pathIndex = url.indexOf('/', protocolIndex + 3);
if (pathIndex > 0) {
basePath = url.substring(pathIndex);
}
} else {
// support openapi Relative URLs
basePath = url.startsWith("/") ? url : "";
}
}
return basePath;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.networknt.openapi;

import com.networknt.config.Config;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class BasePathTest {
@Before
public void testOAuth2Name() {
String spec = Config.getInstance().getStringFromFile("openapi-relative-server-url.yaml");
OpenApiHelper.init(spec);
}
@Test
public void testBasePath() {
Assert.assertEquals("/api/v1", OpenApiHelper.basePath);
}
}
Loading

0 comments on commit 9461c4b

Please sign in to comment.