forked from loafle/openapi-generator-original
* feat(gdscript): sketch implementation of gdscript target language This does not really work yet, but it's a start. Results are not denormalized, no support for enums nor datetimes, and thousands of other features are missing. I still don't know how we are going to denormalize JSON+LD without writing a whole GDScript lib for it… * feat: add an exhaustive list of keywords reserved in GDScript I've also provided the small python script I used to generate the list. * refacto(gdscript): start using partials in templates Whilst I'm racking my brains trying to figure out integration testing… * test(gdscript): prepare a demo and integration testing * fix(gdscript): do not use subclasses, use plain POGO (plain ol' godot object) One: I don't know how they work under-the-hood. Two: I'm very confused over-the-hood. Tri: We do not need them. * refacto(gdscript): move demo files to their own directory I know I'm making a lot of commits for not much, but now I'm opening the sample files with Godot as well, and doing unholy things with filesystems, so I'm not taking any chances. It's all going to be squashed anyway. :) * fix(gdscript): sample as a Godot project It works ! I can now write integration tests in GDScript. The real work starts now. /spend 25h * feat(gdscript): serialize and send body params The test suite is now past its first hurdle, the 415 HTTP status code, and went straight into an unexpected error 500. I suspect the server does not like me trying to set the pet id at 0, because that's what we're trying to do right now. Godot is crashing a lot, mostly because I don't know how to make Callable.NOOP and my current solution hints at optional on_success and on_failure, yet if we omit them the engine will ragequit. * feat(gdscript): check request body for required yet missing properties Now we'll get a nice error when we forget to set a required property. The demo is now able to: - connect - create a user - login as that user - create a pet * feat(gdscript): namespace core classes as well with apiPrefixName This makes our usage of `class_name` a little more acceptable. * feat(gdscript): support prefixes and suffixes for class names This will crutch namespacing well enough for most uses. * feat(gdscript): handle enums, naively * feat(gdscript): support basic API endpoint param constraints - minLength - maxLength - minItems - maxItems - minimum - maximum - pattern (no flags) * feat(gdscript): handle header params and header customization We also support serializing to application/x-www-form-urlencoded now. Next up: DateTimes ! * feat(gdscript): handle Date and DateTime like Strings There's no timezone support in Godot for DateTimes. * feat(gdscript): support plain text responses * feat(gdscript): support collections of models Those are Arrays, not custom collection objects. * feat(gdscript): configure default host from OAS * feat(gdscript): some documentation and better config We don't need no factories nor singletons ; config is enough. * docs(gdscript): document usage a little * feat(gdscript): add more reserved words, skip jsonld models and configure features We can now generate a client for an OAS server running ApiPlatform (PHP). * feat(gdscript): improve logging with a configurable log level * feat(gdscript): add support for Basic Bearer and Header ApiKey (but I can't find the `description` template handler) * fix(gdscript) Too late to amend >.< * fix(gdscript) dangsarnit * chore(gdscript): clean up a sprint artifact * fix: don't forget the HTTP error code when relevant * feat: use Resource as base class for models * fix. Default string values now with "quotes" * temporary remove settings as godot api have changed * kick ci * docs: review gdscript java class * feat: support for TLS, some refacto, some review There's still a lot of holes, TODOs and FIXMEs. * feat: experimental support of Request inline objects The inline response objects are still not supported. * feat(gdscript): support inline request and response objects * chore(gdscript): review the templates * fix(gdscript): unexpected nulls in default values {{#if defaultValue}} evaluates to true for null if we call super here. * refacto(gdscript): replace "bee" prefix by "bzz", use a constructor Now we pass the config and the client via the constructor. This reduces the area of the public surface a bit, for the better I think. This commit also cleans up the class name shenanigans. * fix(gdscript): add missing file * test(gdscript): refactor the test project to use the generated lib as addon Since there is no singleton in the generated client, the addon need not be enabled in the project configuration to be usable. The --headless mode is broken for now, as things changed in Godot 4 since the beta. * docs(gdscript): document petstore server ADR * test(gdscript): add GUT and an integration test We used the latest stable GUT, but a feature we're going to need was merged today, so we'll need to update it either to master or to the next release at some point. * refacto(gdscript, breaking): use an ApiResponse object in success callbacks /spent 6d since the beginning * test(gdscript): update integration tests /spend 2h * docs(gdscript): explain the new ApiResponse Also moving core templates to their own subdir, for clarity. /spend 10m * chore(gdscript): review, document, clean up /spend 2h * test(gdscript): test the delete operation as well /spend 7m * feat(gdscript): update GUT and exit with appropriate code /spend 2h * docs(gdscript): add Gdscript's PI Hire me while I'm available ! :D I'd rather code than make a CV. * feat(gdscript): support reserved keywords Also adding some more assertions, and using our own OAS file now. /spend 3h * refacto(gdscript): use "base" instead of "bee" /spend 1h * feat(gdscript): improve descriptions /spend 1h * fix(gdscript): await before polling Contributed by @jchu231 * docs(gdscript): review the template files * docs(gdscript): review and generate docs --------- Co-authored-by: Bagrat <b.saatsazov@gmail.com>
183 lines
4.8 KiB
GDScript
183 lines
4.8 KiB
GDScript
# ------------------------------------------------------------------------------
|
|
# Interface and some basic functionality for all printers.
|
|
# ------------------------------------------------------------------------------
|
|
class Printer:
|
|
var _format_enabled = true
|
|
var _disabled = false
|
|
var _printer_name = 'NOT SET'
|
|
var _show_name = false # used for debugging, set manually
|
|
|
|
func get_format_enabled():
|
|
return _format_enabled
|
|
|
|
func set_format_enabled(format_enabled):
|
|
_format_enabled = format_enabled
|
|
|
|
func send(text, fmt=null):
|
|
if(_disabled):
|
|
return
|
|
|
|
var formatted = text
|
|
if(fmt != null and _format_enabled):
|
|
formatted = format_text(text, fmt)
|
|
|
|
if(_show_name):
|
|
formatted = str('(', _printer_name, ')') + formatted
|
|
|
|
_output(formatted)
|
|
|
|
func get_disabled():
|
|
return _disabled
|
|
|
|
func set_disabled(disabled):
|
|
_disabled = disabled
|
|
|
|
# --------------------
|
|
# Virtual Methods (some have some default behavior)
|
|
# --------------------
|
|
func _output(text):
|
|
pass
|
|
|
|
func format_text(text, fmt):
|
|
return text
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Responsible for sending text to a GUT gui.
|
|
# ------------------------------------------------------------------------------
|
|
class GutGuiPrinter:
|
|
extends Printer
|
|
var _textbox = null
|
|
|
|
var _colors = {
|
|
red = Color.RED,
|
|
yellow = Color.YELLOW,
|
|
green = Color.GREEN
|
|
}
|
|
|
|
func _init():
|
|
_printer_name = 'gui'
|
|
|
|
func _wrap_with_tag(text, tag):
|
|
return str('[', tag, ']', text, '[/', tag, ']')
|
|
|
|
func _color_text(text, c_word):
|
|
return '[color=' + c_word + ']' + text + '[/color]'
|
|
|
|
# Remember, we have to use push and pop because the output from the tests
|
|
# can contain [] in it which can mess up the formatting. There is no way
|
|
# as of 3.4 that you can get the bbcode out of RTL when using push and pop.
|
|
#
|
|
# The only way we could get around this is by adding in non-printable
|
|
# whitespace after each "[" that is in the text. Then we could maybe do
|
|
# this another way and still be able to get the bbcode out, or generate it
|
|
# at the same time in a buffer (like we tried that one time).
|
|
#
|
|
# Since RTL doesn't have good search and selection methods, and those are
|
|
# really handy in the editor, it isn't worth making bbcode that can be used
|
|
# there as well.
|
|
#
|
|
# You'll try to get it so the colors can be the same in the editor as they
|
|
# are in the output. Good luck, and I hope I typed enough to not go too
|
|
# far that rabbit hole before finding out it's not worth it.
|
|
func format_text(text, fmt):
|
|
if(_textbox == null):
|
|
return
|
|
|
|
if(fmt == 'bold'):
|
|
_textbox.push_bold()
|
|
elif(fmt == 'underline'):
|
|
_textbox.push_underline()
|
|
elif(_colors.has(fmt)):
|
|
_textbox.push_color(_colors[fmt])
|
|
else:
|
|
# just pushing something to pop.
|
|
_textbox.push_normal()
|
|
|
|
_textbox.add_text(text)
|
|
_textbox.pop()
|
|
|
|
return ''
|
|
|
|
func _output(text):
|
|
if(_textbox == null):
|
|
return
|
|
|
|
_textbox.add_text(text)
|
|
|
|
func get_textbox():
|
|
return _textbox
|
|
|
|
func set_textbox(textbox):
|
|
_textbox = textbox
|
|
|
|
# This can be very very slow when the box has a lot of text.
|
|
func clear_line():
|
|
_textbox.remove_line(_textbox.get_line_count() - 1)
|
|
_textbox.queue_redraw()
|
|
|
|
func get_bbcode():
|
|
return _textbox.text
|
|
|
|
func get_disabled():
|
|
return _disabled and _textbox != null
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# This AND TerminalPrinter should not be enabled at the same time since it will
|
|
# result in duplicate output. printraw does not print to the console so i had
|
|
# to make another one.
|
|
# ------------------------------------------------------------------------------
|
|
class ConsolePrinter:
|
|
extends Printer
|
|
var _buffer = ''
|
|
|
|
func _init():
|
|
_printer_name = 'console'
|
|
|
|
# suppresses output until it encounters a newline to keep things
|
|
# inline as much as possible.
|
|
func _output(text):
|
|
if(text.ends_with("\n")):
|
|
print(_buffer + text.left(text.length() -1))
|
|
_buffer = ''
|
|
else:
|
|
_buffer += text
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Prints text to terminal, formats some words.
|
|
# ------------------------------------------------------------------------------
|
|
class TerminalPrinter:
|
|
extends Printer
|
|
|
|
var escape = PackedByteArray([0x1b]).get_string_from_ascii()
|
|
var cmd_colors = {
|
|
red = escape + '[31m',
|
|
yellow = escape + '[33m',
|
|
green = escape + '[32m',
|
|
|
|
underline = escape + '[4m',
|
|
bold = escape + '[1m',
|
|
|
|
default = escape + '[0m',
|
|
|
|
clear_line = escape + '[2K'
|
|
}
|
|
|
|
func _init():
|
|
_printer_name = 'terminal'
|
|
|
|
func _output(text):
|
|
# Note, printraw does not print to the console.
|
|
printraw(text)
|
|
|
|
func format_text(text, fmt):
|
|
return cmd_colors[fmt] + text + cmd_colors.default
|
|
|
|
func clear_line():
|
|
send(cmd_colors.clear_line)
|
|
|
|
func back(n):
|
|
send(escape + str('[', n, 'D'))
|
|
|
|
func forward(n):
|
|
send(escape + str('[', n, 'C'))
|