hammock-project/hammock

Add rest-cxf-swagger artifact

Closed this issue · 4 comments

Like documented in the swagger artifacts, cxf manages this itself with an artifact.
Only this cxf dep needs to be equal to the version in rest-cxf.

So an rest-cxf-swagger artifact which argegates rest-cxf and the cxf-rt-rs-service-description-swagger would be nice.

I'm not sure I see a benefit to doing this over the existing util-swagger module in Hammock (which is openapi v3.0.1 now). What features were you looking for from the CXF specific integration?

Ah yes, i assumed the swagger artifact did not work on cxf.
As the swagger/readme.md says not to use it for cxf.
And the hammock-cqrs example uses this seperate cxf-rt-rs-service-description-swagger artifact.

So then its just outdated documentation. (and util-swagger is not there yet)

Yes, sorry, that readme is out of date (had forgotten it was there). Do you in fact see it working?

Yes, it needs the following steps to work;

  • add hammock swagger artifact
  • add annotions like @OpenAPIDefinition and @operation
  • add "/openapi-configuration.json" to classpath resources;
{
    "resourcePackages": [
        "com.example.project"
    ]
}
  • optional fix "class scanning per request" ;
	static {
		try {
			System.out.println("Manual monkey patch OpenApiContextLocator to fix ctxId mismatch somewhere.");
			OpenApiContextLocator loc = OpenApiContextLocator.getInstance();
			Field field = OpenApiContextLocator.class.getDeclaredField("map");
			field.setAccessible(true);
			field.set(loc, new ConcurrentMapSingleKey());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public static class ConcurrentMapSingleKey extends ConcurrentHashMap<String, OpenApiContext> {
		private static final String SINGLE_KEY = ConcurrentMapSingleKey.class.getSimpleName();
		@Override
		public OpenApiContext get(Object key) { return super.get(SINGLE_KEY); }
		@Override
		public OpenApiContext put(String key, OpenApiContext value) { return super.put(SINGLE_KEY, value); }
	}

Maybe bug in rc4 or i missed how to config that correctly :)