Posts
Chat
Members
Info
September 4, 2020 at 10:05pm
September 8, 2020 at 3:05pm
@ConditionalOnMissingBeanpublic Swagger buildSwagger(EntityDictionary dictionary, ElideConfigProperties settings) {Info info = new Info().title(settings.getSwagger().getName()).version(settings.getSwagger().getVersion());SwaggerBuilder builder = new SwaggerBuilder(dictionary, info).withLegacyFilterDialect(false);Swagger swagger = builder.build().basePath(settings.getJsonApi().getPath());return swagger;}
You can then add your data types and controller directly to the Swagger object.
September 10, 2020 at 3:36pm
The examples I'm finding online is to do something like this
@Configurationpublic class Swagger2Config {@Beanpublic Docket productApi() {return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.basePackage("com.demo.resource")).paths(regex("/v1.*")).build();}}
However, only using the swagger object, I've tried a few different ways of adding the class and I'm not getting any traction:
@RestController@RequestMapping("/api/v1")@Api(tags = "Layers")public class LayerController {...@GetMapping("/layers/hospitals/{x}/{y}/{radius}")public String findNearbyHospitals(@PathVariable double x, @PathVariable double y, @PathVariable double radius) {return this.toGeoJson(repository.findNearby(x, y, radius)).toString();}...}
and working with swagger I've tried adding a definition
Model lcModel = new ModelImpl().name("LayerController").type("LayerController");lcModel.setReference("...");
and working with the model directly - which I'm not finding a lot of examples on
Path value = new Path();Operation op = new Operation();swagger.getPaths().put("LayerController", value ); // ???swagger.path("LayerControl", value); // ???
do you have an example or some direction you can provide to help me with this?
September 10, 2020 at 9:55pm
Swagger core is a lower level API - so Spring won't help here.
The last example above from your different trials is what I was recommending (using Swagger object directly from swagger models). It is possible there is a way to get access to the same object from Spring - but I'm not sure how to do it.
The Swagger object is pretty much identical to what gets serialized over the wire as the Open API document.
So if you see something in the swagger specification - you can and will find it in the Swagger object.
For example, this is the code that converts the Swagger object to JSON text:
* @param swagger Swagger-Core swagger POJO* @return Pretty printed 'Swagger' document in JSON.*/public static String getDocument(Swagger swagger) {return Json.pretty(swagger);}
Json.pretty is provided by swagger directly - and it just uses Jackson to directly serialize it.
This following might also be helpful
You will notice open API has a few different versions. They are working on 3.0.X. but
swagger-core uses an older version of the Open API specification:
The above link has the document for the swagger object:
Swagger Object This is the root document object for the API specification. It combines what previously was the Resource Listing and API Declaration (version 1.2 and earlier) together into one document.
Hope that link helps.
September 22, 2020 at 8:32pm
Is there polymorphic support for relationships? There are a few ways to go about this with hibernate but when trying to implement them, I've been getting various errors. The specifications I received require an "action" relationship, allowing one of several Resource Types to be used in the relationship. How can I best support this specification?
Simply, I want to support something like this
{"data": [{"id": "1","type": "some_type","attributes": {"attr1": "string"},"relationships": {"action_detail": {"data": {"id": "5","type": "exercise"}}}},{"id": "2","type": "some_type","attributes": {"attr1": "string"},"relationships": {"action_detail": {"data": {"id": "66","type": "clone_protocol_order"}}}},{"id": "3","type": "some_type","attributes": {"attr1": "string"},"relationships": {"action_detail": {"data": null}}}]}