Skip to content

Commit

Permalink
updated python client for generator version 7.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-kuba committed Apr 2, 2024
1 parent c87ad6f commit e97cc79
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
26 changes: 18 additions & 8 deletions chat-client-python/chat_client.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
7 changes: 3 additions & 4 deletions chat-client-python/generate.sh
Original file line number Diff line number Diff line change
@@ -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 \
Expand All @@ -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

0 comments on commit e97cc79

Please sign in to comment.