Skip to content

OperationID from embedded spec doesn't match the original spec #1274

Closed

Description

@skoo25

Version: v1.15

I'm not sure if this is by design, but given an OAPI spec

openapi: "3.0.0"
info:
  title: "my spec"
  version: 1.0.0
paths:
  /pet:
    get:
      operationId: getPet
      responses:
        200:
          content:
            application/json:
              schema:
                type: string

OperationId from the embedded spec is set as GetPet rather than getPet. I used the generated GetSwagger() function to convert embedded spec to openapi3.T object.

Activity

  1. nickajacks1 commented on Sep 21, 2023

    @nickajacks1

    this capitalization is done explicitly, see ToCamelCase in the codegen package.
    This was probably done so that the generated function always gets exported. Users would probably find it surprising if the capitalization of the operation ID in their spec controlled whether the resulting function is exported or not.

  2. skoo25 commented on Sep 22, 2023

    @skoo25
    Author

    this capitalization is done explicitly, see ToCamelCase in the codegen package. This was probably done so that the generated function always gets exported. Users would probably find it surprising if the capitalization of the operation ID in their spec controlled whether the resulting function is exported or not.

    Indeed. I'm trying to write a middleware utilizing Operation ID specified within the embedded spec. However, the capitalization proves to be a challenge, as the ID is case-sensitive according to the OAPI specification.

  3. nickajacks1 commented on Sep 22, 2023

    @nickajacks1

    Right now there's a generation option that controls capitalization of initialims. Perhaps there could be single option that controls various modes of capitalization, including force-camel-case, force-camel-case with Go initialisms, and a new preserve casing option. Then in v2 the initialisms specific parameter could be removed. @jamietanna any thoughts on adding a new parameter for strict case preservation?

    From the Openapi 3.1.0 spec:

    Tools and libraries MAY use the operationId to uniquely identify an operation, therefore, it is RECOMMENDED to follow common programming naming conventions.

    From this, it sounds like OpenAPI recommends we write operation IDs with Go name conventions in mind, so "MyOpID" instead of "myOpId". Of course, that complicates things a tad when you access a single API is shared between languages..

  4. jamietanna commented on Nov 28, 2024

    @jamietanna
    Member

    I think a good option here - with the current state of the codebase - would be to add a "name normalizer" which is a No-Op for this use-case.

    That being said, it'd probably not make sense, as that'd impact all types generated.

    An additional parameter for "do not modify operationIds" would be a good option

  5. jamietanna commented on Apr 7, 2025

    @jamietanna
    Member

    This should now be fixed under #1945 which introduces a new configuration option to opt-in to the behaviour.

    This is also something that I would see as being a good option to be a default behaviour as of oapi-codegen v3 (if we ever get there!)

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

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions