Skip to content

1105 progenitor requires operationid to be set #1110

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

Conversation

upachler
Copy link
Contributor

@upachler upachler commented Mar 31, 2025

This PR modifies missing operationId handling from default-deny to default-generate. At this point there is no GenerationSetting for this to be configured, I expect the PR not to go through because of that (to add a GenerationSetting field I feel there is more discussion needed, however, I'm happy to it once it's clear how that is desired).

The algorithm used here tries to apply 'smart' heuristics and is, of course, opinionated. To capsule it all I introduced a the new module opid with a struct OperationIds, which stores mappings between the path method tuple and the operationId (generated or manually set).

The changes to lib.rs try to be minimal, most logic is in opid.rs, as well as most unit tests.

validate_openapi() now runs two passes:

  1. For all operations for which operation_id is present, store that in the OperationIds struct, together with their path/method mapping
  2. For all operations that do not have an `operation_id, generate one and store it, again together with their path/method mapping

OperationIds is stored in the Generator instance.

Later, when requiring an operation_id, these are pulled from the OperationIds struct (rather than the Operation object directly as it has been previously).

Step 2 in above uses an algorithm to generate the name, which also handles collisions with both present operationIds and also its own generated ones.

The name generation algorithm is described in detail in the OperationIds::gen_operation_id() method in the opid.rs file. The basic idea is that names derive from HTTP path and method, which are unique in combination. The path is stripped of non alphanumeric characters and lowercased, and the HTTP method is appended with a '_' prefix.
So 'GET /foo/bar' becomes foo_bar_get. There are more special cases which are documented and covered by the unit tests.

Thanks for reading all this, hope it helps with reviewing the PR :)

@ahl
Copy link
Collaborator

ahl commented May 2, 2025

Thank you for the contribution, but this isn't functionality that we'd like to incorporate in progenitor at this time. We have a couple of projects cooking on the back-burner--in particular support for OpenAPI 3.1--for which I don't want to carry the additional functionality and complexity. I would encourage you to incorporate this functionality either in a fork or in a stand-alone tool that can modify an OpenAPI document (useful for generators beyond progenitor) or generate a JSON patch document that could be applied to an OpenAPI document.

@ahl ahl closed this May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants