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

OpenAPI defect introduced by extracting request/response bodies to schema references #18578

Closed
maxb opened this issue Jan 2, 2023 · 3 comments
Assignees
Labels
bug Used to indicate a potential bug devex Developer Experience

Comments

@maxb
Copy link
Contributor

maxb commented Jan 2, 2023

Describe the bug
#14217 changed OpenAPI generation to extract the details of the JSON format of requests and responses, from being in-line with the relevant operations, to being defined in a separate portion of the document, and referenced by name.

Critically, the names assigned to these request/response schemas, are not sufficiently unique. This leads to some silently overwriting others, and generating an OpenAPI document that contains lies about actual requests/responses.

To Reproduce
Steps to reproduce the behavior:

  1. Start up a vault server -dev - use a 1.13-dev make dev-ui build for this, as it seems 1.12 isn't showing responses in the API explorer at all.
  2. Enable an approle auth method
  3. Open up the API explorer
  4. Observe the GET​ /auth​/{approle_mount_path}​/role/{role_name} endpoint, specifically that it claims its response will look identical to the GET​ /auth​/{approle_mount_path}​/role endpoint - these are entirely different endpoints, but the response for one has overwritten the other during OpenAPI generation.

Additional context
With the introduction of plugin versioning in Vault 1.12, there is now a new related problem - you could be running multiple different versions of a plugin, which have different parameters for their APIs. The current approach of seeking to flatten all request/response formats into named references becomes even more problematic - you'd have to disambiguate between different versions of request/response for the same endpoint in plugin mounts running different versions.

For these reasons, I believe the change to use request/response schemas should be reverted, returning to inline definition, which will more reliably associate the correct parameters with each endpoint.

@averche averche self-assigned this Jan 3, 2023
@averche averche added the devex Developer Experience label Jan 3, 2023
@averche
Copy link
Contributor

averche commented Jan 3, 2023

Hi @maxb! You are correct, this is indeed an issue with the current request/response naming function. I believe it should be resolved in #18321, which has a shared naming pattern for operationIds, request names and response names. For the examples you mentioned, the following operationIds and response names will be generated:

GET​ /auth​/{approle_mount_path}​/role
    OperationID: AppRoleListRoles
  Response name: AppRoleListRolesResponse
 
GET​ /auth​/{approle_mount_path}​/role/{role_name}`
    OperationID: AppRoleReadRole
  Response name: AppRoleReadRoleResponse

For a bit of background, we are working on generating client libraries from this OpenAPI spec. Without extracting request and response bodies (and giving them sensible names), openapi generators have no way of knowing what to call these request/response objects in the generated libraries. This results in anonymous structs/classes being generated for requests and responses with meaningless names like RequestStruct1.

@maxb
Copy link
Contributor Author

maxb commented Jan 4, 2023

Right - but that does need to be balanced with avoiding naming clashes, that result in the incorrect Request/Response objects being associated with some APIs. Let's continue the thread of conversation in #18321, to avoid splitting it between an issue and a PR.

@peteski22 peteski22 added the bug Used to indicate a potential bug label Jan 10, 2023
@averche
Copy link
Contributor

averche commented May 4, 2023

Hi @maxb! The #19319 (OpenAPI naming changes) and ~40 related PR's have been successfully merged for all the builtin plugins (both within this repo and in hashicorp/vault-plugin-*). As a result, all the OperationID's for built-in plugins and the corresponding request/response names are now unique:

GET/auth/{approle_mount_path}​/role
    OperationID: app-role-list-roles
  Response name: AppRoleListRolesResponse
 
GET/auth/{approle_mount_path}​/role/{role_name}`
    OperationID: app-role-read-role
  Response name: AppRoleReadRoleResponse

In general,

 request name = titleCase(operationID) + "Request"
response name = titleCase(operationID) + "Response"

Thanks again for bringing up this issue and contributing to the OpenAPI-related work!

@averche averche closed this as completed May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Used to indicate a potential bug devex Developer Experience
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants