@Test public void testAnnotation() throws TranslatorException{ SwaggerExecutionFactory translator = new SwaggerExecutionFactory(); translator.start(); MetadataFactory mf = swaggerMetadata(translator); for(Procedure p : mf.getSchema().getProcedures().values()){ if(p.getName().equals("addCustomer")){ assertEquals("Add a Customer", p.getAnnotation()); } else if (p.getName().equals("getByNumCityCountry")){ assertEquals("get customer by Number, City, Country as return xml/json", p.getAnnotation()); } } }
protected Swagger getSchema(WSConnection conn) throws TranslatorException { Swagger swagger = null; try { String swaggerFile = getSwaggerFilePath(); if( swaggerFile != null && !swaggerFile.isEmpty()) { File f = new File(swaggerFile); if(!f.exists() || !f.isFile()) { throw new TranslatorException(SwaggerPlugin.Event.TEIID28019, SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28019, swaggerFile)); } SwaggerParser parser = new SwaggerParser(); swagger = parser.read(f.getAbsolutePath(), null, true); } else { BaseQueryExecution execution = new BaseQueryExecution(this.ef, null, null, conn); Map<String, List<String>> headers = new HashMap<String, List<String>>(); BinaryWSProcedureExecution call = execution.buildInvokeHTTP("GET", "swagger.json", null, headers); call.execute(); if (call.getResponseCode() != 200) { throw new TranslatorException(SwaggerPlugin.Event.TEIID28015, SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28015,call.getResponseCode())); } Blob out = (Blob)call.getOutputParameterValues().get(0); ObjectMapper objectMapper = new ObjectMapper(); JsonNode rootNode = objectMapper.readTree(out.getBinaryStream()); swagger = new SwaggerParser().read(rootNode, true); } } catch (Exception e) { throw new TranslatorException(SwaggerPlugin.Event.TEIID28016, e, SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28016, e)); } return swagger; }
SwaggerMetadataProcessor implements MetadataProcessor<WSConnection> { protected Swagger getSchema(WSConnection conn) throws TranslatorException { Swagger swagger = null; try { String swaggerFile = getSwaggerFilePath(); if( swaggerFile != null && !swaggerFile.isEmpty()) { File f = new File(swaggerFile); if(!f.exists() || !f.isFile()) { throw new TranslatorException(SwaggerPlugin.Event.TEIID28019, SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28019, swaggerFile)); } SwaggerParser parser = new SwaggerParser(); swagger = parser.read(f.getAbsolutePath(), null, true); } else { BaseQueryExecution execution = new BaseQueryExecution(this.ef, null, null, conn); Map<String, List<String>> headers = new HashMap<String, List<String>>(); BinaryWSProcedureExecution call = execution.buildInvokeHTTP("GET", "swagger.json", null, headers); call.execute(); if (call.getResponseCode() != 200) { throw new TranslatorException(SwaggerPlugin.Event.TEIID28015, SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28015,call.getResponseCode())); } Blob out = (Blob)call.getOutputParameterValues().get(0); ObjectMapper objectMapper = new ObjectMapper(); JsonNode rootNode = objectMapper.readTree(out.getBinaryStream()); swagger = new SwaggerParser().read(rootNode, true); } } catch (Exception e) { throw new TranslatorException(SwaggerPlugin.Event.TEIID28016, e, SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28016, e)); } return swagger; } }
SwaggerMetadataProcessor implements MetadataProcessor<WSConnection> { protected Swagger getSchema(WSConnection conn) throws TranslatorException { Swagger swagger = null; try { String swaggerFile = getSwaggerFilePath(); if( swaggerFile != null && !swaggerFile.isEmpty()) { File f = new File(swaggerFile); if(!f.exists() || !f.isFile()) { throw new TranslatorException(SwaggerPlugin.Event.TEIID28019, SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28019, swaggerFile)); } SwaggerParser parser = new SwaggerParser(); swagger = parser.read(f.getAbsolutePath(), null, true); } else { BaseQueryExecution execution = new BaseQueryExecution(this.ef, null, null, conn); Map<String, List<String>> headers = new HashMap<String, List<String>>(); BinaryWSProcedureExecution call = execution.buildInvokeHTTP("GET", "swagger.json", null, headers); call.execute(); if (call.getResponseCode() != 200) { throw new TranslatorException(SwaggerPlugin.Event.TEIID28015, SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28015,call.getResponseCode())); } Blob out = (Blob)call.getOutputParameterValues().get(0); ObjectMapper objectMapper = new ObjectMapper(); JsonNode rootNode = objectMapper.readTree(out.getBinaryStream()); swagger = new SwaggerParser().read(rootNode, true); } } catch (Exception e) { throw new TranslatorException(SwaggerPlugin.Event.TEIID28016, e, SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28016, e)); } return swagger; } SwaggerMetadataProcessor(SwaggerExecutionFactory ef); }
SwaggerMetadataProcessor implements MetadataProcessor<WSConnection> { protected Swagger getSchema(WSConnection conn) throws TranslatorException { Swagger swagger = null; try { String swaggerFile = getSwaggerFilePath(); if( swaggerFile != null && !swaggerFile.isEmpty()) { File f = new File(swaggerFile); if(!f.exists() || !f.isFile()) { throw new TranslatorException(SwaggerPlugin.Event.TEIID28019, SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28019, swaggerFile)); } SwaggerParser parser = new SwaggerParser(); swagger = parser.read(f.getAbsolutePath(), null, true); } else { BaseQueryExecution execution = new BaseQueryExecution(this.ef, null, null, conn); Map<String, List<String>> headers = new HashMap<String, List<String>>(); BinaryWSProcedureExecution call = execution.buildInvokeHTTP("GET", "swagger.json", null, headers); call.execute(); if (call.getResponseCode() != 200) { throw new TranslatorException(SwaggerPlugin.Event.TEIID28015, SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28015,call.getResponseCode())); } Blob out = (Blob)call.getOutputParameterValues().get(0); ObjectMapper objectMapper = new ObjectMapper(); JsonNode rootNode = objectMapper.readTree(out.getBinaryStream()); swagger = new SwaggerParser().read(rootNode, true); } } catch (Exception e) { throw new TranslatorException(SwaggerPlugin.Event.TEIID28016, e, SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28016, e)); } return swagger; } SwaggerMetadataProcessor(SwaggerExecutionFactory ef); @TranslatorProperty(display="Swagger metadata file path", category=PropertyType.IMPORT, description="Swagger metadata file path.") String getSwaggerFilePath(); void setSwaggerFilePath(String swaggerFilePath); @TranslatorProperty(display="Use Host from Swagger File", category=PropertyType.IMPORT, description="Use default host specified in the Swagger file; Defaults to true") boolean isUseDefaultHost(); void setUseDefaultHost(boolean useDefault); @TranslatorProperty(display="Preferred Scheme", category=PropertyType.IMPORT, description="Preferred Scheme to use when Swagger file supports multiple invocation schemes like http, https etc.") String getPreferredScheme(); void setPreferredScheme(String scheme); @TranslatorProperty(display="Preferred Accept Header", category=PropertyType.IMPORT, description="Preferred Accept MIME type header, this should be one of the Swagger " + "'produces' types; default is application/json") String getPreferredProduces(); void setPreferredProduces(String accept); @TranslatorProperty(display="Preferred Content-type Header", category=PropertyType.IMPORT, description="Preferred Content-type header, this should be one of the Swagger 'consume' " + "types, default is application/json") String getPreferredConsumes(); void setPreferredConsumes(String type); @Override void process(MetadataFactory mf, WSConnection connection); static Map<HttpMethod, Operation> getOperationMap(Path operations); }
SwaggerMetadataProcessor implements MetadataProcessor<WSConnection> { protected Swagger getSchema(WSConnection conn) throws TranslatorException { Swagger swagger = null; try { String swaggerFile = getSwaggerFilePath(); if( swaggerFile != null && !swaggerFile.isEmpty()) { File f = new File(swaggerFile); if(!f.exists() || !f.isFile()) { throw new TranslatorException(SwaggerPlugin.Event.TEIID28019, SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28019, swaggerFile)); } SwaggerParser parser = new SwaggerParser(); swagger = parser.read(f.getAbsolutePath(), null, true); } else { BaseQueryExecution execution = new BaseQueryExecution(this.ef, null, null, conn); Map<String, List<String>> headers = new HashMap<String, List<String>>(); BinaryWSProcedureExecution call = execution.buildInvokeHTTP("GET", "swagger.json", null, headers); call.execute(); if (call.getResponseCode() != 200) { throw new TranslatorException(SwaggerPlugin.Event.TEIID28015, SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28015,call.getResponseCode())); } Blob out = (Blob)call.getOutputParameterValues().get(0); ObjectMapper objectMapper = new ObjectMapper(); JsonNode rootNode = objectMapper.readTree(out.getBinaryStream()); swagger = new SwaggerParser().read(rootNode, true); } } catch (Exception e) { throw new TranslatorException(SwaggerPlugin.Event.TEIID28016, e, SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28016, e)); } return swagger; } SwaggerMetadataProcessor(SwaggerExecutionFactory ef); @TranslatorProperty(display="Swagger metadata file path", category=PropertyType.IMPORT, description="Swagger metadata file path.") String getSwaggerFilePath(); void setSwaggerFilePath(String swaggerFilePath); @TranslatorProperty(display="Use Host from Swagger File", category=PropertyType.IMPORT, description="Use default host specified in the Swagger file; Defaults to true") boolean isUseDefaultHost(); void setUseDefaultHost(boolean useDefault); @TranslatorProperty(display="Preferred Scheme", category=PropertyType.IMPORT, description="Preferred Scheme to use when Swagger file supports multiple invocation schemes like http, https etc.") String getPreferredScheme(); void setPreferredScheme(String scheme); @TranslatorProperty(display="Preferred Accept Header", category=PropertyType.IMPORT, description="Preferred Accept MIME type header, this should be one of the Swagger " + "'produces' types; default is application/json") String getPreferredProduces(); void setPreferredProduces(String accept); @TranslatorProperty(display="Preferred Content-type Header", category=PropertyType.IMPORT, description="Preferred Content-type header, this should be one of the Swagger 'consume' " + "types, default is application/json") String getPreferredConsumes(); void setPreferredConsumes(String type); @Override void process(MetadataFactory mf, WSConnection connection); static Map<HttpMethod, Operation> getOperationMap(Path operations); static final String KEY_NAME; static final String KEY_VALUE; @ExtensionMetadataProperty(applicable=Procedure.class, datatype=String.class, display="URI",
            description="Used to define endpoint of the procedure", required=true)
    final static String URI; @ExtensionMetadataProperty(applicable=Procedure.class, datatype=String.class, display="Http Method",
            description="Http method used to execute the procedure", required=true,
            allowed="GET,POST,PUT,DELETE,OPTIONS,HEAD,PATCH")
    final static String METHOD; @ExtensionMetadataProperty(applicable=Procedure.class, datatype=String.class, display="Scheme",
            description="Scheme to use http, https etc.",
            allowed="HTTP,HTTPS")
    final static String SCHEME; @ExtensionMetadataProperty(applicable=Procedure.class, datatype=String.class, display="Produces",
            description="Used to define content type produced by this procedure, default JSON assumed")
    final static String PRODUCES; @ExtensionMetadataProperty(applicable=Procedure.class, datatype=String.class, display="Consumes",
            description="Used to define content type consumed by this procedure with body type parameters. Default JSON assumed")
    final static String CONSUMES; @ExtensionMetadataProperty(applicable=Procedure.class, datatype=String.class, display="Charset",
            description="Encoding of the return data")
    final static String CHARSET; @ExtensionMetadataProperty(applicable=ProcedureParameter.class, datatype=String.class, display="Parameter Type",
            description="Parameter type, as to how the parameter is being provided to the procedure", required=true,
            allowed="PATH,QUERY,FORM,FORMDATA,BODY,HEADER")
    final static String PARAMETER_TYPE; @ExtensionMetadataProperty(applicable=ProcedureParameter.class, datatype=String.class, display="Collection Format",
            description="Determines the format of the array if type array is used, like CSV,TSV etc.",
            allowed="CSV,SSV,TSV,PIPES,MULTI")
    final static String COLLECION_FORMAT; }