Skip to content

code generated for components.requestBodies is invalid when described with same type as components.schemas #254

Closed

Description

@mahbh2001

When the code is generated for types with the swagger definition containing components.requestBodies and components.schemas have the same type name, the resulting code generated is not compilable. e.g. Pet

paths:
/pets:
post:
summary: Add a new pet
requestBody:
$ref: '#/components/requestBodies/Pet'
/pets/{petId}
put:
summary: Update a pet
parameters: [ ... ]
requestBody:
$ref: '#/components/requestBodies/Pet'
components:
requestBodies:
Pet:
description: A JSON object containing pet information
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'

Activity

  1. tooolbox commented on Jan 3, 2021

    @tooolbox
    Contributor

    Any advice on getting around this?

  2. mahbh2001 commented on Jan 3, 2021

    @mahbh2001
    Author
  3. tooolbox commented on Jan 5, 2021

    @tooolbox
    Contributor

    Yeah, I have a spec I don't want to mess with.

    Ideally the types generated for request bodies have some kind of configurable suffix to allow devs to resolve conflicts like this.

  4. dmhdeveloper commented on May 13, 2021

    @dmhdeveloper

    I have also encountered the same issue, around the use of Response as a suffix for components. I have a solution that changes the suffix to HTTPResponse, which I think is less likely to create a conflict.

    Could I put up a pull request for this?

    EDIT: Appologies, did not have the time to look into adding this but it looks to be resolved in an upcoming release.

  5. DannyHinshaw commented on Aug 17, 2021

    @DannyHinshaw

    @dmhdeveloper I'd be very interested in seeing that, though I wonder if it would be better to make the response suffix a configuration detail so that there are no breaking changes. The idea would be the default would remain the same, but we could add an additional config to specify if we want to change the default suffix:

    oapi-codegen -package=openapi3 -generate=types -response-suffix=HTTPResponse -o ./somedir ./some-spec.yaml

    I'd be more than willing to help with this as well as we're running into issues with duplicate types generated from specs from a 3rd party.

    Thoughts?

  6. ryan-bever commented on Jul 4, 2022

    @ryan-bever

    Just ran into this as well. I can work-around the issue, but since this library is so great would like to see this issue actually resolved.

  7. mromaszewicz commented on Feb 7, 2026

    @mromaszewicz
    Member

    The experimental v3 codegen in /experimental should support this.

  8. mromaszewicz commented on Mar 2, 2026

    @mromaszewicz
    Member

    This was addressed in #2213, please enable name conflict resolution via the output options and file a new issue if it doesn't work for you

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions