Taking the petstore example,
I am trying to dereference the $Ref in the /pet -> put operation which is currently: schema $ref: #definitions/Pet
I am trying to resolve this but unable to get this text out from the json file. This is what I have:
BodyParameter bp = (BodyParameter) param; System.out.println(((RefModel) bp.getSchema()).get$ref());
I thought this would give me the above text out which I could later map with a definition Map and resolve it but got the following error:
Exception in thread "main" java.lang.ClassCastException: io.swagger.models.ModelImpl cannot be cast to io.swagger.models.RefModel
Would anyone know of a way to extract this string out from a body parameter and in general since the schema returns a Type Model? I do not find a proper documentation source for the swagger parser , swagger inflector projects so hunting around through the source code itself.
you would do the following:
Model model = bp.getSchema();
if(model instanceof RefModel) {
RefModel ref = (RefModel) model;
String simpleRef = ref.getSimpleRef();
Model concreteModel = swagger.getDefinitions().get(simpleRef);
}
You should confirm that concreteModel
is a ModelImpl
but in the petstore case, it will be.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.