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

Migrate Swagger to OpenAPI 3 #840

Closed
stevespringett opened this issue Nov 18, 2020 · 8 comments
Closed

Migrate Swagger to OpenAPI 3 #840

stevespringett opened this issue Nov 18, 2020 · 8 comments
Labels
api docs enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed needs milestone Issues or PRs that are pending a milestone assignment p2 Non-critical bugs, and features that help organizations to identify and reduce risk

Comments

@stevespringett
Copy link
Member

The current swagger definition is autogenerated. The automatically generated definitions rely on reflection and annotations to create the documentation. The reflection capabilities are poor at best and lead to missing API parameters. Annotations can help in some cases, but the only fix for Swagger is to create individual POJOs for every possible request. This will lead to unnecessary large number of classes and affects on GC.

Therefore, in order to migrate to OpenAPI 3 and have to deal with similar issues (the Java implementations are virtually the same), the only way to accurately describe the API is to manually keep it updated.

This ticket is to track the removal of Swagger from Alpine and from Dependency-Track and to include support for OpenAPI 3 definitions that can be authored and improved by the community over time.

Related to stevespringett/Alpine#1

@stevespringett stevespringett added enhancement New feature or request p2 Non-critical bugs, and features that help organizations to identify and reduce risk labels Nov 18, 2020
@sephiroth-j
Copy link
Contributor

You can import the current swagger.json and convert it to openapi.yml using https://editor.swagger.io/, so you do not have to start from scratch. This site is also a good starting point for writing openapi.yml files. I have made good experiences with it.

@ruckc
Copy link

ruckc commented Nov 19, 2021

FWIW, creating pojos for every request isn't strictly necessary, mainly only the Create/Update requests which don't accept all parameters (i.e. trying to pass uuid in on create project when it gets ignored).

@nscuro
Copy link
Member

nscuro commented Jun 3, 2022

I think I posted this in Slack a while back already, but another good approach we can take is to generate resource definitions (read: interfaces with all sorts of validation annotations) and DTOs from the openapi YAML. The generator for jaxrs-spec could work.

That way the YAML will be the single source of truth. We get syntactic validation for free in many cases, and because we have to implement interfaces we can be sure our code matches what we advertise.

There will be additional work in mapping between persistent models and DTOs, but that can be a benefit. Due to DataNucleus fetching some properties lazily, they are sometimes missing in API responses, even though they should be there. We won't have that issue if we explicitly map our types.

@nscuro
Copy link
Member

nscuro commented Sep 16, 2023

Moving to a later milestone. FTR, this issue is intertwined with the migration from Java EE to Jakarta EE namespaces, which includes an upgrade of Jersey and Jetty. The current proposed way forward is documented here: stevespringett/Alpine#402 (comment)

@nscuro nscuro modified the milestones: 4.9, 4.10 Sep 16, 2023
@nscuro nscuro added the needs milestone Issues or PRs that are pending a milestone assignment label Oct 26, 2023
@nscuro nscuro removed this from the 4.10 milestone Oct 26, 2023
@nscuro
Copy link
Member

nscuro commented May 17, 2024

We are migrating to OpenAPI v3 via #3726. This issue will remain open however, since the goal of manually maintaining the OpenAPI spec is still to be done.

@jmezach
Copy link

jmezach commented Aug 16, 2024

I just pulled the OpenAPI v3 document from a the snapshot version running locally using docker-compose and it seems that there is just one small issue with it making the document invalid:

Errors:
        - attribute paths.'/version'(get).responses.200.description is missing

Thought I'd post that here :).

@nscuro
Copy link
Member

nscuro commented Aug 16, 2024

Thanks @jmezach, will be fixed in stevespringett/Alpine#631

I seem to have encountered this as well while migrating the DT code base, but chose to ignore it back then just so I can proceed with said migration:

final List<String> validationMessages = parseResult.getMessages();
// Version resource is defined in Alpine and outside our control.
validationMessages.removeIf("attribute paths.'/version'(get).responses.200.description is missing"::equals);
assertThat(validationMessages).isEmpty();

Copy link
Contributor

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api docs enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed needs milestone Issues or PRs that are pending a milestone assignment p2 Non-critical bugs, and features that help organizations to identify and reduce risk
Projects
None yet
Development

No branches or pull requests

5 participants