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

@Schema(hidden = true) does not work with data model class #826

Closed
abuklis opened this issue Aug 17, 2020 · 6 comments
Closed

@Schema(hidden = true) does not work with data model class #826

abuklis opened this issue Aug 17, 2020 · 6 comments
Labels
enhancement New feature or request

Comments

@abuklis
Copy link

abuklis commented Aug 17, 2020

Hi,
I am Hanna Buklis, backend developer.
I started using springdoc-openapi-ui on my current project a few days ago.
I faced the following issue: I cannot hide on certain schema from 'Schemas' list in ui section.
Schemas list:
image

I checked documentation, it looks like @Schema(hidden = true) should hide a class from the list above.

My setup:
Spring Boot 2.2.6.RELEASE
springdoc-openapi: 1.4.3
springdoc-openapi-data-rest: 1.4.3

Entity class which I want to hide:

@AllArgsConstructor
@NoArgsConstructor
@Schema(hidden = true)
public class FailedUser {
    @Id
    private String id;
}

Application properties :
springdoc.api-docs.resolve-schema-properties=true
springdoc.api-docs.enabled=true
springdoc.api-docs.path=/doc/definition
springdoc.swagger-ui.path=/doc/docs
springdoc.swagger-ui.supportedSubmitMethods=["get"]

After this configuration, I expect FailedUser to be absent in 'Schemas' list. But it is still in place.
Could you please tell me if this is a bug or wrong configuration?

Thank you in advance.

Best regards,
Hanna Buklis.

@bnasslahsen
Copy link
Contributor

bnasslahsen commented Aug 18, 2020

Hi @abuklis,

Not sure which springdoc documentation you are refering to about the usage of @Schema on the class level:
It looks more an issue in the swagger-core code:

Here is the code snippet, that shows it.
You can submit your issue to the swagger team with the following:

	ResolvedSchema resolvedSchema = ModelConverters.getInstance()
				.resolveAsResolvedSchema(
						new AnnotatedType(FailedUser.class).resolveAsRef(true));
		Assert.isNull(resolvedSchema.schema, "The schema should be hidden.");

This is said, you have many workarounds depending on your case:

  • if the class FailedUser is a parameter of your controller, you can use you can use the annotation @Hidden on the class, or @Parameter(hidden = true) or @RequestBody(hidden=true). (The support of @Hidden on the response objects, will be also available on the next release!)

  • If its on the response, you can use: empty content return if its relevant:

    Otherwise, if you want the schema to be hidden from the response object, the OpenAPI generated documentation will be not valid.

  • if the class FailedUser is a field in another class, then: You can add on the field level instead:

@jlorenzoC
Copy link

jlorenzoC commented Oct 23, 2020

Hi @bnasslahsen , I'm new at springdoc openapi 3 cuz I'm collaborating on a project that is using it. So, in my case my problem is that I'm not seeing in this object schemas list, some already defined models. Some models are there, but others are not.
Definition of missing schema E.g.:

public class A {
  ...
}

Please, why is that happening? Cheers.

@bnasslahsen
Copy link
Contributor

@jlorenzoC,

You should have the getter/setter, for all your fields.
If it is already the case, could you add more details about your class A, with a sample minimal sample including a HelloController that references it?

@jlorenzoC
Copy link

jlorenzoC commented Oct 23, 2020

@jlorenzoC,

You should have the getter/setter, for all your fields.
If it is already the case, could you add more details about your class A, with a sample minimal sample including a HelloController that references it?

Thanks @bnasslahsen for your fast reply. In this context, how would you reference a model A in a controller to get it to work?

@bnasslahsen
Copy link
Contributor

@jlorenzoC,

You have a lot of samples for test controllers in the project tests.
For example, the code here:

If you have any other question, please make sure you provide the requested code samples.

@jlorenzoC
Copy link

@bnasslahsen thanks bro. Issue solved! You helped me to solve the issue. The problem was that the controller of the model A wasn't referencing it like you just showed me. Thanks a lot!

@bnasslahsen bnasslahsen added the enhancement New feature or request label Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants