Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated REST API interface method return type depends on order of content types #284

Open
jsenko opened this issue Jul 5, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@jsenko
Copy link
Member

jsenko commented Jul 5, 2024

Given the following operation:

"/admin/export": {
  "get": {
    "description": "Exports registry data as a ZIP archive.",
    "operationId": "exportData",
    "parameters": [
      {
        "description": "Indicates if the operation is done for a browser.  If true, the response will be a JSON payload with a property called `href`.  This `href` will be a single-use, naked download link suitable for use by a web browser to download the content.",
        "in": "query",
        "name": "forBrowser",
        "schema": {
          "type": "boolean"
        }
      }
    ],
    "responses": {
      "200": {
        "content": {
          "application/zip": {
            "schema": {
              "$ref": "#/components/schemas/FileContent"
            }
          },
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/DownloadRef"
            }
          }
        },
        ...
      },
      ...
    },
    ...
  },
  ...
}

the generated method is:

/**
 * <p>
 * Exports registry data as a ZIP archive.
 * </p>
 * 
 */
@Path("/export")
@GET
@Produces({"application/json", "application/zip"})
Response exportData(@QueryParam("forBrowser") Boolean forBrowser);

If we reverse the order of the content types:

"/admin/export": {
  "get": {
    "description": "Exports registry data as a ZIP archive.",
    "operationId": "exportData",
    "parameters": [
      {
        "description": "Indicates if the operation is done for a browser.  If true, the response will be a JSON payload with a property called `href`.  This `href` will be a single-use, naked download link suitable for use by a web browser to download the content.",
        "in": "query",
        "name": "forBrowser",
        "schema": {
          "type": "boolean"
        }
      }
    ],
    "responses": {
      "200": {
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/DownloadRef"
            }
          },
          "application/zip": {
            "schema": {
              "$ref": "#/components/schemas/FileContent"
            }
          }
        },
        ...
      },
      ...
    },
    ...
  },
  ...
}

the generated method is:

/**
 * <p>
 * Exports registry data as a ZIP archive.
 * </p>
 * 
 */
@Path("/export")
@GET
@Produces({"application/json", "application/zip"})
DownloadRef exportData(@QueryParam("forBrowser") Boolean forBrowser);

JSON is semantically equivalent if any of the map keys are reordered, so the generator should always generate the first method.

@jsenko jsenko added the bug Something isn't working label Jul 5, 2024
jsenko added a commit to jsenko/apicurio-registry that referenced this issue Jul 5, 2024
jsenko added a commit to jsenko/apicurio-registry that referenced this issue Jul 7, 2024
jsenko added a commit to Apicurio/apicurio-registry that referenced this issue Jul 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant