Skip to content

Commit 005543c

Browse files
committed
fix(openapi): fix additionalProperties definition
Previously additionalProperties were indented wrongly so that they appeared as a regular property. Also, adjust the controller code correspondingly. Depends on the openapi-generator PR OpenAPITools/openapi-generator#19312 (otherwise additionalProperties support does not work with the python-fastapi generator)
1 parent 84ad17f commit 005543c

3 files changed

Lines changed: 9 additions & 11 deletions

File tree

Makefile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ BUILD_IMG=beets-websearch-build
99
DOCKER_OPTS=--rm -u `id -u`:`id -g` \
1010
-v "`pwd`:/work" -w /work \
1111
--entrypoint sh $(BUILD_IMG) -c
12-
OPENAPI_GENERATOR_VERSION=131fd518fbfe894cfa23619ede96adab707630d9 # v7.7.0+patch
12+
OPENAPI_FILE=openapi.yaml
13+
#OPENAPI_GENERATOR_VERSION=131fd518fbfe894cfa23619ede96adab707630d9 # v7.7.0+patch
14+
OPENAPI_GENERATOR_VERSION=24b70a9200dc8532900a2896154081995c29fa91
1315

1416

1517
.PHONY: wheel
1618
wheel: clean python-container
1719
docker run $(DOCKER_OPTS) 'python3 setup.py bdist_wheel'
1820

1921
.PHONY: validate-openapi
20-
validate-openapi: OPENAPI_FILE=openapi.yaml
2122
validate-openapi:
2223
@echo Validating the OpenAPI spec at $(OPENAPI_FILE)
2324
@docker run -t --rm --mount "type=bind,src=$(realpath $(OPENAPI_FILE)),dst=/openapi.yaml" \
@@ -31,7 +32,7 @@ validate-openapi:
3132
generate: PKG=beetsplug.websearch
3233
generate: .openapi-generator ## Generate server stub
3334
rm -rf ./build/src-gen
34-
docker run -ti --rm -v "`pwd`:/work" -w /work -u `id -u`:`id -g` openapitools/openapi-generator-cli:local-$(OPENAPI_GENERATOR_VERSION) generate -i ./openapi.yaml -g python-fastapi -o ./build/src-gen --package-name=$(PKG).gen -p sourceFolder= -p fastapiImplementationPackage=$(PKG).controller
35+
docker --debug run -ti --rm -v "`pwd`:/work" -w /work -u `id -u`:`id -g` openapitools/openapi-generator-cli:local-$(OPENAPI_GENERATOR_VERSION) generate -i $(OPENAPI_FILE) -g python-fastapi -o ./build/src-gen --package-name=$(PKG).gen -p sourceFolder= -p fastapiImplementationPackage=$(PKG).controller
3536
rm -rf ./beetsplug/websearch/gen
3637
cp -r ./build/src-gen/beetsplug/websearch/gen ./beetsplug/websearch/gen
3738

@@ -96,5 +97,5 @@ python-container:
9697
docker build --force-rm -t openapitools/openapi-generator-cli:local-$(OPENAPI_GENERATOR_VERSION) build/openapi-generator
9798

9899
build/openapi-generator:
99-
git clone -c advice.detachedHead=0 https://github.com/OpenAPITools/openapi-generator.git build/openapi-generator
100+
git clone -c advice.detachedHead=0 https://github.com/mgoltzsche/openapi-generator.git build/openapi-generator
100101

beetsplug/websearch/controller/__init__.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,8 @@ async def list_tracks(
9999
Track(
100100
id="123",
101101
title="Serpiente Dorada",
102-
# TODO: make this work (generated code expects a string currently):
103-
#additional_properties={
104-
# "genre": "Dub",
105-
# "bpm": "90",
106-
#},
102+
genre=str("Dub"),
103+
bpm=str("90"),
107104
),
108105
],
109106
)

openapi.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ components:
189189
type: string
190190
title:
191191
type: string
192-
additionalProperties:
193-
type: string
192+
additionalProperties:
193+
type: string
194194
required:
195195
- id
196196
- title

0 commit comments

Comments
 (0)