Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into refactor-php-client…
Browse files Browse the repository at this point in the history
…-generator
  • Loading branch information
ackintosh committed Jul 9, 2018
2 parents 9672fa6 + 86a0445 commit a1e7a8e
Show file tree
Hide file tree
Showing 122 changed files with 6,419 additions and 2,873 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ samples/client/petstore/python/swagger_client.egg-info/SOURCES.txt
samples/client/petstore/python/.coverage
samples/client/petstore/python/.projectile
samples/client/petstore/python/.venv/
samples/client/petstore/python-asyncio/.venv/
samples/client/petstore/python-asyncio/.pytest_cache/
samples/client/petstore/python-tornado/.venv/

# ts
samples/client/petstore/typescript-node/npm/node_modules
Expand Down
4 changes: 2 additions & 2 deletions bin/utils/ensure-up-to-date
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ sleep 5
./bin/kotlin-client-petstore.sh > /dev/null 2>&1
./bin/kotlin-client-string.sh > /dev/null 2>&1
./bin/kotlin-client-threetenbp.sh > /dev/null 2>&1
./bin/kotlin-server-petstore.shl> /dev/null 2>&1
./bin/kotlin-server-petstore.sh > /dev/null 2>&1
./bin/php-petstore.sh > /dev/null 2>&1
./bin/php-silex-petstore-server.shj> /dev/null 2>&1
./bin/php-silex-petstore-server.sh > /dev/null 2>&1
./bin/php-symfony-petstore.sh > /dev/null 2>&1
./bin/php-lumen-petstore-server.sh > /dev/null 2>&1
./bin/php-slim-petstore-server.sh > /dev/null 2>&1
Expand Down
196 changes: 196 additions & 0 deletions bin/utils/release_checkout.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
#release_chekcout.rb
require 'rubygems'
require 'open-uri'
require 'net/http'

def check_homebrew
print "Checking homebrew forumla ... "

url = "https://github.com/raw/Homebrew/homebrew-core/master/Formula/openapi-generator.rb"
new_maven_url = "https://search.maven.org/remotecontent?filepath=org/openapitools/openapi-generator-cli/#{$version}/openapi-generator-cli-#{$version}.jar"
open(url) do |f|
content = f.read
if !content.nil? && content.include?(new_maven_url)
puts "[OK]"
else
puts "[ERROR]"
puts "> #{url} not yet updated with #{new_maven_url}"
end
end
end

def check_openapi_generator_online_docker
print "Checking openapi-generator-online docker ... "

url = "https://hub.docker.com/r/openapitools/openapi-generator-online/tags/"
docker_tag = "v#{$version}"
open(url) do |f|
content = f.read
if !content.nil? && content.include?(docker_tag)
puts "[OK]"
else
puts "[ERROR]"
puts "> #{url} does not have tag #{docker_tag}"
end
end
end

def check_openapi_generator_cli_docker
print "Checking openapi-generator-cli docker ... "

url = "https://hub.docker.com/r/openapitools/openapi-generator-cli/tags/"
docker_tag = "v#{$version}"
open(url) do |f|
content = f.read
if !content.nil? && content.include?(docker_tag)
puts "[OK]"
else
puts "[ERROR]"
puts "> #{url} does not have tag #{docker_tag}"
end
end
end

def check_readme
print "Checking openapi-generator README.md ... "

url = "https://github.com/raw/OpenAPITools/openapi-generator/master/README.md"
matches = ["[#{$version}](https://github.com/OpenAPITools/openapi-generator/releases/tag/v#{$version})",
"JAR location: `http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/#{$version}/openapi-generator-cli-#{$version}.jar`",
"wget http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/#{$version}/openapi-generator-cli-#{$version}.jar -O openapi-generator-cli.jar",
"Invoke-WebRequest -OutFile openapi-generator-cli.jar http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/#{$version}/openapi-generator-cli-#{$version}.jar"]
open(url) do |f|
content = f.read
has_outdated = false
not_matched = []
matches.each do |match|
if !content.nil? && content.include?(match)
# matched
else
has_outdated = true
not_matched << match
end
end

if has_outdated
puts "[ERROR]"
not_matched.each do |str|
puts "> '#{str}' not found in README.md"
end
else
puts "[OK]"
end
end
end

def check_openapi_generator_jar
print "Checking openapi-generator JAR ... "
url = "http://central.maven.org/maven2/org/openapitools/openapi-generator/#{$version}/openapi-generator-#{$version}.jar"

if check_url(url)
puts "[OK]"
else
puts "[ERROR]"
puts "> #{url} not found"
end

end


def check_openapi_generator_cli_jar
print "Checking openapi-generator-cli JAR ... "
url = "http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/#{$version}/openapi-generator-cli-#{$version}.jar"

if check_url(url)
puts "[OK]"
else
puts "[ERROR]"
puts "> #{url} not found"
end
end

def check_openapi_generator_maven_plugin_jar
print "Checking openapi-generator-maven-plugin JAR ... "
url = "http://central.maven.org/maven2/org/openapitools/openapi-generator-maven-plugin/#{$version}/openapi-generator-maven-plugin-#{$version}.jar"

if check_url(url)
puts "[OK]"
else
puts "[ERROR]"
puts "> #{url} not found"
end
end

def check_openapi_generator_gradle_plugin_jar
print "Checking openapi-generator-gradle-plugin JAR ... "
url = "http://central.maven.org/maven2/org/openapitools/openapi-generator-gradle-plugin/#{$version}/openapi-generator-gradle-plugin-#{$version}.jar"

if check_url(url)
puts "[OK]"
else
puts "[ERROR]"
puts "> #{url} not found"
end
end

def check_openapi_generator_online_jar
print "Checking openapi-generator-online JAR ... "
url = "http://central.maven.org/maven2/org/openapitools/openapi-generator-online/#{$version}/openapi-generator-online-#{$version}.jar"

if check_url(url)
puts "[OK]"
else
puts "[ERROR]"
puts "> #{url} not found"
end
end

def check_openapi_generator_project_pom
print "Checking openapi-generator-project pom.xml ... "
url = "http://central.maven.org/maven2/org/openapitools/openapi-generator-project/#{$version}/openapi-generator-project-#{$version}.pom"

if check_url(url)
puts "[OK]"
else
puts "[ERROR]"
puts "> #{url} not found"
end
end

def check_url url
content = Net::HTTP.get(URI.parse(url))
url = URI.parse(url)
req = Net::HTTP.new(url.host, url.port)
res = req.request_head(url.path)
if res.code == "200"
true
else
false
end
end

def usage
puts "ERROR!! Version (e.g. 3.0.2) missing"
puts "Usage example: ruby #{$0} 3.0.2"
end


if (!ARGV[0])
usage
exit
end

$version = ARGV[0]

puts "Running checkout on OpenAPI Generator release #{$version}"

check_homebrew
check_openapi_generator_jar
check_openapi_generator_cli_jar
check_openapi_generator_maven_plugin_jar
check_openapi_generator_gradle_plugin_jar
check_openapi_generator_online_jar
check_openapi_generator_project_pom
check_readme
check_openapi_generator_online_docker
check_openapi_generator_cli_docker
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import io.airlift.airline.Cli;
import io.airlift.airline.Help;
import io.airlift.airline.ParseArgumentsUnexpectedException;
import io.airlift.airline.ParseOptionMissingException;
import io.airlift.airline.ParseOptionMissingValueException;
import org.openapitools.codegen.cmd.*;
Expand Down Expand Up @@ -67,6 +68,9 @@ public static void main(String[] args) {
if (args.length == 0) {
System.exit(1);
}
} catch (ParseArgumentsUnexpectedException e) {
System.err.printf("[error] %s%n%nSee 'openapi-generator-cli help' for usage.%n", e.getMessage());
System.exit(1);
} catch (ParseOptionMissingException | ParseOptionMissingValueException e) {
System.err.printf("[error] %s%n", e.getMessage());
System.exit(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,21 @@ public static String getHost(OpenAPI openAPI) {
}

private static String sanitizeUrl(String url) {
if (url.startsWith("/")) {
LOGGER.warn("'host' not defined in the spec (2.0). Default to " + LOCAL_HOST);
if (url.startsWith("//")) {
url = "http:" + url;
LOGGER.warn("'scheme' not defined in the spec (2.0). Default to [http] for server URL [{}]", url);
} else if (url.startsWith("/")) {
url = LOCAL_HOST + url;
LOGGER.warn("'host' not defined in the spec (2.0). Default to [{}] for server URL [{}]", LOCAL_HOST, url);
} else if (!url.matches("[a-zA-Z][0-9a-zA-Z.+\\-]+://.+")) {
// Add http scheme for urls without a scheme.
// 2.0 spec is restricted to the following schemes: "http", "https", "ws", "wss"
// 3.0 spec does not have an enumerated list of schemes
// This regex attempts to capture all schemes in IANA example schemes which
// can have alpha-numeric characters and [.+-]. Examples are here:
// https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml
url = "http://" + url;
LOGGER.warn("'scheme' not defined in the spec (2.0). Default to [http] for server URL [{}]", url);
}

return url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,9 @@ func CacheExpires(r *http.Response) time.Time {
lifetime, err := time.ParseDuration(maxAge + "s")
if err != nil {
expires = now
} else {
expires = now.Add(lifetime)
}
expires = now.Add(lifetime)
} else {
expiresHeader := r.Header.Get("Expires")
if expiresHeader != "" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,24 @@ public void testUrl() throws Exception {
Assert.assertEquals(URLPathUtils.getPort(serverURL, "8081"), "9999");
Assert.assertEquals(URLPathUtils.getPath(serverURL, "/abc"), "/some/path");
}

@Test
public void testSanitizeUrl() throws Exception {
String[][] testData = {
{ "https://abc1.xyz:9999/some/path", "https://abc1.xyz:9999/some/path" },
{ "HTTPS://abc2.xyz:9999/some/path", "https://abc2.xyz:9999/some/path" },
{ "http://abc3.xyz:9999/some/path", "http://abc3.xyz:9999/some/path" },
{ "HTTP://abc4.xyz:9999/some/path", "http://abc4.xyz:9999/some/path" },
{ "//abc5.xyz:9999/some/path", "http://abc5.xyz:9999/some/path" },
{ "abc6.xyz:9999/some/path", "http://abc6.xyz:9999/some/path" },
{ "localhost:9000/api", "http://localhost:9000/api" },
{ "/some/path", "http://localhost/some/path" } };

for (String[] t:testData) {
OpenAPI openAPI = new OpenAPI();
openAPI.addServersItem(new Server().url(t[0]));

Assert.assertEquals(URLPathUtils.getServerURL(openAPI).toString(), t[1]);
}
}
}
Loading

0 comments on commit a1e7a8e

Please sign in to comment.