Skip to content

Commit 89f6ab5

Browse files
committed
docs(gdscript): review and generate docs
1 parent c47b7a1 commit 89f6ab5

File tree

11 files changed

+1837
-46
lines changed

11 files changed

+1837
-46
lines changed

docs/generators/gdscript.md

Lines changed: 1704 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import static org.openapitools.codegen.utils.StringUtils.camelize;
1818

19+
1920
public class GdscriptClientCodegen extends DefaultCodegen implements CodegenConfig {
2021

2122
// All generated core classes will use this affixes both in class_name and file name.
@@ -190,7 +191,7 @@ public GdscriptClientCodegen() {
190191
);
191192

192193
// It makes sense to package the generated code like a Godot addon, for ease of installation.
193-
// Since most users will set the output dir, we perhaps ought to to document that fact.
194+
// Since most users will set the output dir, we perhaps ought to document that fact.
194195
String addonName = "goas.client";
195196
outputFolder = "generated-code"
196197
+ File.separator + "gdscript"
@@ -245,10 +246,11 @@ public GdscriptClientCodegen() {
245246
cliOptions.add(new CliOption(ANTICOLLISION_SUFFIX, "Suffix added at the ending of reserved words")
246247
.defaultValue(ANTICOLLISION_SUFFIX_VALUE));
247248

248-
// Also, I have not taken care of escaping things properly in the templates.
249+
// Alas, I have not taken care of escaping things properly in the templates.
249250
// I'm not sure how to handle the different escaping strategies required.
250-
LOGGER.warn("---- THE GENERATED CODE MAY BE UNSAFE AND MALICIOUS OAS FILES MAY HURT YOU ----");
251-
LOGGER.warn("PLEASE READ *CAREFULLY* THE OAS FILE YOU ARE USING BEFORE YOU TRUST IT.");
251+
// FIXME: we can't log like this here → too verbose
252+
//LOGGER.warn("---- THE GENERATED CODE MAY BE UNSAFE AND MALICIOUS OAS FILES MAY HURT YOU ----");
253+
//LOGGER.warn("PLEASE READ *CAREFULLY* THE OAS FILE YOU ARE USING BEFORE YOU TRUST IT.");
252254
}
253255

254256
@Override
@@ -451,9 +453,9 @@ protected List<String> getReservedWords() {
451453
"randfn", "randi", "randi_range", "randomize", "remap", "rid_allocate_id", "rid_from_int64",
452454
"round", "roundf", "roundi", "seed", "sign", "signf", "signi", "sin", "sinh", "smoothstep",
453455
"snapped", "sqrt", "step_decimals", "str", "str_to_var", "tan", "tanh", "typeof",
454-
"var_to_bytes", "var_to_bytes_with_objects", "var_to_str", "weakref", "wrap", "wrapf",
456+
"var_to_bytes", "var_to_bytes_with_objects", "var_to_str", "weakref", "wrap", "wrapf", "wrapi",
455457
// Godot's global constants
456-
"wrapi", "SIDE_LEFT", "SIDE_TOP", "SIDE_RIGHT", "SIDE_BOTTOM", "CORNER_TOP_LEFT",
458+
"SIDE_LEFT", "SIDE_TOP", "SIDE_RIGHT", "SIDE_BOTTOM", "CORNER_TOP_LEFT",
457459
"CORNER_TOP_RIGHT", "CORNER_BOTTOM_RIGHT", "CORNER_BOTTOM_LEFT", "VERTICAL", "HORIZONTAL",
458460
"CLOCKWISE", "COUNTERCLOCKWISE", "HORIZONTAL_ALIGNMENT_LEFT", "HORIZONTAL_ALIGNMENT_CENTER",
459461
"HORIZONTAL_ALIGNMENT_RIGHT", "HORIZONTAL_ALIGNMENT_FILL", "VERTICAL_ALIGNMENT_TOP",
@@ -585,8 +587,9 @@ protected List<String> getReservedWords() {
585587
"OP_GREATER_EQUAL", "OP_ADD", "OP_SUBTRACT", "OP_MULTIPLY", "OP_DIVIDE", "OP_NEGATE",
586588
"OP_POSITIVE", "OP_MODULE", "OP_POWER", "OP_SHIFT_LEFT", "OP_SHIFT_RIGHT", "OP_BIT_AND",
587589
"OP_BIT_OR", "OP_BIT_XOR", "OP_BIT_NEGATE", "OP_AND", "OP_OR", "OP_XOR", "OP_NOT", "OP_IN",
590+
"OP_MAX",
588591
// Godot's singletons
589-
"OP_MAX", "AudioServer", "CameraServer", "ClassDB", "DisplayServer", "Engine",
592+
"AudioServer", "CameraServer", "ClassDB", "DisplayServer", "Engine",
590593
"EngineDebugger", "Geometry2D", "Geometry3D", "GodotSharp", "IP", "Input", "InputMap",
591594
"JavaClassWrapper", "JavaScriptBridge", "Marshalls", "NativeExtensionManager",
592595
"NavigationMeshGenerator", "NavigationServer2D", "NavigationServer3D", "OS", "Performance",
@@ -606,9 +609,9 @@ protected List<String> getReservedWords() {
606609
"var", "void", "yield",
607610
// Constants
608611
"PI", "TAU", "INF", "NaN",
609-
612+
// Primitive (lowercase) types
610613
"float", "int", "bool",
611-
614+
// Types
612615
"AABB",
613616
"AcceptDialog",
614617
"AESContext",
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.openapitools.codegen.gdscript;
2+
3+
import org.openapitools.codegen.*;
4+
import org.openapitools.codegen.languages.GdscriptClientCodegen;
5+
import io.swagger.models.*;
6+
import io.swagger.models.properties.*;
7+
8+
import org.testng.Assert;
9+
import org.testng.annotations.Test;
10+
11+
@SuppressWarnings("static-method")
12+
public class GdscriptClientCodegenModelTest {
13+
14+
@Test(description = "convert a simple java model")
15+
public void simpleModelTest() {
16+
final Model model = new ModelImpl()
17+
.description("a sample model")
18+
.property("id", new LongProperty())
19+
.property("name", new StringProperty())
20+
.required("id")
21+
.required("name");
22+
final DefaultCodegen codegen = new GdscriptClientCodegen();
23+
24+
// TODO: Complete this test.
25+
//Assert.fail("Not implemented.");
26+
}
27+
28+
}
29+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.openapitools.codegen.gdscript;
2+
3+
import org.openapitools.codegen.languages.GdscriptClientCodegen;
4+
import org.testng.annotations.Test;
5+
6+
import static org.mockito.Mockito.verify;
7+
8+
public class GdscriptClientCodegenTest {
9+
10+
GdscriptClientCodegen clientCodegen = new GdscriptClientCodegen();
11+
12+
@Test
13+
public void shouldSucceed() throws Exception {
14+
// TODO: Complete this test.
15+
//Assert.fail("Not implemented.");
16+
// verify(clientCodegen).setArtifactVersion(GdscriptClientCodegenOptionsProvider.ARTIFACT_VERSION_VALUE);
17+
}
18+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package org.openapitools.codegen.gdscript;
2+
3+
//import org.openapitools.codegen.AbstractOptionsTest;
4+
//import org.openapitools.codegen.CodegenConfig;
5+
//import org.openapitools.codegen.languages.GdscriptClientCodegen;
6+
//import org.openapitools.codegen.options.GdscriptClientOptionsProvider;
7+
//
8+
//import static org.mockito.Mockito.mock;
9+
//import static org.mockito.Mockito.verify;
10+
11+
12+
// NOTE:
13+
// This is commented out because it fails to use handlebars.
14+
// It is perhaps trivial to fix, but I could not figure it out.
15+
// Anyway, there's no test case in here right now, so it does not matter much.
16+
17+
18+
//public class GdscriptClientOptionsTest extends AbstractOptionsTest {
19+
// private final GdscriptClientCodegen codegen = mock(GdscriptClientCodegen.class, mockSettings);
20+
//
21+
// public GdscriptClientOptionsTest() {
22+
// super(new GdscriptClientOptionsProvider());
23+
// }
24+
//
25+
// @Override
26+
// protected CodegenConfig getCodegenConfig() {
27+
// return codegen;
28+
// }
29+
//
30+
// @SuppressWarnings("unused")
31+
// @Override
32+
// protected void verifyOptions() {
33+
// // TODO: Complete options using Mockito
34+
// // verify(codegen).someMethod(arguments)
35+
// }
36+
//}
37+

modules/openapi-generator/src/test/java/org/openapitools/codegen/options/GdscriptClientCodegenOptionsProvider.java renamed to modules/openapi-generator/src/test/java/org/openapitools/codegen/options/GdscriptClientOptionsProvider.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import java.util.Map;
99

10-
public class GdscriptClientCodegenOptionsProvider implements OptionsProvider {
10+
public class GdscriptClientOptionsProvider implements OptionsProvider {
1111

1212
// public static final String MODEL_PACKAGE_VALUE = "package";
1313
// public static final String API_PACKAGE_VALUE = "apiPackage";
@@ -41,7 +41,7 @@ public Map<String, String> createOptions() {
4141
.put(GdscriptClientCodegen.ANTICOLLISION_PREFIX, GdscriptClientCodegen.ANTICOLLISION_PREFIX_VALUE)
4242
.put(GdscriptClientCodegen.ANTICOLLISION_SUFFIX, GdscriptClientCodegen.ANTICOLLISION_SUFFIX_VALUE)
4343

44-
// > "le remblai, c'était mieux avant"
44+
// Things we *might* need (we'll see)
4545

4646
// .put(CodegenConstants.API_PACKAGE, API_PACKAGE_VALUE)
4747
// .put(PhpClientCodegen.VARIABLE_NAMING_CONVENTION, VARIABLE_NAMING_CONVENTION_VALUE)
@@ -53,6 +53,7 @@ public Map<String, String> createOptions() {
5353

5454
// The following is required by CodeGen
5555

56+
//.put(CodegenConstants.TEMPLATING_ENGINE, "handlebars")
5657
.put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, SORT_PARAMS_VALUE)
5758
.put(CodegenConstants.SORT_MODEL_PROPERTIES_BY_REQUIRED_FLAG, SORT_MODEL_PROPERTIES_VALUE)
5859
.put(CodegenConstants.ENSURE_UNIQUE_PARAMS, ENSURE_UNIQUE_PARAMS_VALUE)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6.6.0-SNAPSHOT
1+
7.8.0-SNAPSHOT

samples/client/petstore/gdscript/addons/oas.petstore.client/core/DemoApiBee.gd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,13 @@ func _bzz_do_request_text(
288288
on_failure.call(error)
289289
return
290290

291+
# Keep polling for as long as the request is being processed.
291292
while self._bzz_client.get_status() == HTTPClient.STATUS_REQUESTING:
292-
# Keep polling for as long as the request is being processed.
293-
self._bzz_client.poll()
294293
self._bzz_config.log_debug("Requesting…")
295294
if self._bzz_config.polling_interval_ms:
296295
OS.delay_msec(self._bzz_config.polling_interval_ms)
297296
await _bzz_next_loop_iteration()
297+
self._bzz_client.poll()
298298

299299
if not self._bzz_client.has_response():
300300
var error := DemoApiError.new()
@@ -321,14 +321,14 @@ func _bzz_do_request_text(
321321
var response_bytes := PackedByteArray()
322322

323323
while self._bzz_client.get_status() == HTTPClient.STATUS_BODY:
324-
self._bzz_client.poll()
325324
var chunk = self._bzz_client.read_response_body_chunk()
326325
if chunk.size() == 0: # Got nothing, wait for buffers to fill a bit.
327326
if self._bzz_config.polling_interval_ms:
328327
OS.delay_usec(self._bzz_config.polling_interval_ms)
329328
await _bzz_next_loop_iteration()
330329
else: # Yummy data has arrived
331330
response_bytes = response_bytes + chunk
331+
self._bzz_client.poll()
332332

333333
self._bzz_config.log_info("%s: RESPONSE %d (%d bytes)" % [
334334
_bzz_name, response.code, response_bytes.size()

samples/client/petstore/gdscript/addons/oas.petstore.client/core/DemoApiConfig.gd

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,13 @@ enum LogLevel {
4242
}
4343

4444

45-
# Log level to configure verbosity.
46-
# @export_enum ain't working for ints yet (2023-03)
45+
## Log level to configure verbosity.
4746
@export var log_level := LogLevel.WARNING
4847

4948

50-
# The host to connect to, with or without the protocol scheme.
51-
# Eg: "gitea.com", "https://gitea.com"
52-
# We toggle TLS accordingly to the provided scheme, if any.
49+
## The host to connect to, with or without the protocol scheme.
50+
## Eg: "gitea.com", "https://gitea.com"
51+
## We toggle TLS accordingly to the provided scheme, if any.
5352
@export var host := BEE_DEFAULT_HOST:
5453
set(value):
5554
if value.begins_with("https://"):
@@ -61,14 +60,14 @@ enum LogLevel {
6160
host = value
6261

6362

64-
# Port through which the connection will be established.
65-
# Note: changing the host may change the port as well if the scheme was provided, see above.
63+
## Port through which the connection will be established.
64+
## NOTE: changing the host may change the port as well if the scheme was provided, see above.
6665
@export var port := BEE_DEFAULT_PORT_HTTP
6766

6867

69-
# Headers used as base for all requests made by Api instances using this config.
70-
# Those are the lowest priority headers, and are merged with custom headers provided in the bee_request() method call
71-
# as well as the headers override below, to compute the final, actually sent headers.
68+
## Headers used as base for all requests made by Api instances using this config.
69+
## Those are the lowest priority headers, and are merged with custom headers provided in the bee_request() method call
70+
## as well as the headers override below, to compute the final, actually sent headers.
7271
@export var headers_base := {
7372
# Stigmergy: everyone does what is left to do (like ants do)
7473
"User-Agent": "Stigmergiac/1.0 (Godot)",
@@ -78,30 +77,30 @@ enum LogLevel {
7877
}
7978

8079

81-
# High-priority headers, they will always override other headers coming from the base above or the method call.
80+
## High-priority headers, they will always override other headers coming from the base above or the method call.
8281
@export var headers_override := {}
8382

8483

85-
# Duration of sleep between poll() calls.
84+
## Duration of sleep between poll() calls.
8685
@export var polling_interval_ms := BEE_DEFAULT_POLLING_INTERVAL_MS # milliseconds
8786

8887

89-
# Enable the Transport Security Layer (packet encryption, HTTPS)
88+
## Enable the Transport Security Layer (packet encryption, HTTPS)
9089
@export var tls_enabled := false:
9190
set(value):
9291
tls_enabled = value
9392
port = BEE_DEFAULT_PORT_HTTPS if tls_enabled else BEE_DEFAULT_PORT_HTTP
9493

9594

96-
# You should preload your *.crt file (the whole chain) in here if you want TLS.
97-
# I usually concatenate my /etc/ssl/certs/ca-certificates.crt and webserver certs here.
98-
# Remember to add the *.crt file to the exports, if necessary.
95+
## You should preload your *.crt file (the whole chain) in here if you want TLS.
96+
## I usually concatenate my /etc/ssl/certs/ca-certificates.crt and webserver certs here.
97+
## Remember to add the *.crt file to the exports, if necessary.
9998
@export var trusted_chain: X509Certificate # only used if tls is enabled
10099
@export var common_name_override := "" # for TLSOptions
101100

102101

103-
# Dynamic accessor using the TLS properties above, but you may inject your own
104-
# for example if you need to use TLSOptions.client_unsafe. Best not @export this.
102+
## Dynamic accessor using the TLS properties above, but you may inject your own
103+
## for example if you need to use TLSOptions.client_unsafe. Best not @export this.
105104
var tls_options: TLSOptions:
106105
set(value):
107106
tls_options = value
@@ -131,7 +130,7 @@ func log_debug(message: String):
131130

132131

133132
# Authentication method `petstore_auth`.
134-
# → Skipped: not implemented in the gdscript templates. (contribs welcome)
133+
# → Skipped: not implemented in the gdscript templates. (contribs are welcome)
135134

136135

137136
# Authentication method `api_key`.

samples/client/petstore/gdscript/addons/oas.petstore.client/core/DemoApiError.gd

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ class_name DemoApiError
1414
# it will trigger the error callback, with an instance of this as parameter.
1515
#
1616

17-
# Helps finding the error in the code, among other things.
18-
# Could be a UUID, or even a translation key, so long as it's unique.
19-
# Right now we're mostly using a lowercase ~namespace joined by dots. (.)
17+
## Helps finding the error in the code, among other things.
18+
## Could be a UUID, or even a translation key, so long as it's unique.
19+
## Right now we're mostly using a lowercase ~namespace joined by dots. (.)
2020
@export var identifier := ""
2121

22-
# A message for humans. May be multiline.
22+
## A message for humans. May be multiline.
2323
@export var message := ""
2424

25-
# One of Godot's ERR_XXXX, when relevant.
25+
## One of Godot's ERR_XXXX, when relevant.
2626
@export var internal_code := OK
2727

28-
# The HTTP response code, if any. (usually >= 400)
29-
# DEPRECATED: prefer reading from response object below
28+
## The HTTP response code, if any. (usually >= 400)
29+
## DEPRECATED: prefer reading from response object below
3030
@export var response_code := HTTPClient.RESPONSE_OK
3131

32-
# The HTTP response, if any.
32+
## The HTTP response, if any.
3333
@export var response: DemoApiResponse
3434

3535

0 commit comments

Comments
 (0)