Springdoc-openapi: @Schema(hidden = true) does not work with data model class

Created on 17 Aug 2020  路  6Comments  路  Source: springdoc/springdoc-openapi

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:
@Document@Data @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.

All 6 comments

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 FailedUseris 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:

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.

@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,

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?

@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.

@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!

Was this page helpful?
0 / 5 - 0 ratings