You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by Jim Talbut <jt...@spudsoft.co.uk> on 2018/05/10 16:51:15 UTC
OpenApiFeature with customizer
Hi,
Is it possible to use a customizer to modify the OpenApi data in the
same way that it is with a Swagger Customizer?
I have this:
@Bean
@Autowired
public OpenApiFeature openApiFeature(MyOpenApiCustomizer customizer) {
OpenApiFeature feature = new OpenApiFeature();
feature.setVersion("1.0.0");
feature.setLicense("");
feature.setLicenseUrl("");
feature.setSupportSwaggerUi(true);
feature.setScan(true);
feature.setCustomizer(customizer);
feature.setTitle("Service API");
feature.setDescription("The service does stuff\n");
return feature;
}
Where MyOpenApiCustomizer just overrides one customize method:
@Override
public void customize(OpenAPI oas) {
super.customize(oas);
StringBuilder builder = new StringBuilder();
builder.append(oas.getInfo().getDescription());
builder.append("More docs");
oas.getInfo().description(builder.toString());
}
I'm getting the standard openapi.json data out, but my customizer isn't
being called at all.
In OpenApiCustomizedResource it's looking for an OpenApiContext with a
CXF ID, but not finding one.
What's wrong?
Thanks
Jim
Re: OpenApiFeature with customizer
Posted by Andriy Redko <dr...@gmail.com>.
Hi Jim,
You certainly should be able to do that. It seems like there were slight
changes between Swagger 2.0.0/2.0.1 releases with respect to handling context id,
that's why the OpenApiCustomizedResource is not finding one. What you could do
right now, as a workaround, is to override this method:
public OpenAPIConfiguration customize(final OpenAPIConfiguration configuration) {
final OpenAPIConfiguration config = super.customize(configuration);
final OpenAPI oas = config.getOpenAPI();
// you code here
return config;
}
It seems to work fine. We'll be working on a proper fix, but it may take some
time since the way Swagger manages configuration / models is very different now.
Thank you.
Best Regards,
Andriy Redko
JT> Hi,
JT> Is it possible to use a customizer to modify the OpenApi data in the
JT> same way that it is with a Swagger Customizer?
JT> I have this:
JT> @Bean
JT> @Autowired
JT> public OpenApiFeature openApiFeature(MyOpenApiCustomizer customizer) {
JT> OpenApiFeature feature = new OpenApiFeature();
JT> feature.setVersion("1.0.0");
JT> feature.setLicense("");
JT> feature.setLicenseUrl("");
JT> feature.setSupportSwaggerUi(true);
JT> feature.setScan(true);
JT> feature.setCustomizer(customizer);
JT> feature.setTitle("Service API");
JT> feature.setDescription("The service does stuff\n");
JT> return feature;
JT> }
JT> Where MyOpenApiCustomizer just overrides one customize method:
JT> @Override
JT> public void customize(OpenAPI oas) {
JT> super.customize(oas);
JT> StringBuilder builder = new StringBuilder();
JT> builder.append(oas.getInfo().getDescription());
JT> builder.append("More docs");
JT> oas.getInfo().description(builder.toString());
JT> }
JT> I'm getting the standard openapi.json data out, but my customizer isn't
JT> being called at all.
JT> In OpenApiCustomizedResource it's looking for an OpenApiContext with a
JT> CXF ID, but not finding one.
JT> What's wrong?
JT> Thanks
JT> Jim