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

Can org.eclipse.microprofile.openapi.models.OpenAPI and its "children" return null on getters? #558

Open
hbelmiro opened this issue Feb 28, 2023 · 1 comment

Comments

@hbelmiro
Copy link
Contributor

hbelmiro commented Feb 28, 2023

I couldn't find in the docs whether OpenAPI's getters can return null. For example, could the following code throw a NullPointerException?

    private static Optional<Schema> getSchemaRef(String id, OpenAPI openAPI) {
        return Optional.ofNullable(openAPI.getComponents().getSchemas().get(id));
    }

It would be helpful to have it explicitly stated in the #getComponents() and #getSchemas() Javadoc whether they can or cannot return null values, or if it's up to the implementation."

@MikeEdgar MikeEdgar added this to the MP OpenAPI 4.0 milestone Aug 7, 2023
@Azquelt
Copy link
Member

Azquelt commented Aug 7, 2023

I agree that the Javadoc should state where null may be returned or passed as a parameter and what it means. We should add that in the next release.

To my eye, the fact that the model API has separate set and get methods for collections suggests that null is permitted and may be returned.

In a Security Requirement Object, there's a difference between a key being present and set to an empty array vs. not being present which would make changing the API to be null free API more difficult.

There are a few other things the model API javadoc also doesn't make clear:

  • We also don't state whether you can call e.g. getComponents, make changes to it and expect your changes to be reflected in the model or whether getComponents returns a copy or an immutable object.
  • We don't provide a way to copy or clone a model object

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants