Skip to content

Commit 076404c

Browse files
authored
Merge branch 'master' into fix-formdata-binary
2 parents 99765c7 + bf67367 commit 076404c

File tree

24 files changed

+244
-122
lines changed

24 files changed

+244
-122
lines changed

docs/generators/scala-sttp.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
2020
| ------ | ----------- | ------ | ------- |
2121
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
2222
|apiPackage|package for generated api classes| |null|
23+
|circeVersion|The version of circe library| |0.14.1|
2324
|dateLibrary|Option. Date library to use|<dl><dt>**joda**</dt><dd>Joda (for legacy app)</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (preferred for JDK 1.8+)</dd></dl>|java8|
2425
|disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|<dl><dt>**false**</dt><dd>The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.</dd><dt>**true**</dt><dd>Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.</dd></dl>|true|
2526
|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true|

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaSttpClientCodegen.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,16 @@ public class ScalaSttpClientCodegen extends AbstractScalaCodegen implements Code
4949
"joda-time library", "2.10.13");
5050
private static final StringProperty JSON4S_VERSION = new StringProperty("json4sVersion", "The version of json4s " +
5151
"library", "3.6.11");
52-
52+
private static final StringProperty CIRCE_VERSION = new StringProperty("circeVersion", "The version of circe " +
53+
"library", "0.14.1");
5354
private static final JsonLibraryProperty JSON_LIBRARY_PROPERTY = new JsonLibraryProperty();
5455

5556
public static final String DEFAULT_PACKAGE_NAME = "org.openapitools.client";
5657
private static final PackageProperty PACKAGE_PROPERTY = new PackageProperty();
5758

5859
private static final List<Property<?>> properties = Arrays.asList(
5960
STTP_CLIENT_VERSION, USE_SEPARATE_ERROR_CHANNEL, JODA_TIME_VERSION,
60-
JSON4S_VERSION, JSON_LIBRARY_PROPERTY, PACKAGE_PROPERTY);
61+
JSON4S_VERSION, CIRCE_VERSION, JSON_LIBRARY_PROPERTY, PACKAGE_PROPERTY);
6162

6263
private final Logger LOGGER = LoggerFactory.getLogger(ScalaSttpClientCodegen.class);
6364

modules/openapi-generator/src/main/resources/crystal/api.mustache

+7-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module {{moduleName}}
2323
{{/required}}
2424
{{/allParams}}
2525
# @return [{{{returnType}}}{{^returnType}}nil{{/returnType}}]
26-
def {{operationId}}({{#allParams}}{{paramName}} : {{{dataType}}}{{^required}}?{{/required}}{{^-last}}, {{/-last}}{{/allParams}})
26+
def {{operationId}}({{#allParams}}{{paramName}} : {{{dataType}}}{{^required}}?{{/required}}{{^required}} = nil{{/required}}{{^-last}}, {{/-last}}{{/allParams}})
2727
{{#returnType}}data, _status_code, _headers = {{/returnType}}{{operationId}}_with_http_info({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}})
2828
{{#returnType}}data{{/returnType}}{{^returnType}}nil{{/returnType}}
2929
end
@@ -40,7 +40,7 @@ module {{moduleName}}
4040
{{/required}}
4141
{{/allParams}}
4242
# @return [Array<({{{returnType}}}{{^returnType}}nil{{/returnType}}, Integer, Hash)>] {{#returnType}}{{{.}}} data{{/returnType}}{{^returnType}}nil{{/returnType}}, response status code and response headers
43-
def {{operationId}}_with_http_info({{#allParams}}{{paramName}} : {{{dataType}}}{{^required}}?{{/required}}{{^-last}}, {{/-last}}{{/allParams}})
43+
def {{operationId}}_with_http_info({{#allParams}}{{paramName}} : {{{dataType}}}{{^required}}?{{/required}}{{^required}} = nil{{/required}}{{^-last}}, {{/-last}}{{/allParams}})
4444
if @api_client.config.debugging
4545
Log.debug {"Calling API: {{classname}}.{{operationId}} ..."}
4646
end
@@ -127,10 +127,13 @@ module {{moduleName}}
127127
# resource path
128128
local_var_path = "{{{path}}}"{{#pathParams}}.sub("{" + "{{baseName}}" + "}", URI.encode_path({{paramName}}.to_s){{^strictSpecBehavior}}.gsub("%2F", "/"){{/strictSpecBehavior}}){{/pathParams}}
129129

130+
# cookie parameters
131+
cookie_params = Hash(String, String).new
132+
130133
# query parameters
131134
query_params = Hash(String, String).new
132135
{{#queryParams}}
133-
query_params["{{{baseName}}}"] = {{#collectionFormat}}@api_client.build_collection_param({{{paramName}}}, :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}.to_s unless {{{paramName}}}.nil?{{/collectionFormat}}
136+
query_params["{{{baseName}}}"] = {{#collectionFormat}}@api_client.build_collection_param({{{paramName}}}, :{{{collectionFormat}}}) unless {{{paramName}}}.nil?{{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}.to_s unless {{{paramName}}}.nil?{{/collectionFormat}}
134137
{{/queryParams}}
135138

136139
# header parameters
@@ -170,6 +173,7 @@ module {{moduleName}}
170173
auth_names,
171174
header_params,
172175
query_params,
176+
cookie_params,
173177
form_params)
174178
if @api_client.config.debugging
175179
Log.debug {"API called: {{classname}}#{{operationId}}\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}

modules/openapi-generator/src/main/resources/crystal/api_client.mustache

+6-5
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,15 @@ module {{moduleName}}
5050
# @param [Hash] header_params Header parameters
5151
# @param [Hash] query_params Query parameters
5252
# @param [String] auth_names Authentication scheme name
53-
def update_params_for_auth!(header_params, query_params, auth_names)
53+
def update_params_for_auth!(header_params, query_params, cookie_params, auth_names)
5454
auth_names.each do |auth_name|
5555
auth_setting = @config.auth_settings[auth_name]
5656
next unless auth_setting
5757
case auth_setting[:in]
5858
when "header" then header_params[auth_setting[:key]] = auth_setting[:value]
5959
when "query" then query_params[auth_setting[:key]] = auth_setting[:value]
60-
else raise ArgumentError.new("Authentication token must be in `query` of `header`")
60+
when "cookie" then cookie_params[auth_setting[:key]] = auth_setting[:value]
61+
else raise ArgumentError.new("Authentication token must be in `cookie`, `query` or `header`")
6162
end
6263
end
6364
end
@@ -119,7 +120,7 @@ module {{moduleName}}
119120
#
120121
# @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
121122
# the data deserialized from response body (could be nil), response status code and response headers.
122-
def call_api(http_method : Symbol, path : String, operation : Symbol, return_type : String?, post_body : String?, auth_names = [] of String, header_params = {} of String => String, query_params = {} of String => String, form_params = {} of Symbol => (String | ::File))
123+
def call_api(http_method : Symbol, path : String, operation : Symbol, return_type : String?, post_body : String?, auth_names = [] of String, header_params = {} of String => String, query_params = {} of String => String, cookie_params = {} of String => String, form_params = {} of Symbol => (String | ::File))
123124
#ssl_options = {
124125
# :ca_file => @config.ssl_ca_file,
125126
# :verify => @config.ssl_verify,
@@ -128,7 +129,7 @@ module {{moduleName}}
128129
# :client_key => @config.ssl_client_key
129130
#}
130131

131-
update_params_for_auth! header_params, query_params, auth_names
132+
update_params_for_auth! header_params, query_params, cookie_params, auth_names
132133

133134
if !post_body.nil? && !post_body.empty?
134135
# use JSON string in the payload
@@ -143,7 +144,7 @@ module {{moduleName}}
143144
build_request_url(path, operation),
144145
params: query_params,
145146
headers: header_params,
146-
#cookies: cookie_params, # TODO add cookies support
147+
cookies: cookie_params,
147148
form: form_or_body,
148149
logging: @config.debugging,
149150
handle_errors: false

modules/openapi-generator/src/main/resources/crystal/model.mustache

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require "big"
44
require "json"
5+
require "yaml"
56
require "time"
67

78
module {{moduleName}}

modules/openapi-generator/src/main/resources/crystal/partial_model_generic.mustache

+7-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
{{/description}}
44
class {{classname}}{{#parent}} < {{{.}}}{{/parent}}
55
include JSON::Serializable
6+
include YAML::Serializable
67

78
{{#hasRequired}}
89
# Required properties
@@ -269,16 +270,16 @@
269270
{{/vars}}
270271
# Checks equality by comparing each attribute.
271272
# @param [Object] Object to be compared
272-
def ==(o)
273-
return true if self.same?(o)
274-
self.class == o.class{{#vars}} &&
275-
{{name}} == o.{{name}}{{/vars}}{{#parent}} && super(o){{/parent}}
273+
def ==(other)
274+
return true if self.same?(other)
275+
self.class == other.class{{#vars}} &&
276+
{{name}} == other.{{name}}{{/vars}}{{#parent}} && super(other){{/parent}}
276277
end
277278

278279
# @see the `==` method
279280
# @param [Object] Object to be compared
280-
def eql?(o)
281-
self == o
281+
def eql?(other)
282+
self == other
282283
end
283284

284285
# Calculates hash code according to all attributes.

modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/api.mustache

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ import kotlinx.serialization.encoding.*
9999
{{/hasBodyParam}}
100100

101101
val localVariableQuery = mutableMapOf<String, List<String>>(){{#queryParams}}
102-
{{{paramName}}}?.apply { localVariableQuery["{{baseName}}"] = {{#isContainer}}toMultiValue(this, "{{collectionFormat}}"){{/isContainer}}{{^isContainer}}listOf({{^isEnum}}"${{{paramName}}}"{{/isEnum}}{{#isEnum}}"${ {{paramName}}.value }"{{/isEnum}}){{/isContainer}} }{{/queryParams}}
102+
{{{paramName}}}?.apply { localVariableQuery["{{baseName}}"] = {{#isContainer}}toMultiValue(this, "{{collectionFormat}}"){{/isContainer}}{{^isContainer}}listOf({{^isEnumOrRef}}"${{{paramName}}}"{{/isEnumOrRef}}{{#isEnumOrRef}}"${ {{paramName}}.value }"{{/isEnumOrRef}}){{/isContainer}} }{{/queryParams}}
103103
val localVariableHeaders = mutableMapOf<String, String>(){{#headerParams}}
104104
{{{paramName}}}?.apply { localVariableHeaders["{{baseName}}"] = {{#isContainer}}this.joinToString(separator = collectionDelimiter("{{collectionFormat}}")){{/isContainer}}{{^isContainer}}this.toString(){{/isContainer}} }{{/headerParams}}
105105

106106
val localVariableConfig = RequestConfig<kotlin.Any?>(
107107
RequestMethod.{{httpMethod}},
108-
"{{{path}}}"{{#pathParams}}.replace("{" + "{{baseName}}" + "}", {{#isContainer}}{{paramName}}.joinToString(","){{/isContainer}}{{^isContainer}}{{^isEnum}}"${{{paramName}}}"{{/isEnum}}{{#isEnum}}"${ {{paramName}}.value }"{{/isEnum}}{{/isContainer}}){{/pathParams}},
108+
"{{{path}}}"{{#pathParams}}.replace("{" + "{{baseName}}" + "}", {{#isContainer}}{{paramName}}.joinToString(","){{/isContainer}}{{^isContainer}}{{^isEnumOrRef}}"${{{paramName}}}"{{/isEnumOrRef}}{{#isEnumOrRef}}"${ {{paramName}}.value }"{{/isEnumOrRef}}{{/isContainer}}){{/pathParams}},
109109
query = localVariableQuery,
110110
headers = localVariableHeaders,
111111
requiresAuthentication = {{#hasAuthMethods}}true{{/hasAuthMethods}}{{^hasAuthMethods}}false{{/hasAuthMethods}},

modules/openapi-generator/src/main/resources/scala-sttp/build.sbt.mustache

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ libraryDependencies ++= Seq(
1515
"org.json4s" %% "json4s-jackson" % "{{json4sVersion}}"
1616
{{/json4s}}
1717
{{#circe}}
18-
"com.softwaremill.sttp.client3" %% "circe" % "{{sttpClientVersion}}"
18+
"com.softwaremill.sttp.client3" %% "circe" % "{{sttpClientVersion}}",
19+
"io.circe" %% "circe-generic" % "{{circeVersion}}"
1920
{{/circe}}
2021
)
2122

modules/openapi-generator/src/main/resources/scala-sttp/jsonSupport.mustache

+8
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ object JsonSupport extends SttpCirceApi with AutoDerivation with DateSerializers
5353
implicit val {{classname}}Decoder: Decoder[{{classname}}.{{classname}}] = Decoder.decodeEnumeration({{classname}})
5454
implicit val {{classname}}Encoder: Encoder[{{classname}}.{{classname}}] = Encoder.encodeEnumeration({{classname}})
5555
{{/isEnum}}
56+
{{#hasEnums}}
57+
{{#vars}}
58+
{{#isEnum}}
59+
implicit val {{classname}}{{datatypeWithEnum}}Decoder: Decoder[{{classname}}Enums.{{datatypeWithEnum}}] = Decoder.decodeEnumeration({{classname}}Enums.{{datatypeWithEnum}})
60+
implicit val {{classname}}{{datatypeWithEnum}}Encoder: Encoder[{{classname}}Enums.{{datatypeWithEnum}}] = Encoder.encodeEnumeration({{classname}}Enums.{{datatypeWithEnum}})
61+
{{/isEnum}}
62+
{{/vars}}
63+
{{/hasEnums}}
5664
{{/model}}
5765
{{/models}}
5866
}
2.96 MB
Binary file not shown.

samples/client/petstore/crystal/spec/api_client_spec.cr

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ Spectator.describe Petstore::ApiClient do
99

1010
header_params = {} of String => String
1111
query_params = {} of String => String
12+
cookie_params = {} of String => String
1213

1314
api_client = Petstore::ApiClient.new(config)
14-
api_client.update_params_for_auth!(header_params, query_params, ["petstore_auth"])
15+
api_client.update_params_for_auth!(header_params, query_params, cookie_params, ["petstore_auth"])
1516

1617
expect(header_params["Authorization"]).to eq "Bearer xxx"
1718
expect(query_params.size).to eq 0
@@ -26,9 +27,10 @@ Spectator.describe Petstore::ApiClient do
2627

2728
header_params = {} of String => String
2829
query_params = {} of String => String
30+
cookie_params = {} of String => String
2931

3032
api_client = Petstore::ApiClient.new(config)
31-
api_client.update_params_for_auth!(header_params, query_params, ["api_key"])
33+
api_client.update_params_for_auth!(header_params, query_params, cookie_params, ["api_key"])
3234

3335
expect(header_params["api_key"]).to eq "xxx"
3436
expect(query_params.empty?).to be_true
@@ -43,9 +45,10 @@ Spectator.describe Petstore::ApiClient do
4345

4446
header_params = {} of String => String
4547
query_params = {} of String => String
48+
cookie_params = {} of String => String
4649

4750
api_client = Petstore::ApiClient.new(config)
48-
api_client.update_params_for_auth!(header_params, query_params, ["api_key"])
51+
api_client.update_params_for_auth!(header_params, query_params, cookie_params, ["api_key"])
4952

5053
expect(header_params["api_key"]).to eq "Token xxx"
5154
expect(query_params.empty?).to be_true

samples/client/petstore/crystal/src/petstore/api/fake_api.cr

+4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ module Petstore
6363
# resource path
6464
local_var_path = "/fake/parameter-name-mapping"
6565

66+
# cookie parameters
67+
cookie_params = Hash(String, String).new
68+
6669
# query parameters
6770
query_params = Hash(String, String).new
6871
query_params["type"] = _type.to_s unless _type.nil?
@@ -94,6 +97,7 @@ module Petstore
9497
auth_names,
9598
header_params,
9699
query_params,
100+
cookie_params,
97101
form_params)
98102
if @api_client.config.debugging
99103
Log.debug {"API called: FakeApi#get_parameter_name_mapping\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}

0 commit comments

Comments
 (0)