Skip to content

Commit 13d0a5b

Browse files
wing328lbialyKamil-Lontkowski
authored andcommitted
New generator for Scala3 + sttp4 + jsoniter-scala (OpenAPITools#21908)
* started impl * seems to work * generated docs * fix class name duplicates on case-insensitive filesystems * wip * added script to rebuild all projects * dropped bash slop * fixed directory structure * ok, now it makes sense * update sttp, serialize query params, fix enums serialization, fix not required files params * fix compile errors after sttp upgrade, fix missing enum import in operations, fix file response. change serialization from Map to Seq to avoid deleting duplicate keys * auth support * fix enums entries, multipart support(partially), header, path and cookie serialization support * support of option fields * add samples, update workflow * add new files * fix * remove tab * remove tab * update doc * update header * update readme --------- Co-authored-by: Łukasz Biały <[email protected]> Co-authored-by: Kamil-Lontkowski <[email protected]>
1 parent c1f37c2 commit 13d0a5b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+4237
-1
lines changed

.github/workflows/samples-scala.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
- samples/client/petstore/scalaz
2525
- samples/client/petstore/scala-pekko
2626
- samples/client/petstore/scala-http4s
27+
- samples/client/petstore/scala-sttp4-jsoniter
2728
#- samples/client/petstore/scala-sttp
2829
#- samples/client/petstore/scala-sttp-circe
2930
# servers

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,7 @@ Here is a list of template creators:
10991099
* Scala (Akka): @cchafer
11001100
* Scala (sttp): @chameleon82
11011101
* Scala (sttp4): @flsh86
1102+
* Scala (scala-sttp4-jsoniter): @lbialy
11021103
* Scala (Pekko): @mickaelmagniez
11031104
* Scala (http4s): @JennyLeahy
11041105
* Swift: @tkqubo
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
generatorName: scala-sttp4-jsoniter
2+
outputDir: samples/client/petstore/scala-sttp4-jsoniter
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/scala/scala-sttp4-jsoniter/petstore.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/scala-sttp4-jsoniter
5+
additionalProperties:
6+
hideGenerationTimestamp: "true"

docs/generators.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ The following generators are available:
6565
* [scala-pekko](generators/scala-pekko.md)
6666
* [scala-sttp](generators/scala-sttp.md)
6767
* [scala-sttp4 (beta)](generators/scala-sttp4.md)
68+
* [scala-sttp4-jsoniter (beta)](generators/scala-sttp4-jsoniter.md)
6869
* [scalaz](generators/scalaz.md)
6970
* [swift-combine](generators/swift-combine.md)
7071
* [swift5](generators/swift5.md)
Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
---
2+
title: Documentation for the scala-sttp4-jsoniter Generator
3+
---
4+
5+
## METADATA
6+
7+
| Property | Value | Notes |
8+
| -------- | ----- | ----- |
9+
| generator name | scala-sttp4-jsoniter | pass this to the generate command after -g |
10+
| generator stability | BETA | |
11+
| generator type | CLIENT | |
12+
| generator language | Scala | |
13+
| generator default templating engine | mustache | |
14+
| helpTxt | Generates a Scala client library (beta) based on Sttp4 and Jsoniter-Scala. | |
15+
16+
## CONFIG OPTIONS
17+
These options may be applied as additional-properties (cli) or configOptions (plugins). Refer to [configuration docs](https://openapi-generator.tech/docs/configuration) for more details.
18+
19+
| Option | Description | Values | Default |
20+
| ------ | ----------- | ------ | ------- |
21+
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
22+
|apiPackage|package for generated api classes| |null|
23+
|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|
24+
|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true|
25+
|enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|<dl><dt>**false**</dt><dd>No changes to the enum's are made, this is the default option.</dd><dt>**true**</dt><dd>With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.</dd></dl>|false|
26+
|jsoniterVersion|The version of jsoniter-scala library| |2.31.1|
27+
|legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C# have this enabled by default).|<dl><dt>**true**</dt><dd>The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.</dd><dt>**false**</dt><dd>The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document AND Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.</dd></dl>|true|
28+
|mainPackage|Top-level package name, which defines 'apiPackage', 'modelPackage', 'invokerPackage'| |org.openapitools.client|
29+
|modelPackage|package for generated models| |null|
30+
|modelPropertyNaming|Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name| |camelCase|
31+
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
32+
|separateErrorChannel|Whether to return response as F[Either[ResponseError[ErrorType], ReturnType]]] or to flatten response's error raising them through enclosing monad (F[ReturnType]).| |true|
33+
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
34+
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
35+
|sourceFolder|source folder for generated code| |null|
36+
|sttpClientVersion|The version of sttp client| |4.0.0-RC1|
37+
38+
## IMPORT MAPPING
39+
40+
| Type/Alias | Imports |
41+
| ---------- | ------- |
42+
|Array|java.util.List|
43+
|ArrayList|java.util.ArrayList|
44+
|BigDecimal|scala.math.BigDecimal|
45+
|Date|java.util.Date|
46+
|DateTime|org.joda.time.*|
47+
|File|java.io.File|
48+
|HashMap|java.util.HashMap|
49+
|ListBuffer|scala.collection.mutable.ListBuffer|
50+
|ListSet|scala.collection.immutable.ListSet|
51+
|LocalDate|org.joda.time.*|
52+
|LocalDateTime|org.joda.time.*|
53+
|LocalTime|org.joda.time.*|
54+
|Seq|scala.collection.immutable.Seq|
55+
|Set|scala.collection.immutable.Set|
56+
|Timestamp|java.sql.Timestamp|
57+
|URI|java.net.URI|
58+
|UUID|java.util.UUID|
59+
|io.circe.Json|com.github.plokhotnyuk.jsoniter_scala.circe.JsoniterScalaCodec.*|
60+
61+
62+
## INSTANTIATION TYPES
63+
64+
| Type/Alias | Instantiated By |
65+
| ---------- | --------------- |
66+
|array|ListBuffer|
67+
|map|Map|
68+
|set|Set|
69+
70+
71+
## LANGUAGE PRIMITIVES
72+
73+
<ul class="column-ul">
74+
<li>Any</li>
75+
<li>Array</li>
76+
<li>Boolean</li>
77+
<li>Byte</li>
78+
<li>Double</li>
79+
<li>Float</li>
80+
<li>Int</li>
81+
<li>List</li>
82+
<li>Long</li>
83+
<li>Map</li>
84+
<li>Object</li>
85+
<li>Seq</li>
86+
<li>String</li>
87+
<li>boolean</li>
88+
</ul>
89+
90+
## RESERVED WORDS
91+
92+
<ul class="column-ul">
93+
<li>Either</li>
94+
<li>Method</li>
95+
<li>Request</li>
96+
<li>abstract</li>
97+
<li>case</li>
98+
<li>catch</li>
99+
<li>class</li>
100+
<li>clone</li>
101+
<li>def</li>
102+
<li>do</li>
103+
<li>else</li>
104+
<li>enum</li>
105+
<li>export</li>
106+
<li>extends</li>
107+
<li>false</li>
108+
<li>final</li>
109+
<li>finally</li>
110+
<li>for</li>
111+
<li>forSome</li>
112+
<li>given</li>
113+
<li>if</li>
114+
<li>implicit</li>
115+
<li>import</li>
116+
<li>lazy</li>
117+
<li>match</li>
118+
<li>new</li>
119+
<li>null</li>
120+
<li>object</li>
121+
<li>override</li>
122+
<li>package</li>
123+
<li>private</li>
124+
<li>protected</li>
125+
<li>return</li>
126+
<li>sealed</li>
127+
<li>super</li>
128+
<li>then</li>
129+
<li>this</li>
130+
<li>throw</li>
131+
<li>trait</li>
132+
<li>true</li>
133+
<li>try</li>
134+
<li>type</li>
135+
<li>using</li>
136+
<li>val</li>
137+
<li>var</li>
138+
<li>while</li>
139+
<li>with</li>
140+
<li>yield</li>
141+
</ul>
142+
143+
## FEATURE SET
144+
145+
146+
### Client Modification Feature
147+
| Name | Supported | Defined By |
148+
| ---- | --------- | ---------- |
149+
|BasePath|✓|ToolingExtension
150+
|Authorizations|✗|ToolingExtension
151+
|UserAgent|✓|ToolingExtension
152+
|MockServer|✗|ToolingExtension
153+
154+
### Data Type Feature
155+
| Name | Supported | Defined By |
156+
| ---- | --------- | ---------- |
157+
|Custom|✗|OAS2,OAS3
158+
|Int32|✓|OAS2,OAS3
159+
|Int64|✓|OAS2,OAS3
160+
|Float|✓|OAS2,OAS3
161+
|Double|✓|OAS2,OAS3
162+
|Decimal|✓|ToolingExtension
163+
|String|✓|OAS2,OAS3
164+
|Byte|✓|OAS2,OAS3
165+
|Binary|✓|OAS2,OAS3
166+
|Boolean|✓|OAS2,OAS3
167+
|Date|✓|OAS2,OAS3
168+
|DateTime|✓|OAS2,OAS3
169+
|Password|✓|OAS2,OAS3
170+
|File|✓|OAS2
171+
|Uuid||
172+
|Array|✓|OAS2,OAS3
173+
|Null|✗|OAS3
174+
|AnyType|✗|OAS2,OAS3
175+
|Object|✓|OAS2,OAS3
176+
|Maps|✓|ToolingExtension
177+
|CollectionFormat|✓|OAS2
178+
|CollectionFormatMulti|✓|OAS2
179+
|Enum|✓|OAS2,OAS3
180+
|ArrayOfEnum|✓|ToolingExtension
181+
|ArrayOfModel|✓|ToolingExtension
182+
|ArrayOfCollectionOfPrimitives|✓|ToolingExtension
183+
|ArrayOfCollectionOfModel|✓|ToolingExtension
184+
|ArrayOfCollectionOfEnum|✓|ToolingExtension
185+
|MapOfEnum|✓|ToolingExtension
186+
|MapOfModel|✓|ToolingExtension
187+
|MapOfCollectionOfPrimitives|✓|ToolingExtension
188+
|MapOfCollectionOfModel|✓|ToolingExtension
189+
|MapOfCollectionOfEnum|✓|ToolingExtension
190+
191+
### Documentation Feature
192+
| Name | Supported | Defined By |
193+
| ---- | --------- | ---------- |
194+
|Readme|✓|ToolingExtension
195+
|Model|✓|ToolingExtension
196+
|Api|✓|ToolingExtension
197+
198+
### Global Feature
199+
| Name | Supported | Defined By |
200+
| ---- | --------- | ---------- |
201+
|Host|✓|OAS2,OAS3
202+
|BasePath|✓|OAS2,OAS3
203+
|Info|✓|OAS2,OAS3
204+
|Schemes|✗|OAS2,OAS3
205+
|PartialSchemes|✓|OAS2,OAS3
206+
|Consumes|✓|OAS2
207+
|Produces|✓|OAS2
208+
|ExternalDocumentation|✓|OAS2,OAS3
209+
|Examples|✓|OAS2,OAS3
210+
|XMLStructureDefinitions|✗|OAS2,OAS3
211+
|MultiServer|✗|OAS3
212+
|ParameterizedServer|✗|OAS3
213+
|ParameterStyling|✗|OAS3
214+
|Callbacks|✗|OAS3
215+
|LinkObjects|✗|OAS3
216+
217+
### Parameter Feature
218+
| Name | Supported | Defined By |
219+
| ---- | --------- | ---------- |
220+
|Path|✓|OAS2,OAS3
221+
|Query|✓|OAS2,OAS3
222+
|Header|✓|OAS2,OAS3
223+
|Body|✓|OAS2
224+
|FormUnencoded|✓|OAS2
225+
|FormMultipart|✓|OAS2
226+
|Cookie|✓|OAS3
227+
228+
### Schema Support Feature
229+
| Name | Supported | Defined By |
230+
| ---- | --------- | ---------- |
231+
|Simple|✓|OAS2,OAS3
232+
|Composite|✓|OAS2,OAS3
233+
|Polymorphism|✗|OAS2,OAS3
234+
|Union|✗|OAS3
235+
|allOf|✗|OAS2,OAS3
236+
|anyOf|✗|OAS3
237+
|oneOf|✗|OAS3
238+
|not|✗|OAS3
239+
240+
### Security Feature
241+
| Name | Supported | Defined By |
242+
| ---- | --------- | ---------- |
243+
|BasicAuth|✓|OAS2,OAS3
244+
|ApiKey|✓|OAS2,OAS3
245+
|OpenIDConnect|✗|OAS3
246+
|BearerToken|✓|OAS3
247+
|OAuth2_Implicit|✗|OAS2,OAS3
248+
|OAuth2_Password|✗|OAS2,OAS3
249+
|OAuth2_ClientCredentials|✗|OAS2,OAS3
250+
|OAuth2_AuthorizationCode|✗|OAS2,OAS3
251+
|SignatureAuth|✗|OAS3
252+
|AWSV4Signature|✗|ToolingExtension
253+
254+
### Wire Format Feature
255+
| Name | Supported | Defined By |
256+
| ---- | --------- | ---------- |
257+
|JSON|✓|OAS2,OAS3
258+
|XML|✓|OAS2,OAS3
259+
|PROTOBUF|✗|ToolingExtension
260+
|Custom|✓|OAS2,OAS3

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/*
22
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
3-
* Copyright 2018 SmartBear Software
43
*
54
* Licensed under the Apache License, Version 2.0 (the "License");
65
* you may not use this file except in compliance with the License.
@@ -529,6 +528,21 @@ protected String formatIdentifier(String name, boolean capitalized) {
529528
if (identifier.matches("[a-zA-Z_$][\\w_$]+") && !isReservedWord(identifier)) {
530529
return identifier;
531530
}
531+
532+
// below code block only for scala-sttp4-jsoniter for backward copmatibility
533+
if (this instanceof ScalaSttp4JsoniterClientCodegen) {
534+
if (identifier.matches("[0-9]*")) {
535+
return escapeReservedWord(identifier);
536+
}
537+
if (!capitalized || StringUtils.isNumeric(name)) {
538+
// starts with a small letter, could be a keyword or a number
539+
return escapeReservedWord(identifier);
540+
} else {
541+
// no keywords start with large letter
542+
return identifier;
543+
}
544+
}
545+
532546
return escapeReservedWord(identifier);
533547
}
534548

0 commit comments

Comments
 (0)