pierrejeambrun commented on code in PR #43841: URL: https://github.com/apache/airflow/pull/43841#discussion_r1846178851
########## airflow/api_fastapi/common/headers.py: ########## @@ -0,0 +1,48 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +from fastapi import Depends, Header, HTTPException, status +from typing_extensions import Annotated + +from airflow.api_fastapi.common.types import Mimetype + + +def header_accept_json_or_text_depends( + accept: Annotated[ + str, + Header( + json_schema_extra={ + "type": "string", + "enum": [Mimetype.JSON, Mimetype.TEXT], Review Comment: Are we missing the `Mimetype.Any` ? ########## tests/api_fastapi/core_api/routes/public/test_config.py: ########## @@ -0,0 +1,460 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +import textwrap +from typing import Generator +from unittest.mock import patch + +import pytest + +from tests_common.test_utils.config import conf_vars + +HEADERS_JSON = {"Accept": "application/json"} +HEADERS_TEXT = {"Accept": "text/plain"} +HEADERS_INVALID = {"Accept": "invalid"} +HEADERS_JSON_UTF8 = {"Accept": "application/json; charset=utf-8"} Review Comment: We are missing a test with `*/*` I think ########## tests/api_fastapi/core_api/routes/public/test_dag_sources.py: ########## @@ -79,7 +79,9 @@ def test_should_respond_200_text(self, test_client): json.loads(response.content.decode()) assert response.headers["Content-Type"].startswith("text/plain") - @pytest.mark.parametrize("headers", [{"Accept": "application/json"}, {}]) + @pytest.mark.parametrize( + "headers", [{"Accept": "application/json"}, {"Accept": "application/json; charset=utf-8"}, {}] Review Comment: Here to `*/*` should behave as `application/json` ########## airflow/api_fastapi/core_api/openapi/v1-generated.yaml: ########## @@ -1439,6 +1442,154 @@ paths: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' + /public/config/: + get: + tags: + - Config + summary: Get Config + operationId: get_config + parameters: + - name: section + in: query + required: false + schema: + anyOf: + - type: string + - type: 'null' + title: Section + - name: accept + in: header + required: false + schema: + type: string + enum: + - application/json + - text/plain + default: '*/*' + title: Accept + responses: + '200': + description: Successful Response + content: + application/json: + schema: + $ref: '#/components/schemas/Config' + text/plain: + schema: + type: string + example: '[core] + + dags_folder = /opt/airflow/dags + + base_log_folder = /opt/airflow/logs + + ' + '401': + content: + application/json: + schema: + $ref: '#/components/schemas/HTTPExceptionResponse' + description: Unauthorized + '403': + content: + application/json: + schema: + $ref: '#/components/schemas/HTTPExceptionResponse' + description: Forbidden + '404': + content: + application/json: + schema: + $ref: '#/components/schemas/HTTPExceptionResponse' + description: Not Found + '406': + content: + application/json: + schema: + $ref: '#/components/schemas/HTTPExceptionResponse' + description: Not Acceptable + '422': + description: Validation Error + content: + application/json: + schema: + $ref: '#/components/schemas/HTTPValidationError' + /public/config/section/{section}/option/{option}: + get: + tags: + - Config + summary: Get Config Value + operationId: get_config_value + parameters: + - name: section + in: path + required: true + schema: + type: string + title: Section + - name: option + in: path + required: true + schema: + type: string + title: Option + - name: accept + in: header + required: false + schema: + type: string + enum: + - application/json + - text/plain + default: '*/*' + title: Accept + responses: + '200': + description: Successful Response + content: + application/json: + schema: + $ref: '#/components/schemas/Config' + text/plain: + schema: + type: string + example: '[core] + Review Comment: Why do we have line break between every lines in the example ? ########## airflow/api_fastapi/core_api/openapi/v1-generated.yaml: ########## @@ -1439,6 +1442,154 @@ paths: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' + /public/config/: + get: + tags: + - Config + summary: Get Config + operationId: get_config + parameters: + - name: section + in: query + required: false + schema: + anyOf: + - type: string + - type: 'null' + title: Section + - name: accept + in: header + required: false + schema: + type: string + enum: + - application/json + - text/plain + default: '*/*' + title: Accept + responses: + '200': + description: Successful Response + content: + application/json: + schema: + $ref: '#/components/schemas/Config' + text/plain: + schema: + type: string + example: '[core] + + dags_folder = /opt/airflow/dags + + base_log_folder = /opt/airflow/logs + + ' + '401': + content: + application/json: + schema: + $ref: '#/components/schemas/HTTPExceptionResponse' + description: Unauthorized + '403': + content: + application/json: + schema: + $ref: '#/components/schemas/HTTPExceptionResponse' + description: Forbidden + '404': + content: + application/json: + schema: + $ref: '#/components/schemas/HTTPExceptionResponse' + description: Not Found + '406': + content: + application/json: + schema: + $ref: '#/components/schemas/HTTPExceptionResponse' + description: Not Acceptable + '422': + description: Validation Error + content: + application/json: + schema: + $ref: '#/components/schemas/HTTPValidationError' + /public/config/section/{section}/option/{option}: + get: + tags: + - Config + summary: Get Config Value + operationId: get_config_value + parameters: + - name: section + in: path + required: true + schema: + type: string + title: Section + - name: option + in: path + required: true + schema: + type: string + title: Option + - name: accept + in: header + required: false + schema: + type: string + enum: + - application/json + - text/plain + default: '*/*' + title: Accept + responses: + '200': + description: Successful Response + content: + application/json: + schema: + $ref: '#/components/schemas/Config' + text/plain: + schema: + type: string + example: '[core] + Review Comment: Also should we only have one value here ? ########## airflow/api_fastapi/core_api/openapi/v1-generated.yaml: ########## @@ -1439,6 +1442,154 @@ paths: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' + /public/config/: + get: + tags: + - Config + summary: Get Config + operationId: get_config + parameters: + - name: section + in: query + required: false + schema: + anyOf: + - type: string + - type: 'null' + title: Section + - name: accept + in: header + required: false + schema: + type: string + enum: + - application/json + - text/plain + default: '*/*' + title: Accept + responses: + '200': + description: Successful Response + content: + application/json: + schema: + $ref: '#/components/schemas/Config' + text/plain: + schema: + type: string + example: '[core] + + dags_folder = /opt/airflow/dags + + base_log_folder = /opt/airflow/logs + + ' Review Comment: Here we need at least 2 sections (as in the legacy doc) to show that multiples sections are returned in parison to the other endpoint. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
