api: fix schema not referencing errors correctly

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2022-09-11 23:01:26 +02:00
parent 15c34c6f1f
commit fd7a7a6e64
8 changed files with 5939 additions and 1201 deletions

View File

@ -139,7 +139,7 @@ jobs:
working-directory: web
run: |
npm ci
make -C .. gen-client-web
make -C .. gen-client-ts
npm run build
- name: run e2e
run: |
@ -173,7 +173,7 @@ jobs:
working-directory: web/
run: |
npm ci
make -C .. gen-client-web
make -C .. gen-client-ts
npm run build
- name: run e2e
run: |

View File

@ -23,7 +23,7 @@ jobs:
- working-directory: web/
run: npm ci
- name: Generate API
run: make gen-client-web
run: make gen-client-ts
- name: Eslint
working-directory: web/
run: npm run lint
@ -39,7 +39,7 @@ jobs:
- working-directory: web/
run: npm ci
- name: Generate API
run: make gen-client-web
run: make gen-client-ts
- name: prettier
working-directory: web/
run: npm run prettier-check
@ -60,7 +60,7 @@ jobs:
cd node_modules/@goauthentik
ln -s ../../src/ web
- name: Generate API
run: make gen-client-web
run: make gen-client-ts
- name: lit-analyse
working-directory: web/
run: npm run lit-analyse
@ -86,7 +86,7 @@ jobs:
- working-directory: web/
run: npm ci
- name: Generate API
run: make gen-client-web
run: make gen-client-ts
- name: build
working-directory: web/
run: npm run build

View File

@ -16,7 +16,7 @@ jobs:
node-version: '16'
registry-url: 'https://registry.npmjs.org'
- name: Generate API Client
run: make gen-client-web
run: make gen-client-ts
- name: Publish package
working-directory: gen-ts-api/
run: |

View File

@ -49,24 +49,44 @@ lint:
bandit -r authentik tests lifecycle -x node_modules
golangci-lint run -v
migrate:
python -m lifecycle.migrate
run:
go run -v cmd/server/main.go
i18n-extract: i18n-extract-core web-extract
i18n-extract-core:
ak makemessages --ignore web --ignore internal --ignore web --ignore web-api --ignore website -l en
#########################
## API Schema
#########################
gen-build:
AUTHENTIK_DEBUG=true ak make_blueprint_schema > blueprints/schema.json
AUTHENTIK_DEBUG=true ak spectacular --file schema.yml
gen-diff:
git show $(shell git tag -l | tail -n 1):schema.yml > old_schema.yml
docker run \
--rm -v ${PWD}:/local \
--user ${UID}:${GID} \
docker.io/openapitools/openapi-diff:2.0.1 \
--markdown /local/diff.md \
/local/old_schema.yml /local/schema.yml
rm old_schema.yml
gen-clean:
rm -rf web/api/src/
rm -rf api/
gen-client-web:
gen-client-ts:
docker run \
--rm -v ${PWD}:/local \
--user ${UID}:${GID} \
openapitools/openapi-generator-cli:v6.0.0 generate \
docker.io/openapitools/openapi-generator-cli:v6.0.0 generate \
-i /local/schema.yml \
-g typescript-fetch \
-o /local/gen-ts-api \
@ -84,7 +104,7 @@ gen-client-go:
docker run \
--rm -v ${PWD}:/local \
--user ${UID}:${GID} \
openapitools/openapi-generator-cli:v6.0.0 generate \
docker.io/openapitools/openapi-generator-cli:v6.0.0 generate \
-i /local/schema.yml \
-g go \
-o /local/gen-go-api \
@ -95,13 +115,7 @@ gen-client-go:
gen-dev-config:
python -m scripts.generate_config
gen: gen-build gen-clean gen-client-web
migrate:
python -m lifecycle.migrate
run:
go run -v cmd/server/main.go
gen: gen-build gen-clean gen-client-ts
#########################
## Web

View File

@ -18,13 +18,13 @@ class AppSerializer(PassiveSerializer):
class AppsViewSet(ViewSet):
"""Read-only view set list all installed apps"""
"""Read-only view list all installed apps"""
permission_classes = [IsAdminUser]
@extend_schema(responses={200: AppSerializer(many=True)})
def list(self, request: Request) -> Response:
"""List current messages and pass into Serializer"""
"""Read-only view list all installed apps"""
data = []
for app in sorted(get_apps(), key=lambda app: app.name):
data.append({"name": app.name, "label": app.verbose_name})

View File

@ -60,8 +60,28 @@ def postprocess_schema_responses(result, generator, **kwargs): # noqa: W0613
for path in result["paths"].values():
for method in path.values():
method["responses"].setdefault("400", validation_error.ref)
method["responses"].setdefault("403", generic_error.ref)
method["responses"].setdefault(
"400",
{
"content": {
"application/json": {
"schema": validation_error.ref,
}
},
"description": "",
},
)
method["responses"].setdefault(
"403",
{
"content": {
"application/json": {
"schema": generic_error.ref,
}
},
"description": "",
},
)
result["components"] = generator.registry.build(spectacular_settings.APPEND_COMPONENTS)

4706
schema.yml

File diff suppressed because it is too large Load Diff

View File

@ -14,10 +14,10 @@ The generated files are stored in `/api` in the root of the repository.
## Building the Web Client
The web client is used by the web-interface and web-FlowExecutor to communicate with authentik. To build the client, run `make gen-client-web`.
The web client is used by the web-interface and web-FlowExecutor to communicate with authentik. To build the client, run `make gen-client-ts`.
Since the client is normally distributed as an npm package, running `make gen-client-web` will overwrite the locally installed client with the newly built one.
Since the client is normally distributed as an npm package, running `make gen-client-ts` will overwrite the locally installed client with the newly built one.
:::warning
Running `npm i` in the `/web` folder after using `make gen-client-web` will overwrite the custom client and revert to the upstream client.
Running `npm i` in the `/web` folder after using `make gen-client-ts` will overwrite the custom client and revert to the upstream client.
:::