springfox swagger Json errors - swagger-2.0

I am new to swagger.
I have the folowing code:
#RestController
#RequestMapping(value = { V1P})
#Api(value = V1P, description= "My Operations Management API")
public class MethodController {
/**
* #return -
*/
#ApiOperation(value = "retrieve task information", notes = "retrieve service instance information", response = String.class)
#ApiResponses(value = {
#ApiResponse(code = 200, message = "Success"),
#ApiResponse(code = 401, message = "Unauthorized"),
#ApiResponse(code = 500, message = "Failure")})
#SuppressWarnings("nls")
#RequestMapping(value = BASE_PATH , method = RequestMethod.GET, consumes = MediaType.TEXT_PLAIN_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> retrieve() {
....
}
#ApiOperation(nickname = "openTaskUsingGet", value = "Open a task", notes = "API to Open a task", response = String.class)
#ApiResponses(value = {
#ApiResponse(code = 200, message = "Success"),
#ApiResponse(code = 401, message = "Unauthorized"),
#ApiResponse(code = 500, message = "Failure")})
#ApiImplicitParams({
#ApiImplicitParam(name = "taskReferenceId", value = "Reference ID of the task", required = true, dataType = "string", paramType = "query"),
#ApiImplicitParam(name = "taskSummary", value = "The task's summary description", required = true, dataType = "string", paramType = "query"),
#ApiImplicitParam(name = "contentDocumentId", value = "The content document ID of the task", required = true, dataType = "string", paramType = "query"),
#ApiImplicitParam(name = "createdBy", value = "The name of the creating user", required = true, dataType = "string", paramType = "query"),
#ApiImplicitParam(name = "teamReferenceId", value = "The creating team reference ID", required = true, dataType = "string", paramType = "query"),
#ApiImplicitParam(name = "taskFromTime", value = "Task planned start time", required = true, dataType = "string", paramType = "query"),
#ApiImplicitParam(name = "taskDueTime", value = "Task planned due time", required = true, dataType = "string", paramType = "query"),
#ApiImplicitParam(name = "taskGroup", value = "Task group name", required = true, dataType = "string", paramType = "query"),
#ApiImplicitParam(name = "taskType", value = "Task type", required = true, dataType = "string", paramType = "query"),
#ApiImplicitParam(name = "siteLongitude", value = "Site longitude coordinate", required = true, dataType = "double", paramType = "query"),
#ApiImplicitParam(name = "siteLatitude", value = "Site latitude coordinate", required = true, dataType = "double", paramType = "query"),
#ApiImplicitParam(name = "siteZipCode", value = "Site zip code", required = true, dataType = "string", paramType = "query"),
#ApiImplicitParam(name = "siteName", value = "Site name", required = true, dataType = "string", paramType = "query"),
#ApiImplicitParam(name = "siteCountry", value = "Site country", required = true, dataType = "string", paramType = "query"),
#ApiImplicitParam(name = "siteState", value = "Site state", required = true, dataType = "string", paramType = "query"),
#ApiImplicitParam(name = "siteCity", value = "Site city", required = true, dataType = "string", paramType = "query"),
#ApiImplicitParam(name = "siteAddress", value = "Site address", required = true, dataType = "string", paramType = "query"),
#ApiImplicitParam(name = "siteComments", value = "Site comments", required = true, dataType = "string", paramType = "query"),
#ApiImplicitParam(name = "siteReferenceId", value = "Site reference ID", required = true, dataType = "string", paramType = "query"),
#ApiImplicitParam(name = "eqType", value = "Equipment type", required = true, dataType = "string", paramType = "query"),
#ApiImplicitParam(name = "eqReferenceId", value = "Equipment reference ID", required = true, dataType = "string", paramType = "query")
})
#SuppressWarnings({ "nls", "javadoc" })
#RequestMapping(value = BASE_PATH + "/mob/openTask" , method = RequestMethod.GET, consumes = MediaType.TEXT_PLAIN_VALUE, produces = MediaType.TEXT_PLAIN_VALUE)
public ResponseEntity<String> openTask(
#RequestParam("taskReferenceId") String taskReferenceId,
#RequestParam("taskSummary") String taskSummary,
#RequestParam("contentDocumentId") String contentDocumentId,
#RequestParam("createdBy") String createdBy,
#RequestParam("teamReferenceId") String teamReferenceId,
#RequestParam("taskFromTime") String taskFromTime,
#RequestParam("taskDueTime") String taskDueTime,
#RequestParam("taskGroup") String taskGroup,
#RequestParam("taskType") String taskType,
#RequestParam("siteLongitude") double siteLongitude,
#RequestParam("siteLatitude") double siteLatitude,
#RequestParam("siteZipCode") String siteZipCode,
#RequestParam("siteName") String siteName,
#RequestParam("siteCountry") String siteCountry,
#RequestParam("siteState") String siteState,
#RequestParam("siteCity") String siteCity,
#RequestParam("siteAddress") String siteAddress,
#RequestParam("siteComments") String siteComments,
#RequestParam("siteReferenceId") String siteReferenceId,
#RequestParam("eqType") String eqType,
#RequestParam("eqReferenceId") String eqReferenceId){
....
}
#ApiOperation(nickname = "openTaskUsingPOST", value = "Open a task", notes = "API to Open a task", response = String.class)
#ApiResponses(value = {
#ApiResponse(code = 200, message = "Success"),
#ApiResponse(code = 401, message = "Unauthorized"),
#ApiResponse(code = 500, message = "Failure")})
#SuppressWarnings({ "nls", "javadoc" })
#RequestMapping(value = BASE_PATH + "/mob/openTask" , method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.TEXT_PLAIN_VALUE)
public ResponseEntity<String> openTask(#RequestBody OpenTaskCmd cmd){
...
}
#ApiOperation(value = "Get an HTML summary of a package content", notes = "API to get an HTML summary of a package content", response = String.class)
#ApiResponses(value = {
#ApiResponse(code = 200, message = "Success"),
#ApiResponse(code = 401, message = "Unauthorized"),
#ApiResponse(code = 500, message = "Failure")})
#ApiImplicitParams({
#ApiImplicitParam(name = "packageName", value = "The name of the required package", required = true, dataType = "string", paramType = "query"),
#ApiImplicitParam(name = "packageVersion", value = "The required package version", required = true, dataType = "string", paramType = "query")
})
#SuppressWarnings({ "nls", "javadoc" })
#RequestMapping(value = BASE_PATH + "/mob/getContent" , method = RequestMethod.GET, consumes = MediaType.TEXT_PLAIN_VALUE, produces = MediaType.TEXT_HTML_VALUE)
public ResponseEntity<String> getContent(#RequestParam("packageName") String pkgName,
#RequestParam("packageVersion") String pkgVersion){
....
}
#ApiOperation(value = "Get the activities of a project as a Json array", notes = "API to get the activities of a project as a Json array")
#ApiResponses(value = {
#ApiResponse(code = 200, message = "Success"),
#ApiResponse(code = 401, message = "Unauthorized"),
#ApiResponse(code = 500, message = "Failure")})
#ApiImplicitParams({
#ApiImplicitParam(name = "startIndex", value = "The first activity index", required = true, dataType = "string", paramType = "query"),
#ApiImplicitParam(name = "pageSize", value = "The number of activities", required = true, dataType = "string", paramType = "query")
})
#SuppressWarnings("javadoc")
#RequestMapping(value = BASE_PATH + "/mob/readActivities" , method = RequestMethod.GET, consumes = MediaType.TEXT_PLAIN_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> readActivities(#RequestParam("startIndex") int startIndex,
#RequestParam("pageSize") int pageSize){
...
}
}
ths is part of the json I get:
{"swagger":"2.0","info":{"description":"Operation Management","version":"v1","title":"API","host":"127.0.0.1","basePath":"/","tags":[{"name":"v1","description":"Operations Management API"}],
"paths":{
"/v1/proxy/resource":{..."responses":{"200":{"description":"Success","schema":{"type":"string"}},"401":{"description":"Unauthorized"},"500":{"description":"Failure","schema":{"$ref":"#/definitions/Error"}}}}},
"/v1/proxy/resource/mob/getContent":{"get":{...,"responses":{"200":{"description":"Success","schema":{"type":"string"}},"401":{"description":"Unauthorized"},"500":{"description":"Failure","schema":{"$ref":"#/definitions/Error"}}}}},
"/v1/proxy/resource/mob/openTask":{"post":{"tags":["v1"],"summary":"Open a task","description":"API to Open a task","operationId":"openTaskUsingPOSTUsingPOST","consumes":["application/json"],"produces":["text/plain"],"parameters":[{"in":"body","name":"cmd","description":"cmd","required":true,"schema":{"$ref":"#/definitions/OpenTaskCmd"}}],"responses":{"200":{"description":"Success","schema":{"type":"string"}},"401":{"description":"Unauthorized"},"500":{"description":"Failure"}}}},
"/v1/proxy/resource/mob/readActivities":{"get":{...,"responses":{"200":{"description":"Success","schema":{"type":"string"}},"401":{"description":"Unauthorized"},"500":{"description":"Failure","schema":{"$ref":"#/definitions/Error"}}}}}},
"definitions":{"OpenTaskCmd":{...}}}}}
There are two issues with the Json I can't figure out:
I have two openTask interfaces, one GET and one POST, but the swagger Json includes only the POST one.
For some of the interfaces I get "schema":{"$ref":"#/definitions/Error"} for the 500 response, but I don't have this schema and I can't understand why I get it only for some of the services.
What am I defining wrong?
Thanks,
Nir

Couple of things to try:
Upgrade to the latest library version (2.6.0 at the time of this post)
Remove all the swagger annotations and see what you get. Taken from the documentation:
Philosophically, we want to discourage using (swagger-core) annotations that are not material to the service description at runtime. For e.g. the jackson annotations should always trump or have more weight than #ApiModelProperty or for e.g. #NotNull or specifying #RequestParam#required should always win. Annotations are to to be used only to supplement documentation or override/tweak the resulting spec in cases where its not possible to infer service/schema characteristics.

Related

is it possible way to customize the sub resource api platform?

The goal was i aiming to is to change identifier from id of entity to JWT token that user has attached at specific path.
#ApiResource(
itemOperations = {
"get" ={
"security" = "is_granted('VIEW',object)",
"normalization_context" = {"groups" = {"read"}}
},
"put" = {
"security" = "is_granted('WRITE',object)",
"normalization_context" = {"groups" = {"get"}},
"denormalization_context" = {"groups" = {"put"}}
},
"api_users_cart_subresource" = {
"method" = "GET",
"path" = "/users/{id}/carts",
"security" = "is_granted('VIEW',object)",
"normalization_context" = {"groups" = {"user:cart"}}
}
},
collectionOperations = {
"post" = {
"denormalization_context" = {"groups" = {"post"}},
"normalization_context" = {"groups" = {"get"}}
},
"get" = {
"access_control" = "is_granted('ROLE_ADMIN')",
"normalization_context" = {"groups" = {"admin:read"}}
}
}
)
is it possible to change the path to /users/carts and return normalized data that belong to the user base from their token?
ps. sorry for my grammar

How to have observable treeview

I am working on an app which requires TreeView.
I'm able to generate the Treeview but facing issue with dynamically updating the treeview based on underlying dataset change.
Classes:
data class Channels(
val channel: Channel? = null
)
data class Channel(
val id: String? = null,
val name: String? = null,
val parentChannelId: String? = null
)
Data List :
var channels = observableListOf(
Channels(channel = Channel(id = "pc1", name = "P Channel 1")),
Channels(channel = Channel(id = "c11", name = "Child 1-1", parentChannelId = "pc1")),
Channels(channel = Channel(id = "c12", name = "Child 1-2", parentChannelId = "pc1")),
Channels(channel = Channel(id = "c121", name = "Child 1-2-1", parentChannelId = "c12")),
Channels(channel = Channel(id = "c111", name = "Child 1-1-1", parentChannelId = "c11")),
Channels(
channel = Channel(
id = "c1111",
name = "Child 1-1-1-1",
parentChannelId = "c111"
)
),
Channels(channel = Channel(id = "pc2", name = "P Channel 2")),
Channels(channel = Channel(id = "pc3", name = "P Channel 3")),
Channels(channel = Channel(id = "c31", name = "Child 3-1", parentChannelId = "pc3"))
)
Treeview :
treeview<Channels> {
isShowRoot = false
root = TreeItem()
cellFormat { text = it.channel?.name }
populate { parent ->
if (parent == root) channels.filter {
it.channel?.parentChannelId == null
} else channels.filter {
it.channel?.parentChannelId == parent.value?.channel?.id
}
}
}
Now when I modify the channels list, treeview doesn't gets updated.
I've been stuck on this since 3-4 days.
Please help.

Swagger Annotations don't show a body example

When working with Swagger Annotations it is not possible to create an example for the request body.
Here comes the annotation stuff for the RESTful resource/endpoint:
#POST
#Path("/{carId}/conversation")
#ApiImplicitParams({
#ApiImplicitParam(name = "Authorization", value = "The AppJWT token", paramType = "header", required = true),
#ApiImplicitParam(name = "ON-BEHALF", value = "The ConsumerJWS token", paramType = "header", required = true),
#ApiImplicitParam(name = "v", value = "API version", defaultValue = "3", paramType = "query", required = true)
})
#ManagedAsync
#ApiOperation(value = "bla", notes = "")
#ApiResponses(value = {
#ApiResponse(code = 200, message = "bla", response = CreateBlaResponse.class, responseContainer = "List"),
#ApiResponse(code = 400, message = "The input was invalid, please check.", response = GenericError.class),
#ApiResponse(code = 401, message = "Unauthorized. Are the headers correct?"),
#ApiResponse(code = 429, message = "Too many requests, please try again later", response = CreateConversationResBody.class)
})
public void createConversationBatchPOST(#ApiParam(value = "Car ID the action should apply to", required = true) #PathParam("carId") String carId,
#ApiParam(name = "body", value = "The Json payload", required = true, examples = #Example(value = {#ExampleProperty(value = "{\"name\" : \"James\"}", mediaType = "application/json")}))
#RequestBody String body,
#Suspended final AsyncResponse asyncResponse) throws IOException {
//.... implementation
}
Do you have an idea why the annotation in the method signature
#ApiParam(name = "body", value = "The Json payload",
required = true, examples = #Example(value = {#ExampleProperty(value = "{\"name\" : \"James\"}", mediaType = "application/json")}))
#RequestBody String body
doesn't lead to the Json example?

Error when implementing a custom layer in keras for R

I am trying to implement a custom layer for the package keras in R (github).
The layer I am implementing is based on this AttentionWithContext layer available here: gist
Here is my code:
AttentionWithContext <- R6::R6Class("AttentionWithContext",
inherit = KerasLayer,
public = list(
W_regularizer = NULL,
b_regularizer = NULL,
u_regularizer = NULL,
W_constraint=NULL,
b_constraint=NULL,
u_constraint=NULL,
bias=NULL,
b=NULL,
W=NULL,
u=NULL,
supports_masking=NULL,
init=NULL,
name = NULL,
initialize = function(name = 'attention',
W_regularizer = NULL,
b_regularizer = NULL,
u_regularizer = NULL,
W_constraint=NULL,
b_constraint=NULL,
u_constraint=NULL,
bias=TRUE ) {
self$supports_masking = TRUE
self$init = keras::initializer_glorot_uniform()
self$W_regularizer = W_regularizer
self$b_regularizer = b_regularizer
self$u_regularizer = u_regularizer
self$W_constraint = W_constraint
self$b_constraint = b_constraint
self$u_constraint = u_constraint
self$bias = bias
self$name = name
},
build = function(input_shape) {
assertthat::assert_that(length(input_shape) == 3)
self$W = self$add_weight(shape = reticulate::tuple(input_shape[[3]],input_shape[[3]], NULL),
initializer = self$init,
name=stringr::str_interp('${self$name}_W'),
regularizer = self$W_regularizer,
constraint = self$W_constraint)
if (self$bias) {
self$b = self$add_weight(shape = reticulate::tuple(input_shape[[3]]),
initializer='zero',
name = stringr::str_interp('${self$name}_b'),
regularizer = self$b_regularizer,
constraint = self$b_constraint)
}
self$u = self$add_weight(shape = reticulate::tuple(input_shape[[3]]),
initializer=self$init,
name = stringr::str_interp('${self$name}_u'),
regularizer = self$u_regularizer,
constraint = self$u_constraint)
},
compute_mask = function(input, input_mask=NULL) {
return(NULL)
},
call = function(x, mask = NULL) {
uit = keras::k_squeeze(keras::k_dot(x, keras::k_expand_dims(self$W)), axis=-1)
if (self$bias) {
uit = uit + self$b
}
uit = keras::k_tanh(uit)
ait = keras::k_dot(uit, self$u)
a = keras::k_exp(ait)
if (!is.null(mask)) {
a = a * keras::k_cast(mask, keras::k_floatx())
}
a = a/keras::k_cast(keras::k_sum(a, axis = 1, keepdims = TRUE) + keras::k_epsilon(), keras::k_floatx())
weighted_input = x * keras::k_expand_dims(a)
keras::k_sum(weighted_input, axis=1)
},
compute_output_shape = function(input_shape) {
list(input_shape[[1]], input_shape[[3]])
}
)
)
# define layer wrapper function
layer_attention_with_context <- function(object, W_regularizer = NULL,
b_regularizer = NULL,
u_regularizer = NULL,
W_constraint=NULL,
b_constraint=NULL,
u_constraint=NULL,
bias=TRUE,
name = 'attention_with_context') {
create_layer(AttentionWithContext, object, list(W_regularizer = W_regularizer,
b_regularizer = b_regularizer,
u_regularizer = u_regularizer,
W_constraint= W_constraint,
b_constraint=b_constraint,
u_constraint=u_constraint,
bias=bias,
name = name
))
}
# Example
model <- keras_model_sequential()
model %>%
layer_embedding(input_dim = 20000,
output_dim = 128,
input_length = 30) %>%
layer_lstm(64, return_sequences = TRUE) %>%
layer_attention_with_context() %>%
time_distributed(layer_dense(units=10))
When I run this, I get a cryptic error message:
Error in py_call_impl(callable, dots$args, dots$keywords) :
RuntimeError: Evaluation error: TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'.
I tried to explore this error and I think it might come from this line :
reticulate::tuple(input_shape[[3]],input_shape[[3]], NULL)
In the original code, in python, we can see this:
(input_shape[-1], input_shape[-1],)
I could not find a way to create this structure in R.
Any ideas ?

How to prevent duplicate validation while updating the value without any changes?

#RequestMapping(value = "/updateYearMaster", method = RequestMethod.POST)
public String updateYearmaster(#RequestParam(value = "id", required = false) Long id,
#RequestParam(value = "fromyear", required = false) Date fromyear,
#RequestParam(value = "toyear", required = false) Date toyear,
#RequestParam(value = "status", required = false) String status,
#RequestParam(value = "yeardescription", required = false) String yeardescription, Model model) {
Yearmaster yearmaster = new Yearmaster(fromyear, toyear, status, yeardescription);
yearmaster.setId(id);
List val = yearmasterService.duplicateEditYear(fromyear, toyear, id);
if (!val.isEmpty()) {
model.addAttribute("yearmaster", yearmaster);
errorMessage = "fromyear and toyear combination is already exist";
model.addAttribute("errorMessage", errorMessage);
return "edit-year-master";
} else {
yearmasterService.save(yearmaster);
return "redirect:/yearmaster";
}
}

Resources