Skip to content

The requestBody declared with $ref is not generating json_body #595

Closed

Description

@RockyMM

Describe the bug
If a requestBody is declared with a $ref, then no json_body property is generated. If the reference is inlined, then json_body is generated.

To Reproduce
Steps to reproduce the behaviour:

  1. Example schema:
paths:
  "/objects":
    post:
      operationId: object_create
      requestBody:
        $ref: "#/components/requestBodies/Object"

  1. generated API is:
def sync_detailed(
    *,
    client: Client,
) -> Response[Object]:
    """
    Returns:
        Response[Object]
    """

    kwargs = _get_kwargs(
        client=client,
    )

    response = httpx.request(
        verify=client.verify_ssl,
        **kwargs,
    )

    return _build_response(response=response)

Expected behavior
The expected API should be:

def sync_detailed(
    *,
    client: Client,
    json_body: Object,
) -> Response[Object]:
    """
    Args:
        json_body (Object):

    Returns:
        Response[Object]
    """

    kwargs = _get_kwargs(
        client=client,
        json_body=json_body,
    )

    response = httpx.request(
        verify=client.verify_ssl,
        **kwargs,
    )

    return _build_response(response=response)

OpenAPI Spec File
test.yaml

Activity

  1. added
    🐞bug
    on Mar 31, 2022
  2. kigawas commented on Jun 13, 2022

    @kigawas
    Contributor

    Hi I just submitted a PR above which works with your yaml. It'll be helpful if you have some time to review

    Output

    def sync_detailed(
        *,
        client: Client,
        json_body: Object,
    ) -> Response[Object]:
        """
        Args:
            json_body (Object):
    
        Returns:
            Response[Object]
        """
    
        kwargs = _get_kwargs(
            client=client,
            json_body=json_body,
        )
    
        response = httpx.request(
            verify=client.verify_ssl,
            **kwargs,
        )
    
        return _build_response(response=response)
    
    async def asyncio_detailed(
        *,
        client: Client,
        json_body: Object,
    ) -> Response[Object]:
        """
        Args:
            json_body (Object):
    
        Returns:
            Response[Object]
        """
    
        kwargs = _get_kwargs(
            client=client,
            json_body=json_body,
        )
    
        async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
            response = await _client.request(**kwargs)
    
        return _build_response(response=response)
  3. Leemur89 commented on Dec 12, 2023

    @Leemur89

    hello, do you have an update on the ongoing PR? I'm facing the exact same issue :/

  4. kigawas commented on Dec 13, 2023

    @kigawas
    Contributor

    @Leemur89 This library seems not actively maintained. I recommend just using the official openapi generator

  5. Leemur89 commented on Dec 14, 2023

    @Leemur89

    @kigawas are you sure? It just got a new release last week
    Otherwise do you hav the link to the official openapi generator please? I've been using this one to generate custom python code and could not find a better one
    (however I found a workaround to dereference my swagger file)

  6. kigawas commented on Dec 15, 2023

    @kigawas
    Contributor

    @Leemur89 The biggest problem is that it only supports Open API v3.0 partially and has no plan to upgrade, while fastapi has already shifted to 3.1. If some day I may have to change to use another library, I'd rather change it now.

    #585

  7. dbanty commented on Dec 15, 2023

    @dbanty
    Collaborator

    @Leemur89 The biggest problem is that it only supports Open API v3.0 partially and has no plan to upgrade, while fastapi has already swifted to 3.1. If some day I may have to change to use another library, I'd rather change it now.

    3.1 support is in progress in #856 . I would categorize this project as "lightly maintained", I am still working on it but it's (mostly) only me and it's not my focus.

  8. kigawas commented on Dec 15, 2023

    @kigawas
    Contributor

    @dbanty Glad to hear you are working on this!

  9. added a commit that references this issue on Jun 15, 2024
    32f6f67
  10. added a commit that references this issue on Jun 15, 2024
    cb32c30
  11. added 2 commits that reference this issue on May 13, 2025
    4cc84a8
    26a54b2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐞bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions