/** * Translates a Restlet Web API Definition to a Swagger definition * * @param definition * The Restlet Web API definition * @return Swagger The translated Swagger 2.0 definition */ public static Swagger getSwagger(Definition definition) { // conversion Swagger swagger = new Swagger(); swagger.setSwagger(SWAGGER_VERSION); // required // fill Swagger main attributes fillSwaggerMainAttributes(definition, swagger); // fill authentication information fillSwaggerAuthentication(definition, swagger); // fill Swagger.info fillSwaggerInfo(definition, swagger); // required // fill Swagger.tags fillTags(definition.getContract(), swagger); // required // fill Swagger.paths fillPaths(definition, swagger); // required // fill Swagger.definitions fillDefinitions(definition, swagger); // TODO add authorization attribute return swagger; }
/** * Fill Swagger "Paths" objects from RWADef definition * * @param definition * RWADef definition * @param swagger * Swagger definition */ private static void fillPaths(Definition definition, Swagger swagger) { Map<String, Path> paths = new LinkedHashMap<>(); for (Resource resource : definition.getContract().getResources()) { Path pathSwagger = new Path(); fillPathOperations(definition, resource, pathSwagger); paths.put(resource.getResourcePath(), pathSwagger); } swagger.setPaths(paths); }
fillOperationParameters(definition, resource, operation, operationSwagger); fillOperationResponses(definition, operation, operationSwagger);
if (Types.isCompositeType(property.getType())) { String compositePropertyType = name + StringUtils.firstUpper(property.getName()); itemProperty = newPropertyForType(compositePropertyType); fillModel( compositePropertyType, null, property.getProperties(), swagger, ms); } else { itemProperty = newPropertyForType(property.getType()); if (Types.isCompositeType(property.getType())) { String compositePropertyType = name + StringUtils.firstUpper(property.getName()); propertySwagger = newPropertyForType(compositePropertyType); fillModel( compositePropertyType, null, property.getProperties(), swagger, ms); propertySwagger.setExample(example); } else { propertySwagger = newPropertyForType(property.getType()); propertySwagger.setExample(example);
/** * Fill Swagger "Definitions" objects from RWADef definition * * @param definition * RWADef definition * @param swagger * Swagger definition */ private static void fillDefinitions(Definition definition, Swagger swagger) { for (Representation representation : definition.getContract() .getRepresentations()) { if (representation.isRaw() || Types.isPrimitiveType(representation.getName())) { continue; } if (StringUtils.isNullOrEmpty(representation.getName())) { LOGGER.warning("A representation should have an identifier:" + representation.getName()); continue; } /* Representation -> Model */ ModelImpl modelSwagger = new ModelImpl(); fillModel(representation.getName(), representation.getDescription(), representation.getProperties(), swagger, modelSwagger); } }
fillOperationParameters(definition, resource, operation, operationSwagger); fillOperationResponses(definition, operation, operationSwagger);
if (Types.isCompositeType(property.getType())) { String compositePropertyType = name + StringUtils.firstUpper(property.getName()); itemProperty = newPropertyForType(compositePropertyType); fillModel( compositePropertyType, null, property.getProperties(), swagger, ms); } else { itemProperty = newPropertyForType(property.getType()); if (Types.isCompositeType(property.getType())) { String compositePropertyType = name + StringUtils.firstUpper(property.getName()); propertySwagger = newPropertyForType(compositePropertyType); fillModel( compositePropertyType, null, property.getProperties(), swagger, ms); propertySwagger.setExample(example); } else { propertySwagger = newPropertyForType(property.getType()); propertySwagger.setExample(example);
/** * Fill Swagger "Definitions" objects from RWADef definition * * @param definition * RWADef definition * @param swagger * Swagger definition */ private static void fillDefinitions(Definition definition, Swagger swagger) { for (Representation representation : definition.getContract() .getRepresentations()) { if (representation.isRaw() || Types.isPrimitiveType(representation.getName())) { continue; } if (StringUtils.isNullOrEmpty(representation.getName())) { LOGGER.warning("A representation should have an identifier:" + representation.getName()); continue; } /* Representation -> Model */ ModelImpl modelSwagger = new ModelImpl(); fillModel(representation.getName(), representation.getDescription(), representation.getProperties(), swagger, modelSwagger); } }
/** * Translates a Restlet Web API Definition to a Swagger definition * * @param definition * The Restlet Web API definition * @return Swagger The translated Swagger 2.0 definition */ public static Swagger getSwagger(Definition definition) { // conversion Swagger swagger = new Swagger(); swagger.setSwagger(SWAGGER_VERSION); // required // fill Swagger main attributes fillSwaggerMainAttributes(definition, swagger); // fill authentication information fillSwaggerAuthentication(definition, swagger); // fill Swagger.info fillSwaggerInfo(definition, swagger); // required // fill Swagger.tags fillTags(definition.getContract(), swagger); // required // fill Swagger.paths fillPaths(definition, swagger); // required // fill Swagger.definitions fillDefinitions(definition, swagger); // TODO add authorization attribute return swagger; }
fillOperationParameters(definition, resource, operation, operationSwagger); fillOperationResponses(definition, operation, operationSwagger);
if (Types.isCompositeType(property.getType())) { String compositePropertyType = name + StringUtils.firstUpper(property.getName()); itemProperty = newPropertyForType(compositePropertyType); fillModel( compositePropertyType, null, property.getProperties(), swagger, ms); } else { itemProperty = newPropertyForType(property.getType()); if (Types.isCompositeType(property.getType())) { String compositePropertyType = name + StringUtils.firstUpper(property.getName()); propertySwagger = newPropertyForType(compositePropertyType); fillModel( compositePropertyType, null, property.getProperties(), swagger, ms); propertySwagger.setExample(example); } else { propertySwagger = newPropertyForType(property.getType()); propertySwagger.setExample(example);
/** * Fill Swagger "Paths" objects from RWADef definition * * @param definition * RWADef definition * @param swagger * Swagger definition */ private static void fillPaths(Definition definition, Swagger swagger) { Map<String, Path> paths = new LinkedHashMap<>(); for (Resource resource : definition.getContract().getResources()) { Path pathSwagger = new Path(); fillPathOperations(definition, resource, pathSwagger); paths.put(resource.getResourcePath(), pathSwagger); } swagger.setPaths(paths); }
/** * Fill Swagger "Definitions" objects from RWADef definition * * @param definition * RWADef definition * @param swagger * Swagger definition */ private static void fillDefinitions(Definition definition, Swagger swagger) { for (Representation representation : definition.getContract() .getRepresentations()) { if (representation.isRaw() || Types.isPrimitiveType(representation.getName())) { continue; } if (StringUtils.isNullOrEmpty(representation.getName())) { LOGGER.warning("A representation should have an identifier:" + representation.getName()); continue; } /* Representation -> Model */ ModelImpl modelSwagger = new ModelImpl(); fillModel(representation.getName(), representation.getDescription(), representation.getProperties(), swagger, modelSwagger); } }
/** * Translates a Restlet Web API Definition to a Swagger definition * * @param definition * The Restlet Web API definition * @return Swagger The translated Swagger 2.0 definition */ public static Swagger getSwagger(Definition definition) { // conversion Swagger swagger = new Swagger(); swagger.setSwagger(SWAGGER_VERSION); // required // fill Swagger main attributes fillSwaggerMainAttributes(definition, swagger); // fill authentication information fillSwaggerAuthentication(definition, swagger); // fill Swagger.info fillSwaggerInfo(definition, swagger); // required // fill Swagger.tags fillTags(definition.getContract(), swagger); // required // fill Swagger.paths fillPaths(definition, swagger); // required // fill Swagger.definitions fillDefinitions(definition, swagger); // TODO add authorization attribute return swagger; }
fillOperationParameters(definition, resource, operation, operationSwagger); fillOperationResponses(definition, operation, operationSwagger);
if (Types.isCompositeType(property.getType())) { String compositePropertyType = name + StringUtils.firstUpper(property.getName()); itemProperty = newPropertyForType(compositePropertyType); fillModel( compositePropertyType, null, property.getProperties(), swagger, ms); } else { itemProperty = newPropertyForType(property.getType()); if (Types.isCompositeType(property.getType())) { String compositePropertyType = name + StringUtils.firstUpper(property.getName()); propertySwagger = newPropertyForType(compositePropertyType); fillModel( compositePropertyType, null, property.getProperties(), swagger, ms); propertySwagger.setExample(example); } else { propertySwagger = newPropertyForType(property.getType()); propertySwagger.setExample(example);
/** * Fill Swagger "Paths" objects from RWADef definition * * @param definition * RWADef definition * @param swagger * Swagger definition */ private static void fillPaths(Definition definition, Swagger swagger) { Map<String, Path> paths = new LinkedHashMap<>(); for (Resource resource : definition.getContract().getResources()) { Path pathSwagger = new Path(); fillPathOperations(definition, resource, pathSwagger); paths.put(resource.getResourcePath(), pathSwagger); } swagger.setPaths(paths); }
/** * Fill Swagger "Definitions" objects from RWADef definition * * @param definition * RWADef definition * @param swagger * Swagger definition */ private static void fillDefinitions(Definition definition, Swagger swagger) { for (Representation representation : definition.getContract() .getRepresentations()) { if (representation.isRaw() || Types.isPrimitiveType(representation.getName())) { continue; } if (StringUtils.isNullOrEmpty(representation.getName())) { LOGGER.warning("A representation should have an identifier:" + representation.getName()); continue; } /* Representation -> Model */ ModelImpl modelSwagger = new ModelImpl(); fillModel(representation.getName(), representation.getDescription(), representation.getProperties(), swagger, modelSwagger); } }
/** * Translates a Restlet Web API Definition to a Swagger definition * * @param definition * The Restlet Web API definition * @return Swagger The translated Swagger 2.0 definition */ public static Swagger getSwagger(Definition definition) { // conversion Swagger swagger = new Swagger(); swagger.setSwagger(SWAGGER_VERSION); // required // fill Swagger main attributes fillSwaggerMainAttributes(definition, swagger); // fill authentication information fillSwaggerAuthentication(definition, swagger); // fill Swagger.info fillSwaggerInfo(definition, swagger); // required // fill Swagger.tags fillTags(definition.getContract(), swagger); // required // fill Swagger.paths fillPaths(definition, swagger); // required // fill Swagger.definitions fillDefinitions(definition, swagger); // TODO add authorization attribute return swagger; }
/** * Fill Swagger "Paths" objects from RWADef definition * * @param definition * RWADef definition * @param swagger * Swagger definition */ private static void fillPaths(Definition definition, Swagger swagger) { Map<String, Path> paths = new LinkedHashMap<>(); for (Resource resource : definition.getContract().getResources()) { Path pathSwagger = new Path(); fillPathOperations(definition, resource, pathSwagger); paths.put(resource.getResourcePath(), pathSwagger); } swagger.setPaths(paths); }