@Test public void testAnnotation() throws Exception{ OpenAPIExecutionFactory translator = new OpenAPIExecutionFactory(); 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 SwaggerParseResult getSchema(WSConnection conn) throws TranslatorException { SwaggerParseResult swagger = null; try { String url = metadataUrl; if( url == null) { url = "openapi"; } OpenAPIParser parser = new OpenAPIParser() { @Override protected List<SwaggerParserExtension> getExtensions() { List<SwaggerParserExtension> extensions = super.getExtensions(); SwaggerConverter converter = new SwaggerConverter(); if (!extensions.contains(converter)) { extensions.add(converter); } return extensions; } }; ParseOptions parseOptions = new ParseOptions(); parseOptions.setResolve(true); if (url.startsWith("classpath:") || url.startsWith("file:")) { swagger = parser.readLocation(url, null, parseOptions); } 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", url, 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); String contents = ObjectConverterUtil.convertToString(out.getBinaryStream()); swagger = parser.readContents(contents, null, parseOptions); } } catch (Exception e) { throw new TranslatorException(SwaggerPlugin.Event.TEIID28016, e, SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28016, e)); } return swagger; }
OpenAPIMetadataProcessor implements MetadataProcessor<WSConnection> { protected SwaggerParseResult getSchema(WSConnection conn) throws TranslatorException { SwaggerParseResult swagger = null; try { String url = metadataUrl; if( url == null) { url = "openapi"; } OpenAPIParser parser = new OpenAPIParser() { @Override protected List<SwaggerParserExtension> getExtensions() { List<SwaggerParserExtension> extensions = super.getExtensions(); SwaggerConverter converter = new SwaggerConverter(); if (!extensions.contains(converter)) { extensions.add(converter); } return extensions; } }; ParseOptions parseOptions = new ParseOptions(); parseOptions.setResolve(true); if (url.startsWith("classpath:") || url.startsWith("file:")) { swagger = parser.readLocation(url, null, parseOptions); } 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", url, 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); String contents = ObjectConverterUtil.convertToString(out.getBinaryStream()); swagger = parser.readContents(contents, null, parseOptions); } } catch (Exception e) { throw new TranslatorException(SwaggerPlugin.Event.TEIID28016, e, SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28016, e)); } return swagger; } }
OpenAPIMetadataProcessor implements MetadataProcessor<WSConnection> { protected SwaggerParseResult getSchema(WSConnection conn) throws TranslatorException { SwaggerParseResult swagger = null; try { String url = metadataUrl; if( url == null) { url = "openapi"; } OpenAPIParser parser = new OpenAPIParser() { @Override protected List<SwaggerParserExtension> getExtensions() { List<SwaggerParserExtension> extensions = super.getExtensions(); SwaggerConverter converter = new SwaggerConverter(); if (!extensions.contains(converter)) { extensions.add(converter); } return extensions; } }; ParseOptions parseOptions = new ParseOptions(); parseOptions.setResolve(true); if (url.startsWith("classpath:") || url.startsWith("file:")) { swagger = parser.readLocation(url, null, parseOptions); } 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", url, 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); String contents = ObjectConverterUtil.convertToString(out.getBinaryStream()); swagger = parser.readContents(contents, null, parseOptions); } } catch (Exception e) { throw new TranslatorException(SwaggerPlugin.Event.TEIID28016, e, SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28016, e)); } return swagger; } OpenAPIMetadataProcessor(OpenAPIExecutionFactory ef); }
OpenAPIMetadataProcessor implements MetadataProcessor<WSConnection> { protected SwaggerParseResult getSchema(WSConnection conn) throws TranslatorException { SwaggerParseResult swagger = null; try { String url = metadataUrl; if( url == null) { url = "openapi"; } OpenAPIParser parser = new OpenAPIParser() { @Override protected List<SwaggerParserExtension> getExtensions() { List<SwaggerParserExtension> extensions = super.getExtensions(); SwaggerConverter converter = new SwaggerConverter(); if (!extensions.contains(converter)) { extensions.add(converter); } return extensions; } }; ParseOptions parseOptions = new ParseOptions(); parseOptions.setResolve(true); if (url.startsWith("classpath:") || url.startsWith("file:")) { swagger = parser.readLocation(url, null, parseOptions); } 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", url, 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); String contents = ObjectConverterUtil.convertToString(out.getBinaryStream()); swagger = parser.readContents(contents, null, parseOptions); } } catch (Exception e) { throw new TranslatorException(SwaggerPlugin.Event.TEIID28016, e, SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28016, e)); } return swagger; } OpenAPIMetadataProcessor(OpenAPIExecutionFactory ef); @TranslatorProperty(display="OpenAPI metadata URL", category=PropertyType.IMPORT, description="OpenAPI metadata URL") String getMetadataUrl(); void setMetadataUrl(String metadataUrl); @TranslatorProperty(display="Server", category=PropertyType.IMPORT, description="Server to use when multiple servers are defined") String getServer(); void setServer(String server); @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(PathItem operations); }
OpenAPIMetadataProcessor implements MetadataProcessor<WSConnection> { protected SwaggerParseResult getSchema(WSConnection conn) throws TranslatorException { SwaggerParseResult swagger = null; try { String url = metadataUrl; if( url == null) { url = "openapi"; } OpenAPIParser parser = new OpenAPIParser() { @Override protected List<SwaggerParserExtension> getExtensions() { List<SwaggerParserExtension> extensions = super.getExtensions(); SwaggerConverter converter = new SwaggerConverter(); if (!extensions.contains(converter)) { extensions.add(converter); } return extensions; } }; ParseOptions parseOptions = new ParseOptions(); parseOptions.setResolve(true); if (url.startsWith("classpath:") || url.startsWith("file:")) { swagger = parser.readLocation(url, null, parseOptions); } 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", url, 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); String contents = ObjectConverterUtil.convertToString(out.getBinaryStream()); swagger = parser.readContents(contents, null, parseOptions); } } catch (Exception e) { throw new TranslatorException(SwaggerPlugin.Event.TEIID28016, e, SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28016, e)); } return swagger; } OpenAPIMetadataProcessor(OpenAPIExecutionFactory ef); @TranslatorProperty(display="OpenAPI metadata URL", category=PropertyType.IMPORT, description="OpenAPI metadata URL") String getMetadataUrl(); void setMetadataUrl(String metadataUrl); @TranslatorProperty(display="Server", category=PropertyType.IMPORT, description="Server to use when multiple servers are defined") String getServer(); void setServer(String server); @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(PathItem 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="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=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; }