springdoc-openapi icon indicating copy to clipboard operation
springdoc-openapi copied to clipboard

Spring Data REST: force openapi schema export

Open fkjaekel opened this issue 2 years ago • 3 comments

When working with SDR, I need that the associated resources are expanded in the returned JSON. I have achieved this by adding @RestResource(exported = false) to the associated resource. For example:

@NotNull
@RestResource(exported = false)
@ManyToOne(fetch = FetchType.EAGER)
private Client client;

So far so good, as I can read and write to the association without extra requests. The problem is that I use openapi-generator to create feign clients of the API, and in this case the Client entity is not exported in the openapi schema, so I need this workaround to get it exported:

public Client getClientInline()
{
    return client;
}

I'd like to know if is there any way to get rid of this workaround. I made a test with an excerpt projection, but the schema also doesn't get exported. Adding @SchemaProperty also doesn't helps.

This is the current schema output:

"EntityModelIntegrationConfig": {
"required": [
"client",
"cron",
"enabled",
"template"
],
"type": "object",
"properties": {
"id": {
"type": "string",
"format": "uuid",
"readOnly": true
},
"cron": {
"type": "string"
},
"enabled": {
"type": "boolean"
},
"templateInline": {
"$ref": "#/components/schemas/Template"
},
"clientInline": {
"$ref": "#/components/schemas/Client"
},
"links": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Link"
}
}
}
}

The expected behavior is to have client and template to be treated as properties, so I can remove the additional "inline" getters.

Sorry to post this here, but I didn't figured this out by looking at documentation / source code / stackoverflow

Thanks in advance

fkjaekel avatar Jul 05 '23 11:07 fkjaekel

If you are reporting a bug, please help to speed up problem diagnosis by providing as much information as possible:

  • You need to describe your context (the title of an issue is not enough)
  • What version of spring-boot you are using?
  • What modules and versions of springdoc-openapi are you using?
  • What are the actual and the expected result using OpenAPI Description (yml or json)?
  • Provide a Minimal, Reproducible Example - with HelloController that reproduces the problem

This ticket will be closed and can be reopened if the relevant information are provided.

bnasslahsen avatar Jul 16 '23 11:07 bnasslahsen

@bnasslahsen I pushed #2511 to fix this.

clementdenis avatar Feb 15 '24 14:02 clementdenis

Thanks @clementdenis, I will take care of it very soon!

bnasslahsen avatar Feb 15 '24 14:02 bnasslahsen

Fixed by https://github.com/springdoc/springdoc-openapi/pull/2501

bnasslahsen avatar Feb 26 '24 16:02 bnasslahsen