Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
f266380
First version of Nim Client
hokamoto Sep 1, 2019
18d367a
Add some codes
hokamoto Sep 5, 2019
9639569
Add some codes
hokamoto Sep 5, 2019
a999b5e
Add some codes
hokamoto Sep 8, 2019
5d73b11
Add some codes
hokamoto Sep 8, 2019
3880039
Add some codes
hokamoto Sep 12, 2019
c48f0a0
First version of Nim Client
hokamoto Sep 1, 2019
c5e4713
Add some codes
hokamoto Sep 5, 2019
feb96b1
Add some codes
hokamoto Sep 5, 2019
5fdc0ab
Add some codes
hokamoto Sep 8, 2019
ae33303
Add some codes
hokamoto Sep 8, 2019
ba35508
Add some codes
hokamoto Sep 12, 2019
fc74ece
[Dart] Fix README template and update testing doco (#3809)
nickmeinhold Sep 3, 2019
7b4a201
Support custom git repository (#3757)
qmuntal Sep 3, 2019
2451702
Add links to article and video (#3820)
wing328 Sep 3, 2019
9ef73eb
Better Go code format (#3819)
wing328 Sep 4, 2019
c90c6c8
Add gRPC Protobuf schema generator (#3818)
wing328 Sep 4, 2019
bdfed92
1792 fix remote spec handling and hash calculation (#3440)
Sep 4, 2019
7c5cfb7
fixed bug where nullApi.java would be generated. Instead, generated …
bensimpson-ch Sep 4, 2019
99eb680
Revert "1792 fix remote spec handling and hash calculation (#3440)"
wing328 Sep 4, 2019
ac1f19d
Add nickmeinhold to Dart technical committee (#3830)
wing328 Sep 4, 2019
9cbcebc
Bug #2845 typescript angular inheritance (#3812)
mnahkies Sep 5, 2019
9ba0dd0
fix warnings in csharp-netcore client (#3831)
wing328 Sep 5, 2019
5d21a8f
Add missing files to the form request (#3834)
etherealjoy Sep 5, 2019
8c637fb
[client][go] avoid duplicated reflect imports (#3847)
qmuntal Sep 6, 2019
f26f726
Following up for #3440 (1792 fix remote spec handling and hash calcul…
fuj1g0n Sep 6, 2019
4a1eb91
Add a link (#3850)
ackintosh Sep 7, 2019
3228ca2
Add Element AI to the list (#3856)
wing328 Sep 7, 2019
2fb08fb
maven-plugin-plugin 3.6.0 (#3854)
sullis Sep 7, 2019
221443a
[Java][okhttp-gson] fix failure to deserialize floats (#3846)
bensimpson-ch Sep 7, 2019
adf1297
Adds Http Info To Dart Api (#3851)
austbot Sep 7, 2019
86adb0a
[C++][Pistache] Add missing setter for arrays (#3837)
muttleyxd Sep 7, 2019
82f00f2
typescript-inversify: improve check for required parameters, support …
bodograumann Sep 9, 2019
0f10987
[typescript-angular] allow empty string basePath (#3489)
martinnovak Sep 9, 2019
bf441c2
Fix/r/serialization fix and minor 3xx resp fix (#3817)
Ramanth Sep 10, 2019
e51ffbe
typescript-axios: Fix baseoptions (#3866)
7474 Sep 10, 2019
0396bb4
Rename gRPC generator to "protobuf-schema" (#3864)
wing328 Sep 10, 2019
3dd0ebd
Prepare v4.1.2 release (#3873)
wing328 Sep 11, 2019
58ec946
fix version in readme
macjohnny Sep 11, 2019
580ca11
BugFix #2053 Spring Boot fails to parse LocalDate query parameter (#3…
peyerroger Sep 11, 2019
fbb3b27
update doc, samples (#3875)
wing328 Sep 11, 2019
549fc8f
update stable release
wing328 Sep 11, 2019
bface47
Update the batch for Windows
hokamoto Sep 12, 2019
5a28be0
Merge branch 'nim-client' of github.com:hokamoto/openapi-generator in…
hokamoto Sep 12, 2019
19cc13b
Merge remote-tracking branch 'upstream/master' into nim-client
hokamoto Sep 12, 2019
2db44c7
Add a test snippet
hokamoto Sep 12, 2019
bcec49b
Update ensure-up-to-date
hokamoto Sep 12, 2019
7276034
Add Nim to README.md
hokamoto Sep 12, 2019
090875b
Ran ensure-up-to-date to pass CircleCI tests
hokamoto Sep 12, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Following up for #3440 (1792 fix remote spec handling and hash calcul…
…ation) (#3826)

* This patch fixes the bug that we cannot access to remote files when checking file updates.
Following up #3440, supporting auth.

* 1792 fix remote spec handling and hash calculation (#3440)

(cherry picked from commit 2a2eefe)

* fix detecting remote file / local file logic while finding the hash file, taking care of IllegalArgumentException for local files.

* add testcase
  • Loading branch information
fuj1g0n authored and hokamoto committed Sep 12, 2019
commit f26f7262dee402ee54a93dd857c4029ecb942ed2
31 changes: 31 additions & 0 deletions modules/openapi-generator-maven-plugin/examples/java-client.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<!-- /RELEASE_VERSION -->
<executions>
<execution>
<id>default</id>
<goals>
<goal>generate</goal>
</goals>
Expand All @@ -39,6 +40,36 @@
<library>jersey2</library>
</configuration>
</execution>
<execution>
<id>remote</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<!-- specify the swagger yaml -->
<inputSpec>https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml</inputSpec>

<!-- target to generate java client code -->
<generatorName>java</generatorName>

<!-- hint: if you want to generate java server code, e.g. based on Spring Boot,
you can use the following target: <generatorName>spring</generatorName> -->

<!-- pass any necessary config options -->
<configOptions>
<dateLibrary>joda</dateLibrary>
</configOptions>

<!-- override the default library to jersey2 -->
<library>jersey2</library>

<output>${project.build.directory}/generated-sources/remote-openapi</output>
<apiPackage>remote.org.openapitools.client.api</apiPackage>
<modelPackage>remote.org.openapitools.client.model</modelPackage>
<invokerPackage>remote.org.openapitools.client</invokerPackage>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,18 @@
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
import static org.openapitools.codegen.config.CodegenConfiguratorUtils.*;

import io.swagger.v3.parser.core.models.AuthorizationValue;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -42,6 +53,7 @@
import org.openapitools.codegen.CodegenConfig;
import org.openapitools.codegen.CodegenConstants;
import org.openapitools.codegen.DefaultGenerator;
import org.openapitools.codegen.auth.AuthParser;
import org.openapitools.codegen.config.CodegenConfigurator;
import org.openapitools.codegen.config.GlobalSettings;
import org.sonatype.plexus.build.incremental.BuildContext;
Expand Down Expand Up @@ -429,7 +441,7 @@ public void execute() throws MojoExecutionException {
if (inputSpecFile.exists()) {
File storedInputSpecHashFile = getHashFile(inputSpecFile);
if(storedInputSpecHashFile.exists()) {
String inputSpecHash = Files.asByteSource(inputSpecFile).hash(Hashing.sha256()).toString();
String inputSpecHash = calculateInputSpecHash(inputSpecFile);
String storedInputSpecHash = Files.asCharSource(storedInputSpecHashFile, Charsets.UTF_8).read();
if (inputSpecHash.equals(storedInputSpecHash)) {
getLog().info(
Expand Down Expand Up @@ -720,12 +732,7 @@ public void execute() throws MojoExecutionException {

// Store a checksum of the input spec
File storedInputSpecHashFile = getHashFile(inputSpecFile);
ByteSource inputSpecByteSource =
inputSpecFile.exists()
? Files.asByteSource(inputSpecFile)
: CharSource.wrap(ClasspathHelper.loadFileFromClasspath(inputSpecFile.toString().replaceAll("\\\\","/")))
.asByteSource(Charsets.UTF_8);
String inputSpecHash =inputSpecByteSource.hash(Hashing.sha256()).toString();
String inputSpecHash = calculateInputSpecHash(inputSpecFile);

if (storedInputSpecHashFile.getParent() != null && !new File(storedInputSpecHashFile.getParent()).exists()) {
File parent = new File(storedInputSpecHashFile.getParent());
Expand All @@ -746,8 +753,75 @@ public void execute() throws MojoExecutionException {
}
}

/**
* Calculate openapi specification file hash. If specification is hosted on remote resource it is downloaded first
*
* @param inputSpecFile - Openapi specification input file to calculate it's hash.
* Does not taken into account if input spec is hosted on remote resource
* @return openapi specification file hash
* @throws IOException
*/
private String calculateInputSpecHash(File inputSpecFile) throws IOException {

URL inputSpecRemoteUrl = inputSpecRemoteUrl();

File inputSpecTempFile = inputSpecFile;

if (inputSpecRemoteUrl != null) {
inputSpecTempFile = File.createTempFile("openapi-spec", ".tmp");

URLConnection conn = inputSpecRemoteUrl.openConnection();
if (isNotEmpty(auth)) {
List<AuthorizationValue> authList = AuthParser.parse(auth);
for (AuthorizationValue auth : authList) {
conn.setRequestProperty(auth.getKeyName(), auth.getValue());
}
}
ReadableByteChannel readableByteChannel = Channels.newChannel(conn.getInputStream());

FileOutputStream fileOutputStream = new FileOutputStream(inputSpecTempFile);
FileChannel fileChannel = fileOutputStream.getChannel();

fileChannel.transferFrom(readableByteChannel, 0, Long.MAX_VALUE);
}

ByteSource inputSpecByteSource =
inputSpecTempFile.exists()
? Files.asByteSource(inputSpecTempFile)
: CharSource.wrap(ClasspathHelper.loadFileFromClasspath(inputSpecTempFile.toString().replaceAll("\\\\","/")))
.asByteSource(Charsets.UTF_8);

return inputSpecByteSource.hash(Hashing.sha256()).toString();
}

/**
* Try to parse inputSpec setting string into URL
* @return A valid URL or null if inputSpec is not a valid URL
*/
private URL inputSpecRemoteUrl(){
try {
return new URI(inputSpec).toURL();
} catch (URISyntaxException | MalformedURLException | IllegalArgumentException e) {
return null;
}
}

/**
* Get specification hash file
* @param inputSpecFile - Openapi specification input file to calculate it's hash.
* Does not taken into account if input spec is hosted on remote resource
* @return a file with previously calculated hash
*/
private File getHashFile(File inputSpecFile) {
return new File(output.getPath() + File.separator + ".openapi-generator" + File.separator + inputSpecFile.getName() + ".sha256");
String name = inputSpecFile.getName();

URL url = inputSpecRemoteUrl();
if (url != null) {
String[] segments = url.getPath().split("/");
name = Files.getNameWithoutExtension(segments[segments.length - 1]);
}

return new File(output.getPath() + File.separator + ".openapi-generator" + File.separator + name + ".sha256");
}

private String getCompileSourceRoot() {
Expand All @@ -757,8 +831,7 @@ private String getCompileSourceRoot() {
final String sourceFolder =
sourceFolderObject == null ? "src/main/java" : sourceFolderObject.toString();

String sourceJavaFolder = output.toString() + "/" + sourceFolder;
return sourceJavaFolder;
return output.toString() + "/" + sourceFolder;
}

private void addCompileSourceRootIfConfigured() {
Expand Down Expand Up @@ -803,4 +876,4 @@ private void adjustAdditionalProperties(final CodegenConfig config) {
}
}
}
}
}