diff --git a/.openapi-generator-ignore b/.openapi-generator-ignore index f6ba2ad..31bef38 100644 --- a/.openapi-generator-ignore +++ b/.openapi-generator-ignore @@ -21,6 +21,8 @@ #docs/*.md # Then explicitly reverse the ignore rule for a single file: #!docs/README.md -gen/openapi_server/controllers/patchnotes_controller.py gen/openapi_server/__main__.py gen/openapi_server/encoder.py +gen/openapi_server/controllers +gen/openapi_server/test +gen/openapi_server diff --git a/announcement_service_spec.yaml b/announcement_service_spec.yaml index 240c8ab..e1f1c03 100644 --- a/announcement_service_spec.yaml +++ b/announcement_service_spec.yaml @@ -93,6 +93,10 @@ components: date: title: date type: string + required: + - "title" + - "changes" + - "date" user: example: lastSeenDate: 2025-01-02 diff --git a/gen/Dockerfile b/gen/Dockerfile new file mode 100644 index 0000000..4857637 --- /dev/null +++ b/gen/Dockerfile @@ -0,0 +1,16 @@ +FROM python:3-alpine + +RUN mkdir -p /usr/src/app +WORKDIR /usr/src/app + +COPY requirements.txt /usr/src/app/ + +RUN pip3 install --no-cache-dir -r requirements.txt + +COPY . /usr/src/app + +EXPOSE 8080 + +ENTRYPOINT ["python3"] + +CMD ["-m", "openapi_server"] \ No newline at end of file diff --git a/gen/openapi_server/__main__.py b/gen/openapi_server/__main__.py index c432aef..67e257f 100644 --- a/gen/openapi_server/__main__.py +++ b/gen/openapi_server/__main__.py @@ -6,7 +6,7 @@ import connexion from openapi_server import encoder from pymongo import MongoClient -client = MongoClient(host='mongodb://localhost:27017/') +client = MongoClient(host='mongodb://host.docker.internal:27017/') db = client["MainDB"] collection = db['patch_notes'] diff --git a/gen/openapi_server/controllers/patchnotes_controller.py b/gen/openapi_server/controllers/patchnotes_controller.py index 16fcc87..c619156 100644 --- a/gen/openapi_server/controllers/patchnotes_controller.py +++ b/gen/openapi_server/controllers/patchnotes_controller.py @@ -1,18 +1,10 @@ import logging - -import connexion -from typing import Dict -from typing import Tuple -from typing import Union +import uuid from bson import json_util from flask import Response -from pymongo import MongoClient -from openapi_server.__main__ import collection from openapi_server.models.patch_notes import PatchNotes # noqa: E501 -from openapi_server import util - def patchnotes_date_get(date): # noqa: E501 @@ -52,22 +44,34 @@ def patchnotes_patch_iddelete(patch_id): # noqa: E501 return 'do some magic!' -def patchnotes_post(body=None): # TODO done for now +def patchnotes_post(body): # TODO _date to date change """patchnotes_post creates new Patch notes # noqa: E501 - :param patch_notes: + :param body: + :param patch_notes: :type patch_notes: dict | bytes :rtype: Union[List[PatchNotes], Tuple[List[PatchNotes], int], Tuple[List[PatchNotes], int, Dict[str, str]] """ - patch_notes = body - logging.error('patch notes' + str(patch_notes)) - if patch_notes is None: + if body is None: return Response(json_util.dumps({'error': 'No patch notes provided'}), status=400) - # Insert the document into the MongoDB collection - posted_patch_id = collection.insert_one(patch_notes) + pn = PatchNotes.from_dict(body) + logging.error('patch_notes_type:' + str(type(pn))) + logging.error('patch notes' + str(pn)) - return Response(json_util.dumps(f'patch with ID: {posted_patch_id} was created'), mimetype='application/json', + patch_notes_uuid = uuid.uuid4() + + patch_notes = { + 'patchID': str(patch_notes_uuid), + 'title': pn.title, + 'changes': pn.changes, + 'date': pn._date, + } + logging.error('patch_notes_type:' + str(type(patch_notes))) + logging.error('patch notes' + str(patch_notes)) + #posted_patch_id = collection.insert_one(patch_notes) + + return Response(json_util.dumps(f'patch with ID: {patch_notes} was created'), mimetype='application/json', status=200) \ No newline at end of file diff --git a/gen/openapi_server/encoder.py b/gen/openapi_server/encoder.py index f60982c..22fb66e 100644 --- a/gen/openapi_server/encoder.py +++ b/gen/openapi_server/encoder.py @@ -15,4 +15,4 @@ class JSONEncoder(ConnexionJSONEncoder): attr = o.attribute_map[attr] dikt[attr] = value return dikt - return ConnexionJSONEncoder.default(self, o) \ No newline at end of file + return ConnexionJSONEncoder.default(self, o) diff --git a/gen/openapi_server/models/patch_notes.py b/gen/openapi_server/models/patch_notes.py index 540229a..275cc6f 100644 --- a/gen/openapi_server/models/patch_notes.py +++ b/gen/openapi_server/models/patch_notes.py @@ -93,6 +93,8 @@ class PatchNotes(Model): :param title: The title of this PatchNotes. :type title: str """ + if title is None: + raise ValueError("Invalid value for `title`, must not be `None`") # noqa: E501 self._title = title @@ -114,6 +116,8 @@ class PatchNotes(Model): :param changes: The changes of this PatchNotes. :type changes: str """ + if changes is None: + raise ValueError("Invalid value for `changes`, must not be `None`") # noqa: E501 self._changes = changes @@ -135,5 +139,7 @@ class PatchNotes(Model): :param _date: The _date of this PatchNotes. :type _date: str """ + if _date is None: + raise ValueError("Invalid value for `_date`, must not be `None`") # noqa: E501 self.__date = _date diff --git a/gen/openapi_server/openapi/openapi.yaml b/gen/openapi_server/openapi/openapi.yaml index 94e6470..c074c75 100644 --- a/gen/openapi_server/openapi/openapi.yaml +++ b/gen/openapi_server/openapi/openapi.yaml @@ -4,7 +4,7 @@ info: title: announcementService version: 1.0.0 servers: -- url: http://127.0.0.1:8080/api +- url: / paths: /patchnotes: post: @@ -102,6 +102,10 @@ components: date: title: date type: string + required: + - changes + - date + - title title: patch_notes user: example: diff --git a/gen/openapi_server/test/__init__.py b/gen/openapi_server/test/__init__.py index 5255d29..364aba9 100644 --- a/gen/openapi_server/test/__init__.py +++ b/gen/openapi_server/test/__init__.py @@ -10,7 +10,7 @@ class BaseTestCase(TestCase): def create_app(self): logging.getLogger('connexion.operation').setLevel('ERROR') - app = connexion.App(__name__ , specification_dir='../openapi/') + app = connexion.App(__name__, specification_dir='../openapi/') app.app.json_encoder = JSONEncoder - app.add_api('openapi.yaml', pythonic_params=True, base_path='/api') + app.add_api('openapi.yaml', pythonic_params=True) return app.app diff --git a/gen/requirements.txt b/gen/requirements.txt index 4ec6b08..2cb0689 100644 --- a/gen/requirements.txt +++ b/gen/requirements.txt @@ -1,8 +1,13 @@ -connexion[swagger-ui, flask, uvicorn] >= 3.2.0 -werkzeug == 3.1.3 +connexion[swagger-ui] >= 2.6.0; python_version>="3.6" +# 2.3 is the last version that supports python 3.4-3.5 +connexion[swagger-ui] <= 2.3.0; python_version=="3.5" or python_version=="3.4" +# prevent breaking dependencies from advent of connexion>=3.0 +connexion[swagger-ui] <= 2.14.2; python_version>"3.4" +# connexion requires werkzeug but connexion < 2.4.0 does not install werkzeug +# we must peg werkzeug versions below to fix connexion +# https://github.com/zalando/connexion/pull/1044 +werkzeug == 0.16.1; python_version=="3.5" or python_version=="3.4" swagger-ui-bundle >= 0.0.2 python_dateutil >= 2.6.0 setuptools >= 21.0.0 -Flask >= 3.1.0 -Flask-PyMongo >= 3.0.1 -pymongo >= 4.11.3 +Flask == 2.1.1