Skip to content

Generate resource looking for entire path definition #336

Open

Description

@mathecruz

Created from quarkiverse/quarkus-openapi-generator#876 (reply in thread) discussion.

Having the followin OpenAPI:

issue.json
  {
    "openapi": "3.0.3",
    "info": {
      "title": "Example API",
      "version": "1.0.0"
    },
    "paths": {
      "/v1/inventory": {
        "get": {
          "tags": ["InventoriesResource"],
          "summary": "Retrieve inventories",
          "responses": {
            "200": {
              "description": "A list of inventories",
              "content": {
                "application/json": {
                  "schema": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "example": "inv-123"
                        },
                        "name": {
                          "type": "string",
                          "example": "Main warehouse"
                        },
                        "quantity": {
                          "type": "integer",
                          "example": 100
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "/v1/permissions/inventories": {
        "get": {
          "tags": ["PermissionsResource"],
          "summary": "Retrieve permissions",
          "responses": {
            "200": {
              "description": "A list of inventory permissions",
              "content": {
                "application/json": {
                  "schema": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "userId": {
                          "type": "string",
                          "example": "user-456"
                        },
                        "inventoryId": {
                          "type": "string",
                          "example": "inv-123"
                        },
                        "permission": {
                          "type": "string",
                          "example": "READ"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }

The apicurio-codegen looks the first part of the path /v1 and create a resource called V1Resource instead creating V1PermissionsInventories.

I think it would be great if the apicurio-codegen generates per path and not per path prefix.

cc: @EricWittmann

Activity

  1. mathecruz commented on May 21, 2025

    @mathecruz
    ContributorAuthor

    Investigation notes:

    • When using a path with /widget-names is generating WidgetResource, should not be /WidgetNamesResource?
  2. aservedio-swi commented on May 21, 2025

    @aservedio-swi

    Cross posting quarkiverse/quarkus-openapi-generator#876 (reply in thread) a bit... To summarize, when faced with this same issue, org.openapitools:openapi-generator-maven-plugin would generate a class that matches the name of the tag - but does not prefix it with V1. I believe that the thinking around that is to allow people to gather together like API's into a single implementation with a name that makes sense to them (since they could technically have /v1 and /v2 paths in the same implementation if that is what worked for them).

    So it is the presence of tags AND the generator being told to use tags that alters this behavior. Without both of those things, it just makes a V1Api.java interface and puts everything under that (which, frankly, is probably not what most people would want).

  3. EricWittmann commented on May 21, 2025

    @EricWittmann
    Contributor

    I agree that V1Resource is not desired. We probably need a lot of work in this area to handle all the different ways that endpoints could be defined and resulting JAX-RS interfaces should be structured.

    In this case, one thing you can do right now is this:

    https://github.com/Apicurio/apicurio-registry/blob/main/common/src/main/resources/META-INF/openapi.json#L3510

    "x-codegen-contextRoot": "/apis/registry/v3"

    If you add that vendor extension to the paths, then you can remove the /v1 from all of the endpoints and the generator will create PermissionsInventoriesResource (in this example).

    Of course, if you have a mix of endpoints (some /v1 and others /v2 for example) then this does not help.

    Having that would seem weird to me (better to have two OpenAPI definitions, one for each API version) but I'm sure it happens.

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