Skip to content

KeyError with OpenAPI URL and Form data. #2579

@cochiseruhulessin

Description

@cochiseruhulessin

When I expose an endpoint with the following signature:

    @frf.action(detail=False, methods=['post'])                                                          
    async def token(self,                                                                                
        response: Response,                                                                              
        grant_type: str = Form(None),                                                                    
        client_id: str = Form(None),                                                                     
        code: str = Form(None),                                                                          
        redirect_uri: str = Form(None),                                                                  
        assertion: str = Form(None),                                                                     
        scope: str = Form(None),                                                                         
        resource: str = Form(None),                                                                      
        clients=frf.ContextualInjected('ClientRepository')                                               
    ): 

I get KeyError when running the following test case:

class ApplicationMetadataEndpointsTestCase(unittest.TestCase):                                           
                                                                                                         
    def setUp(self):                                                                                     
        self.client = TestClient(get_asgi_application())                                                 
                                                                                                         
    def test_openapi_url_is_served(self):                                                                
        response = self.client.get(settings.OPENAPI_URL)                                                 
        self.assertEqual(response.status_code, 200)

The error is:

    def get_model_definitions(
        *,
        flat_models: Set[Union[Type[BaseModel], Type[Enum]]],
        model_name_map: Dict[Union[Type[BaseModel], Type[Enum]], str],
    ) -> Dict[str, Any]:
        definitions: Dict[str, Dict[str, Any]] = {}
        for model in flat_models:
            m_schema, m_definitions, m_nested_models = model_process_schema(
                model, model_name_map=model_name_map, ref_prefix=REF_PREFIX
            )
            definitions.update(m_definitions)
>           model_name = model_name_map[model]
E           KeyError: <class 'pydantic.main.Body_oauth2_token_token_post'>

.lib/python/runtime/fastapi/utils.py:28: KeyError

This error does not occur when visiting /ui in the browser.

FastAPI version is 0.63.0.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions