Skip to content

Commit

Permalink
[Scala][sttp] various improvements (OpenAPITools#5475)
Browse files Browse the repository at this point in the history
* various improvements to scala sttp

* update ScalaSttpClientCodegen.java

* add windows batch file

* test scala sttp in jdk8

* fix tempalte directory
  • Loading branch information
wing328 authored and MikailBag committed Mar 23, 2020
1 parent b7ba8d1 commit 41344af
Show file tree
Hide file tree
Showing 44 changed files with 78 additions and 111 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ OpenAPI Generator allows generation of API client libraries (SDK generation), se

| | Languages/Frameworks |
|-|-|
**API clients** | **ActionScript**, **Ada**, **Apex**, **Bash**, **C**, **C#** (.net 2.0, 3.5 or later, .NET Standard 1.3 - 2.0, .NET Core 2.0), **C++** (cpp-restsdk, Qt5, Tizen), **Clojure**, **Dart (1.x, 2.x)**, **Elixir**, **Elm**, **Eiffel**, **Erlang**, **Go**, **Groovy**, **Haskell** (http-client, Servant), **Java** (Jersey1.x, Jersey2.x, OkHttp, Retrofit1.x, Retrofit2.x, Feign, RestTemplate, RESTEasy, Vertx, Google API Client Library for Java, Rest-assured, Spring 5 Web Client, MicroProfile Rest Client), **k6**, **Kotlin**, **Lua**, **Nim**, **Node.js/JavaScript** (ES5, ES6, AngularJS with Google Closure Compiler annotations, Flow types), **Objective-C**, **OCaml**, **Perl**, **PHP**, **PowerShell**, **Python**, **R**, **Ruby**, **Rust** (rust, rust-server), **Scala** (akka, http4s, scalaz, swagger-async-httpclient), **Swift** (2.x, 3.x, 4.x, 5.x), **Typescript** (AngularJS, Angular (2.x - 8.x), Aurelia, Axios, Fetch, Inversify, jQuery, Node, Rxjs)
**API clients** | **ActionScript**, **Ada**, **Apex**, **Bash**, **C**, **C#** (.net 2.0, 3.5 or later, .NET Standard 1.3 - 2.0, .NET Core 2.0), **C++** (cpp-restsdk, Qt5, Tizen), **Clojure**, **Dart (1.x, 2.x)**, **Elixir**, **Elm**, **Eiffel**, **Erlang**, **Go**, **Groovy**, **Haskell** (http-client, Servant), **Java** (Jersey1.x, Jersey2.x, OkHttp, Retrofit1.x, Retrofit2.x, Feign, RestTemplate, RESTEasy, Vertx, Google API Client Library for Java, Rest-assured, Spring 5 Web Client, MicroProfile Rest Client), **k6**, **Kotlin**, **Lua**, **Nim**, **Node.js/JavaScript** (ES5, ES6, AngularJS with Google Closure Compiler annotations, Flow types), **Objective-C**, **OCaml**, **Perl**, **PHP**, **PowerShell**, **Python**, **R**, **Ruby**, **Rust** (rust, rust-server), **Scala** (akka, http4s, scalaz, sttp, swagger-async-httpclient), **Swift** (2.x, 3.x, 4.x, 5.x), **Typescript** (AngularJS, Angular (2.x - 8.x), Aurelia, Axios, Fetch, Inversify, jQuery, Node, Rxjs)
**Server stubs** | **Ada**, **C#** (ASP.NET Core, NancyFx), **C++** (Pistache, Restbed, Qt5 QHTTPEngine), **Erlang**, **F#** (Giraffe), **Go** (net/http, Gin), **Haskell** (Servant), **Java** (MSF4J, Spring, Undertow, JAX-RS: CDI, CXF, Inflector, Jersey, RestEasy, Play Framework, [PKMST](https://github.com/ProKarma-Inc/pkmst-getting-started-examples), [Vert.x](https://vertx.io/)), **Kotlin** (Spring Boot, Ktor, Vertx), **PHP** (Laravel, Lumen, Slim, Silex, [Symfony](https://symfony.com/), [Zend Expressive](https://github.com/zendframework/zend-expressive)), **Python** (Flask), **NodeJS**, **Ruby** (Sinatra, Rails5), **Rust** (rust-server), **Scala** ([Finch](https://github.com/finagle/finch), [Lagom](https://github.com/lagom/lagom), [Play](https://www.playframework.com/), Scalatra)
**API documentation generators** | **HTML**, **Confluence Wiki**, **Asciidoc**
**Configuration files** | [**Apache2**](https://httpd.apache.org/)
Expand Down Expand Up @@ -814,6 +814,7 @@ Here is a list of template creators:
* Rust (rust-server): @metaswitch
* Scala (scalaz & http4s): @tbrown1979
* Scala (Akka): @cchafer
* Scala (sttp): @chameleon82
* Swift: @tkqubo
* Swift 3: @hexelon
* Swift 4: @ehyche
Expand Down
2 changes: 1 addition & 1 deletion bin/openapi3/scala-sttp-petstore.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ fi

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="generate --artifact-id "scala-sttp-petstore-client" -t modules/openapi-generator/src/main/resources/scala-sttp-client -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g scala-sttp -o samples/client/petstore/scala-sttp $@"
ags="generate --artifact-id 'scala-sttp-petstore' -t modules/openapi-generator/src/main/resources/scala-sttp -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g scala-sttp -o samples/openapi3/client/petstore/scala-sttp $@"

java $JAVA_OPTS -jar $executable $ags
10 changes: 10 additions & 0 deletions bin/openapi3/windows/scala-sttp-petstore.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar

If Not Exist %executable% (
mvn clean package
)

REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties
set ags=generate --artifact-id "scala-sttp-petstore" -t modules\openapi-generator\src\main\resources\scala-sttp -i modules\openapi-generator\src\test\resources\3_0\petstore.yaml -g scala-sttp -o samples\openapi3\client\petstore\scala-sttp

java %JAVA_OPTS% -jar %executable% %ags%
2 changes: 1 addition & 1 deletion docs/generators.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ The following generators are available:
* [scala-akka](generators/scala-akka.md)
* [scala-gatling](generators/scala-gatling.md)
* [scala-httpclient-deprecated (deprecated)](generators/scala-httpclient-deprecated.md)
* [scala-sttp](generators/scala-sttp.md)
* [scala-sttp (beta)](generators/scala-sttp.md)
* [scalaz](generators/scalaz.md)
* [swift2-deprecated (deprecated)](generators/swift2-deprecated.md)
* [swift3-deprecated (deprecated)](generators/swift3-deprecated.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
/*
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.openapitools.codegen.languages;

import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.servers.Server;
import org.openapitools.codegen.CodegenConfig;
import org.openapitools.codegen.CodegenOperation;
import org.openapitools.codegen.SupportingFile;
import org.openapitools.codegen.meta.GeneratorMetadata;
import org.openapitools.codegen.meta.Stability;

import java.io.File;
import java.util.List;
Expand All @@ -14,8 +32,13 @@ public class ScalaSttpClientCodegen extends ScalaAkkaClientCodegen implements Co

public ScalaSttpClientCodegen() {
super();
}
generatorMetadata = GeneratorMetadata.newBuilder(generatorMetadata)
.stability(Stability.BETA)
.build();

embeddedTemplateDir = templateDir = "scala-sttp";
outputFolder = "generated-code/scala-sttp";
}

@Override
public void processOpts() {
Expand Down Expand Up @@ -52,13 +75,13 @@ public String getName() {

@Override
public String getHelp() {
return "Generates a Scala client library base on Sttp.";
return "Generates a Scala client library (beta) based on Sttp.";
}

@Override
public String encodePath(String input) {
String result = super.encodePath(input);
return result.replace("{","${");
return result.replace("{", "${");
}

@Override
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,7 @@
<module>samples/openapi3/client/petstore/go</module>
<!-- test java-related projects -->
<!--<module>samples/client/petstore/scala-akka</module>-->
<module>samples/openapi3/client/petstore/scala-sttp</module>
<module>samples/client/petstore/scala-httpclient</module>
<module>samples/client/petstore/scalaz</module>
<module>samples/client/petstore/clojure</module>
Expand Down

This file was deleted.

99 changes: 0 additions & 99 deletions samples/client/petstore/scala-sttp/src/test/scala/PetApiTest.scala

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# scala-sttp-petstore-client
# &#39;scala-sttp-petstore&#39;

OpenAPI Petstore
- API version: 1.0.0
Expand Down Expand Up @@ -37,7 +37,7 @@ Add this dependency to your project's POM:
```xml
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>scala-sttp-petstore-client</artifactId>
<artifactId>'scala-sttp-petstore'</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
Expand All @@ -48,13 +48,13 @@ Add this dependency to your project's POM:
Add this dependency to your project's build file:

```groovy
compile "org.openapitools:scala-sttp-petstore-client:1.0.0"
compile "org.openapitools:'scala-sttp-petstore':1.0.0"
```

### SBT users

```scala
libraryDependencies += "org.openapitools" % "scala-sttp-petstore-client" % "1.0.0"
libraryDependencies += "org.openapitools" % "'scala-sttp-petstore'" % "1.0.0"
```

## Getting Started
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version := "1.0.0"
name := "scala-sttp-petstore-client"
name := "&#39;scala-sttp-petstore&#39;"
organization := "org.openapitools"

scalaVersion := "2.13.0"
Expand Down
32 changes: 32 additions & 0 deletions samples/openapi3/client/petstore/scala-sttp/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.openapitools</groupId>
<artifactId>scalaz-sttp-petstore-client</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>scala-sttp-petstore-client</name>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
<executions>
<execution>
<id>sbt-test</id>
<phase>integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>sbt</executable>
<arguments>
<argument>test</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

0 comments on commit 41344af

Please sign in to comment.