Skip to content

Commit 9791e6f

Browse files
JennyLeahyJenny Leahy
and
Jenny Leahy
authored
[Scala][Client]Add Http4s scala3 client codegen (#19658)
* fix attemp * use java.time.Instant * fix client gen * Tweeks * header and form * use scala 3 enum * more tweeks * add additional properties; add auth * add form media type * add modelsOnly * add unit tests * add petstore samples * add doc * add new samle to .github/workflows/samples-scala.yaml * update build.sbt template * simply the baseclient * add None to optional field * tweek auth model and format --------- Co-authored-by: Jenny Leahy <[email protected]>
1 parent e5dee54 commit 9791e6f

Some content is hidden

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

49 files changed

+3372
-2
lines changed

.github/workflows/samples-scala.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
- 'samples/client/petstore/java/okhttp-gson'
2424
- samples/client/petstore/scalaz
2525
- samples/client/petstore/scala-pekko
26+
- samples/client/petstore/scala-http4s
2627
#- samples/client/petstore/scala-sttp # won't pass while the same tests in circleci pass
2728
# servers
2829
- samples/server/petstore/scala-lagom-server

bin/configs/scala-http4s.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
generatorName: scala-http4s
2+
outputDir: samples/client/petstore/scala-http4s
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/scala-http4s/petstore.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/scala-http4s
5+
additionalProperties:
6+
artifactId: scala-http4s-client

docs/generators/scala-http4s.md

Lines changed: 272 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,272 @@
1+
---
2+
title: Documentation for the scala-http4s Generator
3+
---
4+
5+
## METADATA
6+
7+
| Property | Value | Notes |
8+
| -------- | ----- | ----- |
9+
| generator name | scala-http4s | pass this to the generate command after -g |
10+
| generator stability | STABLE | |
11+
| generator type | CLIENT | |
12+
| generator language | Scala | |
13+
| generator default templating engine | mustache | |
14+
| helpTxt | Generates a scala-http4s client. | |
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+
| packageName | main package for the generated classes, parent package for api package and model package | |null|
23+
| artifactId | project name / artifactId for for the generated project | |null|
24+
| excludeSbt | exclude sbt from generation | |null|
25+
| excludeApi | exclude apis from generation | |null|
26+
| prependFormOrBodyParameters | Add form or body parameters to the beginning of the parameter list. | |false|
27+
| 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|
28+
| ensureUniqueParams | Whether to ensure parameter names are unique in an operation (rename parameters that are not). | |true|
29+
| 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|
30+
| sortModelPropertiesByRequiredFlag | Sort model properties to place required parameters before optional parameters. | |true|
31+
| sortParamsByRequiredFlag | Sort method arguments to place required parameters before optional parameters. | |true|
32+
| sourceFolder | source folder for generated code | |null|
33+
34+
## IMPORT MAPPING
35+
36+
| Type/Alias | Imports |
37+
| ---------- | ------- |
38+
|ArrayBuffer|scala.collection.mutable.ArrayBuffer|
39+
|Date|java.util.Date|
40+
|File|java.io.File|
41+
|HashMap|scala.collection.immutable.HashMap|
42+
|Instant|java.time.Instant|
43+
|Json|io.circe.Json|
44+
|LocalDate|java.time.LocalDate|
45+
|LocalDateTime|java.time.LocalDateTime|
46+
|LocalTime|java.time.LocalTime|
47+
|Map|scala.collection.immutable.Map|
48+
|OffsetDateTime|java.time.OffsetDateTime|
49+
|Seq|scala.collection.immutable.Seq|
50+
|Timestamp|java.sql.Timestamp|
51+
|URI|java.net.URI|
52+
|UUID|java.util.UUID|
53+
|ZonedDateTime|java.time.ZonedDateTime|
54+
55+
56+
## INSTANTIATION TYPES
57+
58+
| Type/Alias | Instantiated By |
59+
| ---------- | --------------- |
60+
|array|Seq|
61+
|list|List|
62+
|map|Map|
63+
|seq|Seq|
64+
|set|Set|
65+
66+
67+
## LANGUAGE PRIMITIVES
68+
69+
<ul class="column-ul">
70+
<li>Any</li>
71+
<li>AnyRef</li>
72+
<li>AnyVal</li>
73+
<li>BigDecimal</li>
74+
<li>Boolean</li>
75+
<li>Double</li>
76+
<li>Float</li>
77+
<li>Int</li>
78+
<li>Integer</li>
79+
<li>Long</li>
80+
<li>Object</li>
81+
<li>String</li>
82+
</ul>
83+
84+
## RESERVED WORDS
85+
86+
<ul class="column-ul">
87+
<li>abstract</li>
88+
<li>assert</li>
89+
<li>break</li>
90+
<li>byte</li>
91+
<li>case</li>
92+
<li>catch</li>
93+
<li>char</li>
94+
<li>class</li>
95+
<li>const</li>
96+
<li>continue</li>
97+
<li>def</li>
98+
<li>default</li>
99+
<li>do</li>
100+
<li>double</li>
101+
<li>else</li>
102+
<li>enum</li>
103+
<li>extends</li>
104+
<li>false</li>
105+
<li>final</li>
106+
<li>finally</li>
107+
<li>float</li>
108+
<li>for</li>
109+
<li>forsome</li>
110+
<li>goto</li>
111+
<li>if</li>
112+
<li>implements</li>
113+
<li>implicit</li>
114+
<li>import</li>
115+
<li>instanceof</li>
116+
<li>int</li>
117+
<li>interface</li>
118+
<li>lazy</li>
119+
<li>long</li>
120+
<li>match</li>
121+
<li>native</li>
122+
<li>new</li>
123+
<li>null</li>
124+
<li>object</li>
125+
<li>override</li>
126+
<li>package</li>
127+
<li>private</li>
128+
<li>protected</li>
129+
<li>public</li>
130+
<li>return</li>
131+
<li>sealed</li>
132+
<li>short</li>
133+
<li>static</li>
134+
<li>strictfp</li>
135+
<li>super</li>
136+
<li>switch</li>
137+
<li>synchronized</li>
138+
<li>this</li>
139+
<li>throw</li>
140+
<li>throws</li>
141+
<li>trait</li>
142+
<li>transient</li>
143+
<li>true</li>
144+
<li>try</li>
145+
<li>type</li>
146+
<li>val</li>
147+
<li>var</li>
148+
<li>void</li>
149+
<li>volatile</li>
150+
<li>while</li>
151+
<li>with</li>
152+
<li>yield</li>
153+
</ul>
154+
155+
## FEATURE SET
156+
157+
158+
### Client Modification Feature
159+
| Name | Supported | Defined By |
160+
| ---- | --------- | ---------- |
161+
|BasePath|✗|ToolingExtension
162+
|Authorizations|✗|ToolingExtension
163+
|UserAgent|✗|ToolingExtension
164+
|MockServer|✗|ToolingExtension
165+
166+
### Data Type Feature
167+
| Name | Supported | Defined By |
168+
| ---- | --------- | ---------- |
169+
|Custom|✗|OAS2,OAS3
170+
|Int32|✓|OAS2,OAS3
171+
|Int64|✓|OAS2,OAS3
172+
|Float|✓|OAS2,OAS3
173+
|Double|✓|OAS2,OAS3
174+
|Decimal|✓|ToolingExtension
175+
|String|✓|OAS2,OAS3
176+
|Byte|✓|OAS2,OAS3
177+
|Binary|✓|OAS2,OAS3
178+
|Boolean|✓|OAS2,OAS3
179+
|Date|✓|OAS2,OAS3
180+
|DateTime|✓|OAS2,OAS3
181+
|Password|✓|OAS2,OAS3
182+
|File|✓|OAS2
183+
|Uuid||
184+
|Array|✓|OAS2,OAS3
185+
|Null|✗|OAS3
186+
|AnyType|✗|OAS2,OAS3
187+
|Object|✓|OAS2,OAS3
188+
|Maps|✓|ToolingExtension
189+
|CollectionFormat|✓|OAS2
190+
|CollectionFormatMulti|✓|OAS2
191+
|Enum|✓|OAS2,OAS3
192+
|ArrayOfEnum|✓|ToolingExtension
193+
|ArrayOfModel|✓|ToolingExtension
194+
|ArrayOfCollectionOfPrimitives|✓|ToolingExtension
195+
|ArrayOfCollectionOfModel|✓|ToolingExtension
196+
|ArrayOfCollectionOfEnum|✓|ToolingExtension
197+
|MapOfEnum|✓|ToolingExtension
198+
|MapOfModel|✓|ToolingExtension
199+
|MapOfCollectionOfPrimitives|✓|ToolingExtension
200+
|MapOfCollectionOfModel|✓|ToolingExtension
201+
|MapOfCollectionOfEnum|✓|ToolingExtension
202+
203+
### Documentation Feature
204+
| Name | Supported | Defined By |
205+
| ---- | --------- | ---------- |
206+
|Readme|✗|ToolingExtension
207+
|Model|✓|ToolingExtension
208+
|Api|✓|ToolingExtension
209+
210+
### Global Feature
211+
| Name | Supported | Defined By |
212+
| ---- | --------- | ---------- |
213+
|Host|✓|OAS2,OAS3
214+
|BasePath|✓|OAS2,OAS3
215+
|Info|✓|OAS2,OAS3
216+
|Schemes|✗|OAS2,OAS3
217+
|PartialSchemes|✓|OAS2,OAS3
218+
|Consumes|✓|OAS2
219+
|Produces|✓|OAS2
220+
|ExternalDocumentation|✓|OAS2,OAS3
221+
|Examples|✓|OAS2,OAS3
222+
|XMLStructureDefinitions|✗|OAS2,OAS3
223+
|MultiServer|✗|OAS3
224+
|ParameterizedServer|✗|OAS3
225+
|ParameterStyling|✗|OAS3
226+
|Callbacks|✗|OAS3
227+
|LinkObjects|✗|OAS3
228+
229+
### Parameter Feature
230+
| Name | Supported | Defined By |
231+
| ---- | --------- | ---------- |
232+
|Path|✓|OAS2,OAS3
233+
|Query|✓|OAS2,OAS3
234+
|Header|✓|OAS2,OAS3
235+
|Body|✓|OAS2
236+
|FormUnencoded|✓|OAS2
237+
|FormMultipart|✗|OAS2
238+
|Cookie|✗|OAS3
239+
240+
### Schema Support Feature
241+
| Name | Supported | Defined By |
242+
| ---- | --------- | ---------- |
243+
|Simple|✓|OAS2,OAS3
244+
|Composite|✓|OAS2,OAS3
245+
|Polymorphism|✗|OAS2,OAS3
246+
|Union|✗|OAS3
247+
|allOf|✗|OAS2,OAS3
248+
|anyOf|✗|OAS3
249+
|oneOf|✗|OAS3
250+
|not|✗|OAS3
251+
252+
### Security Feature
253+
| Name | Supported | Defined By |
254+
| ---- | --------- | ---------- |
255+
|BasicAuth|✓|OAS2,OAS3
256+
|ApiKey|✓|OAS2,OAS3
257+
|OpenIDConnect|✗|OAS3
258+
|BearerToken|✓|OAS3
259+
|OAuth2_Implicit|✗|OAS2,OAS3
260+
|OAuth2_Password|✗|OAS2,OAS3
261+
|OAuth2_ClientCredentials|✗|OAS2,OAS3
262+
|OAuth2_AuthorizationCode|✗|OAS2,OAS3
263+
|SignatureAuth|✗|OAS3
264+
|AWSV4Signature|✗|ToolingExtension
265+
266+
### Wire Format Feature
267+
| Name | Supported | Defined By |
268+
| ---- | --------- | ---------- |
269+
|JSON|✓|OAS2,OAS3
270+
|XML|✓|OAS2,OAS3
271+
|PROTOBUF|✗|ToolingExtension
272+
|Custom|✓|OAS2,OAS3

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class CodegenOperation {
3030
hasVersionHeaders = false, hasVersionQueryParams = false,
3131
isResponseBinary = false, isResponseFile = false, isResponseOptional = false, hasReference = false, defaultReturnType = false,
3232
isRestfulIndex, isRestfulShow, isRestfulCreate, isRestfulUpdate, isRestfulDestroy,
33-
isRestful, isDeprecated, isCallbackRequest, uniqueItems, hasDefaultResponse = false, hasConstantParams = false,
33+
isRestful, isDeprecated, isCallbackRequest, uniqueItems, hasDefaultResponse = false, hasOnlyDefaultResponse = false, hasConstantParams = false,
3434
hasErrorResponseObject, // if 4xx, 5xx responses have at least one error object defined
3535
hasSingleParam = false; // if the operation has only one parameter;
3636
public CodegenProperty returnProperty;
@@ -215,6 +215,13 @@ public boolean getHasDefaultResponse() {
215215
return responses.stream().anyMatch(response -> response.isDefault);
216216
}
217217

218+
/**
219+
* Check if the responses contain only 1 entry and it's default
220+
*
221+
* @return true if responses contain only 1 entry and it's a default response, false otherwise
222+
*/
223+
public boolean getHasOnlyDefaultResponse() { return responses.size() == 1 && getHasDefaultResponse(); }
224+
218225
public boolean getAllResponsesAreErrors() {
219226
return responses.stream().allMatch(response -> response.is4xx || response.is5xx);
220227
}
@@ -351,6 +358,7 @@ public String toString() {
351358
sb.append(", isResponseOptional=").append(isResponseOptional);
352359
sb.append(", hasReference=").append(hasReference);
353360
sb.append(", hasDefaultResponse=").append(hasDefaultResponse);
361+
sb.append(", hasOnlyDefaultResponse=").append(hasOnlyDefaultResponse);
354362
sb.append(", hasErrorResponseObject=").append(hasErrorResponseObject);
355363
sb.append(", hasSingleParam=").append(hasSingleParam);
356364
sb.append(", isRestfulIndex=").append(isRestfulIndex);
@@ -432,6 +440,7 @@ public boolean equals(Object o) {
432440
isResponseOptional == that.isResponseOptional &&
433441
hasReference == that.hasReference &&
434442
hasDefaultResponse == that.hasDefaultResponse &&
443+
hasOnlyDefaultResponse == that.hasOnlyDefaultResponse &&
435444
hasErrorResponseObject == that.hasErrorResponseObject &&
436445
hasSingleParam == that.hasSingleParam &&
437446
isRestfulIndex == that.isRestfulIndex &&
@@ -496,7 +505,7 @@ public int hashCode() {
496505
return Objects.hash(responseHeaders, hasAuthMethods, hasConsumes, hasProduces, hasParams, hasOptionalParams,
497506
hasRequiredParams, returnTypeIsPrimitive, returnSimpleType, subresourceOperation, isMap,
498507
isArray, isMultipart, isVoid, isResponseBinary, isResponseFile, isResponseOptional, hasReference,
499-
hasDefaultResponse, isRestfulIndex, isRestfulShow, isRestfulCreate, isRestfulUpdate, isRestfulDestroy,
508+
hasDefaultResponse, hasOnlyDefaultResponse, isRestfulIndex, isRestfulShow, isRestfulCreate, isRestfulUpdate, isRestfulDestroy,
500509
isRestful, isDeprecated, isCallbackRequest, uniqueItems, path, operationId, returnType, httpMethod,
501510
returnBaseType, returnContainer, summary, unescapedNotes, notes, baseName, defaultResponse,
502511
discriminator, consumes, produces, prioritizedContentTypes, servers, bodyParam, allParams, bodyParams,

0 commit comments

Comments
 (0)