diff --git a/chat-client-python/chat_client.py b/chat-client-python/chat_client.py index 9681119..f15fe26 100755 --- a/chat-client-python/chat_client.py +++ b/chat-client-python/chat_client.py @@ -1,14 +1,19 @@ #!/usr/bin/env python3 from typing import List +from importlib import metadata +from packaging import version from chat_openapi.exceptions import ApiException from chat_openapi.configuration import Configuration from chat_openapi.api_client import ApiClient from chat_openapi.api.chat_api import ChatApi -from chat_openapi.model.chat_message import ChatMessage -from chat_openapi.model.new_chat_message_request import NewChatMessageRequest -from chat_openapi.model.background_color_enum import BackgroundColorEnum +from chat_openapi.models.chat_message import ChatMessage +from chat_openapi.models.new_chat_message_request import NewChatMessageRequest +from chat_openapi.models.background_color_enum import BackgroundColorEnum +if version.parse(metadata.version('pydantic')) < version.parse("2.0"): + print("pydantic 2+ required") + exit(1) configuration = Configuration(host="http://localhost:8080") configuration.debug = False @@ -18,17 +23,22 @@ try: # get all messages + print("all messages:") messages: List[ChatMessage] = chat.get_all_messages() - for msg in messages: - print("(%s)" % msg.author, msg.text) + for idx, msg in enumerate(messages): + print("#%d (author: %s)" % (idx, msg.author), msg.text) # create a new message + print() + print("new messages:") msg_req = NewChatMessageRequest(text="Hello!", text_color="black", background_color=BackgroundColorEnum("lightgray")) msg: ChatMessage = chat.create_message(msg_req, author="Joe") - print("(%s)" % msg.author, msg.text) + print("(author: %s)" % msg.author, msg.text) - # would cause exception - # chat.get_message("-1") + # handling exception + print() + print("expected exception for non-existent message id:") + msg = chat.get_message("-1") except ApiException as e: print("Exception: %s\n" % e) diff --git a/chat-client-python/generate.sh b/chat-client-python/generate.sh index 03f2618..96b23b5 100755 --- a/chat-client-python/generate.sh +++ b/chat-client-python/generate.sh @@ -1,13 +1,13 @@ #!/bin/bash -GENERATOR_VERSION=6.3.0 +GENERATOR_VERSION=7.4.0 if [ ! -f "openapi-generator-cli-$GENERATOR_VERSION.jar" ] ; then wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/$GENERATOR_VERSION/openapi-generator-cli-$GENERATOR_VERSION.jar fi rm -rf chat_openapi # see https://openapi-generator.tech/docs/usage#generate -# and https://openapi-generator.tech/docs/generators/python-prior +# and https://openapi-generator.tech/docs/generators/python java \ --add-opens java.base/java.util=ALL-UNNAMED \ --add-opens java.base/java.lang=ALL-UNNAMED \ @@ -16,8 +16,7 @@ java \ -DmodelDocs=true \ -DmodelTests=false \ -jar openapi-generator-cli-$GENERATOR_VERSION.jar generate \ - --generator-name python-prior \ + --generator-name python \ --input-spec ../openapi.yaml \ - --model-package model \ --additional-properties=generateSourceCodeOnly=true,packageName=chat_openapi