/** * Indicates if the given resource listing and list of API declarations * match. * * @param resourceListing * The Swagger resource listing. * @param apiDeclarations * The list of Swagger API declarations. * @throws org.restlet.ext.platform.internal.conversion.TranslationException */ private static void validate(ResourceListing resourceListing, Map<String, ApiDeclaration> apiDeclarations) throws TranslationException { int rlSize = resourceListing.getApis().size(); int adSize = apiDeclarations.size(); if (rlSize < adSize) { throw new TranslationException("file", "Some API declarations are not mapped in your resource listing"); } else if (rlSize > adSize) { throw new TranslationException("file", "Some API declarations are missing"); } } }
throw new TranslationException("url", "You did not provide any URL"); if (ImportUtils.isRemoteUrl(swaggerUrl)) { swagger = ImportUtils.getAndDeserialize(swaggerUrl, userName, password, Swagger.class); } else { File swaggerFile = new File(swaggerUrl); swagger = Json.mapper().readValue(swaggerFile, Swagger.class); } catch (Exception e) { throw new TranslationException("file", e.getMessage()); return Swagger2Reader.translate(swagger);
throw new TranslationException("url", "You did not provide any URL"); if (ImportUtils.isRemoteUrl(swaggerUrl)) { LOGGER.log(Level.FINE, "Reading file: " + swaggerUrl); resourceListing = ImportUtils.getAndDeserialize(swaggerUrl, userName, password, ResourceListing.class); for (ResourceListingApi api : resourceListing.getApis()) { LOGGER.log(Level.FINE, "Reading file: " + swaggerUrl + api.getPath()); apis.put( api.getPath(), ImportUtils.getAndDeserialize(swaggerUrl + api.getPath(), userName, password, ApiDeclaration.class)); String basePath = resourceListingFile.getParent(); LOGGER.log(Level.FINE, "Base path: " + basePath); for (ResourceListingApi api : resourceListing.getApis()) { LOGGER.log(Level.FINE, "Reading file " + basePath + api.getPath()); apis.put(api.getPath(), om.readValue(new File(basePath + api.getPath()), ApiDeclaration.class)); throw new TranslationException("file", e.getMessage()); return SwaggerReader.translate(resourceListing, apis);
Definition definition = new Definition(); definition.setContract(new Contract()); Endpoint endpoint = new Endpoint(apiDeclaration.getBasePath()); definition.getEndpoints().add(endpoint); fillEndpointAuthorization(apiDeclaration.getAuthorizations(), endpoint); fillContract(contract, apiDeclaration, new ArrayList<String>(), null, null); return definition; } catch (Exception e) { throw new TranslationException( "compliance", "Impossible to read your API definition, check your Swagger specs compliance",
ClientResource cr = createAuthenticatedClientResource(url, userName, password); representation = cr.get(); throw new TranslationException("file", "Could not deserialize object at " + url + " as " + clazz.getName(), e);
private static void fillRwadefResponses(Operation swaggerOperation, org.restlet.ext.platform.internal.model.Operation operation, Contract contract, Map<String, Object> parameters) { if (swaggerOperation == null) { return; } if (swaggerOperation.getResponses() != null) { for (String key : swaggerOperation.getResponses().keySet()) { Response swaggerResponse = swaggerOperation.getResponses().get(key); org.restlet.ext.platform.internal.model.Response response = new org.restlet.ext.platform.internal.model.Response(); int statusCode; try { statusCode = Integer.parseInt(key); response.setCode(statusCode); } catch (Exception e) { // TODO: what to do with "Default" responses ? LOGGER.warning("Response " + key + " for operation " + swaggerOperation.getOperationId() + " could not be retrieved because its key is not a valid status code."); continue; } response.setDescription(swaggerResponse.getDescription()); response.setName(ConversionUtils.generateResponseName(statusCode)); fillOutputPayload(swaggerResponse, response, swaggerOperation, contract, parameters); operation.getResponses().add(response); } } }
throw new TranslationException("url", "You did not provide any URL"); if (ImportUtils.isRemoteUrl(swaggerUrl)) { LOGGER.log(Level.FINE, "Reading file: " + swaggerUrl); resourceListing = ImportUtils.getAndDeserialize(swaggerUrl, userName, password, ResourceListing.class); for (ResourceListingApi api : resourceListing.getApis()) { LOGGER.log(Level.FINE, "Reading file: " + swaggerUrl + api.getPath()); apis.put( api.getPath(), ImportUtils.getAndDeserialize(swaggerUrl + api.getPath(), userName, password, ApiDeclaration.class)); String basePath = resourceListingFile.getParent(); LOGGER.log(Level.FINE, "Base path: " + basePath); for (ResourceListingApi api : resourceListing.getApis()) { LOGGER.log(Level.FINE, "Reading file " + basePath + api.getPath()); apis.put(api.getPath(), om.readValue(new File(basePath + api.getPath()), ApiDeclaration.class)); throw new TranslationException("file", e.getMessage()); return SwaggerReader.translate(resourceListing, apis);
throw new TranslationException("url", "You did not provide any URL"); if (ImportUtils.isRemoteUrl(swaggerUrl)) { swagger = ImportUtils.getAndDeserialize(swaggerUrl, userName, password, Swagger.class); } else { File swaggerFile = new File(swaggerUrl); swagger = Json.mapper().readValue(swaggerFile, Swagger.class); } catch (Exception e) { throw new TranslationException("file", e.getMessage()); return Swagger2Reader.translate(swagger);
ClientResource cr = createAuthenticatedClientResource(url, userName, password); representation = cr.get(); throw new TranslationException("file", "Could not deserialize object at " + url + " as " + clazz.getName(), e);
/** * Indicates if the given resource listing and list of API declarations * match. * * @param resourceListing * The Swagger resource listing. * @param apiDeclarations * The list of Swagger API declarations. * @throws org.restlet.ext.platform.internal.conversion.TranslationException */ private static void validate(ResourceListing resourceListing, Map<String, ApiDeclaration> apiDeclarations) throws TranslationException { int rlSize = resourceListing.getApis().size(); int adSize = apiDeclarations.size(); if (rlSize < adSize) { throw new TranslationException("file", "Some API declarations are not mapped in your resource listing"); } else if (rlSize > adSize) { throw new TranslationException("file", "Some API declarations are missing"); } } }
private static void fillRwadefResponses(Operation swaggerOperation, org.restlet.ext.platform.internal.model.Operation operation, Contract contract, Map<String, Object> parameters) { if (swaggerOperation == null) { return; } if (swaggerOperation.getResponses() != null) { for (String key : swaggerOperation.getResponses().keySet()) { Response swaggerResponse = swaggerOperation.getResponses().get(key); org.restlet.ext.platform.internal.model.Response response = new org.restlet.ext.platform.internal.model.Response(); int statusCode; try { statusCode = Integer.parseInt(key); response.setCode(statusCode); } catch (Exception e) { // TODO: what to do with "Default" responses ? LOGGER.warning("Response " + key + " for operation " + swaggerOperation.getOperationId() + " could not be retrieved because its key is not a valid status code."); continue; } response.setDescription(swaggerResponse.getDescription()); response.setName(ConversionUtils.generateResponseName(statusCode)); fillOutputPayload(swaggerResponse, response, swaggerOperation, contract, parameters); operation.getResponses().add(response); } } }
throw new TranslationException("url", "You did not provide any URL"); if (ImportUtils.isRemoteUrl(swaggerUrl)) { LOGGER.log(Level.FINE, "Reading file: " + swaggerUrl); resourceListing = ImportUtils.getAndDeserialize(swaggerUrl, userName, password, ResourceListing.class); for (ResourceListingApi api : resourceListing.getApis()) { LOGGER.log(Level.FINE, "Reading file: " + swaggerUrl + api.getPath()); apis.put( api.getPath(), ImportUtils.getAndDeserialize(swaggerUrl + api.getPath(), userName, password, ApiDeclaration.class)); String basePath = resourceListingFile.getParent(); LOGGER.log(Level.FINE, "Base path: " + basePath); for (ResourceListingApi api : resourceListing.getApis()) { LOGGER.log(Level.FINE, "Reading file " + basePath + api.getPath()); apis.put(api.getPath(), om.readValue(new File(basePath + api.getPath()), ApiDeclaration.class)); throw new TranslationException("file", e.getMessage()); return SwaggerReader.translate(resourceListing, apis);
throw new TranslationException("url", "You did not provide any URL"); if (ImportUtils.isRemoteUrl(swaggerUrl)) { swagger = ImportUtils.getAndDeserialize(swaggerUrl, userName, password, Swagger.class); } else { File swaggerFile = new File(swaggerUrl); swagger = Json.mapper().readValue(swaggerFile, Swagger.class); } catch (Exception e) { throw new TranslationException("file", e.getMessage()); return Swagger2Reader.translate(swagger);
ClientResource cr = createAuthenticatedClientResource(url, userName, password); representation = cr.get(); throw new TranslationException("file", "Could not deserialize object at " + url + " as " + clazz.getName(), e);
/** * Indicates if the given resource listing and list of API declarations * match. * * @param resourceListing * The Swagger resource listing. * @param apiDeclarations * The list of Swagger API declarations. * @throws org.restlet.ext.platform.internal.conversion.TranslationException */ private static void validate(ResourceListing resourceListing, Map<String, ApiDeclaration> apiDeclarations) throws TranslationException { int rlSize = resourceListing.getApis().size(); int adSize = apiDeclarations.size(); if (rlSize < adSize) { throw new TranslationException("file", "Some API declarations are not mapped in your resource listing"); } else if (rlSize > adSize) { throw new TranslationException("file", "Some API declarations are missing"); } } }
private static void fillRwadefResponses(Operation swaggerOperation, org.restlet.ext.platform.internal.model.Operation operation, Contract contract, Map<String, Object> parameters) { if (swaggerOperation == null) { return; } if (swaggerOperation.getResponses() != null) { for (String key : swaggerOperation.getResponses().keySet()) { Response swaggerResponse = swaggerOperation.getResponses().get(key); org.restlet.ext.platform.internal.model.Response response = new org.restlet.ext.platform.internal.model.Response(); int statusCode; try { statusCode = Integer.parseInt(key); response.setCode(statusCode); } catch (Exception e) { // TODO: what to do with "Default" responses ? LOGGER.warning("Response " + key + " for operation " + swaggerOperation.getOperationId() + " could not be retrieved because its key is not a valid status code."); continue; } response.setDescription(swaggerResponse.getDescription()); response.setName(ConversionUtils.generateResponseName(statusCode)); fillOutputPayload(swaggerResponse, response, swaggerOperation, contract, parameters); operation.getResponses().add(response); } } }
throw new TranslationException("url", "You did not provide any URL"); if (ImportUtils.isRemoteUrl(swaggerUrl)) { LOGGER.log(Level.FINE, "Reading file: " + swaggerUrl); resourceListing = ImportUtils.getAndDeserialize(swaggerUrl, userName, password, ResourceListing.class); for (ResourceListingApi api : resourceListing.getApis()) { LOGGER.log(Level.FINE, "Reading file: " + swaggerUrl + api.getPath()); apis.put( api.getPath(), ImportUtils.getAndDeserialize(swaggerUrl + api.getPath(), userName, password, ApiDeclaration.class)); String basePath = resourceListingFile.getParent(); LOGGER.log(Level.FINE, "Base path: " + basePath); for (ResourceListingApi api : resourceListing.getApis()) { LOGGER.log(Level.FINE, "Reading file " + basePath + api.getPath()); apis.put(api.getPath(), om.readValue(new File(basePath + api.getPath()), ApiDeclaration.class)); throw new TranslationException("file", e.getMessage()); return SwaggerReader.translate(resourceListing, apis);
throw new TranslationException("url", "You did not provide any URL"); if (ImportUtils.isRemoteUrl(swaggerUrl)) { swagger = ImportUtils.getAndDeserialize(swaggerUrl, userName, password, Swagger.class); } else { File swaggerFile = new File(swaggerUrl); swagger = Json.mapper().readValue(swaggerFile, Swagger.class); } catch (Exception e) { throw new TranslationException("file", e.getMessage()); return Swagger2Reader.translate(swagger);
ClientResource cr = createAuthenticatedClientResource(url, userName, password); representation = cr.get(); throw new TranslationException("file", "Could not deserialize object at " + url + " as " + clazz.getName(), e);
/** * Indicates if the given resource listing and list of API declarations * match. * * @param resourceListing * The Swagger resource listing. * @param apiDeclarations * The list of Swagger API declarations. * @throws org.restlet.ext.platform.internal.conversion.TranslationException */ private static void validate(ResourceListing resourceListing, Map<String, ApiDeclaration> apiDeclarations) throws TranslationException { int rlSize = resourceListing.getApis().size(); int adSize = apiDeclarations.size(); if (rlSize < adSize) { throw new TranslationException("file", "Some API declarations are not mapped in your resource listing"); } else if (rlSize > adSize) { throw new TranslationException("file", "Some API declarations are missing"); } } }