Search in sources :

Example 41 with SwaggerParser

use of io.swagger.parser.SwaggerParser in project gravitee-management-rest-api by gravitee-io.

the class SwaggerServiceImpl method transformV2.

private Swagger transformV2(String content, PageConfigurationEntity config) {
    Swagger swagger = new SwaggerParser().parse(content);
    if (swagger != null && config != null && config.getTryItURL() != null) {
        URI newURI = URI.create(config.getTryItURL());
        swagger.setSchemes(Collections.singletonList(Scheme.forValue(newURI.getScheme())));
        swagger.setHost((newURI.getPort() != -1) ? newURI.getHost() + ':' + newURI.getPort() : newURI.getHost());
        swagger.setBasePath((newURI.getRawPath().isEmpty()) ? "/" : newURI.getRawPath());
    }
    return swagger;
}
Also used : SwaggerParser(io.swagger.parser.SwaggerParser) Swagger(io.swagger.models.Swagger) URI(java.net.URI)

Example 42 with SwaggerParser

use of io.swagger.parser.SwaggerParser in project syndesis by syndesisio.

the class BaseSwaggerConnectorGeneratorTest method shouldCreatePropertyParametersFromPetstoreSwagger.

@Test
public void shouldCreatePropertyParametersFromPetstoreSwagger() throws IOException {
    final String specification = resource("/swagger/petstore.swagger.json");
    final Swagger swagger = new SwaggerParser().parse(specification);
    final Parameter petIdPathParameter = swagger.getPath("/pet/{petId}").getGet().getParameters().get(0);
    final Optional<ConfigurationProperty> maybeConfigurationProperty = BaseSwaggerConnectorGenerator.createPropertyFromParameter(petIdPathParameter);
    final ConfigurationProperty expected = // 
    new ConfigurationProperty.Builder().componentProperty(// 
    false).deprecated(// 
    false).description(// 
    "ID of pet to return").displayName(// 
    "petId").group(// 
    "producer").javaType(// 
    Long.class.getName()).kind(// 
    "property").required(// 
    true).secret(// 
    false).type(// 
    "integer").build();
    assertThat(maybeConfigurationProperty).hasValue(expected);
}
Also used : SwaggerParser(io.swagger.parser.SwaggerParser) ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) Swagger(io.swagger.models.Swagger) Parameter(io.swagger.models.parameters.Parameter) Test(org.junit.Test)

Example 43 with SwaggerParser

use of io.swagger.parser.SwaggerParser in project syndesis by syndesisio.

the class SwaggerHelper method parse.

public static SwaggerModelInfo parse(final String specification, final boolean validate) {
    final SwaggerModelInfo.Builder resultBuilder = new SwaggerModelInfo.Builder();
    final String resolvedSpecification;
    try {
        resolvedSpecification = resolve(specification);
        resultBuilder.resolvedSpecification(resolvedSpecification);
    } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") final Exception e) {
        LOG.debug("Unable to resolve Swagger specification\n{}\n", specification, e);
        return resultBuilder.addError(new Violation.Builder().error("error").property("").message("Unable to resolve Swagger specification from: " + ofNullable(specification).map(s -> StringUtils.abbreviate(s, 100)).orElse("")).build()).build();
    }
    final SwaggerParser parser = new SwaggerParser();
    final Swagger swagger = parser.parse(resolvedSpecification);
    if (swagger == null) {
        LOG.debug("Unable to read Swagger specification\n{}\n", specification);
        return resultBuilder.addError(new Violation.Builder().error("error").property("").message("Unable to read Swagger specification from: " + ofNullable(specification).map(s -> StringUtils.abbreviate(s, 100)).orElse("")).build()).build();
    }
    if (validate) {
        final SwaggerModelInfo swaggerModelInfo = validateJSonSchema(resolvedSpecification, swagger);
        return SyndesisSwaggerValidationRules.getInstance().apply(swaggerModelInfo);
    }
    return resultBuilder.model(swagger).build();
}
Also used : Violation(io.syndesis.common.model.Violation) Violation(io.syndesis.common.model.Violation) SwaggerParser(io.swagger.parser.SwaggerParser) Swagger(io.swagger.models.Swagger) LoggerFactory(org.slf4j.LoggerFactory) ProcessingException(com.github.fge.jsonschema.core.exceptions.ProcessingException) ModelImpl(io.swagger.models.ModelImpl) StringUtils(org.apache.commons.lang3.StringUtils) ProcessingReport(com.github.fge.jsonschema.core.report.ProcessingReport) ArrayList(java.util.ArrayList) Yaml(org.yaml.snakeyaml.Yaml) Locale(java.util.Locale) Path(io.swagger.models.Path) RefProperty(io.swagger.models.properties.RefProperty) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonSchemaFactory(com.github.fge.jsonschema.main.JsonSchemaFactory) Operation(io.swagger.models.Operation) RefModel(io.swagger.models.RefModel) StringUtils.trimToNull(org.apache.commons.lang3.StringUtils.trimToNull) Logger(org.slf4j.Logger) Optional.ofNullable(java.util.Optional.ofNullable) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) List(java.util.List) SwaggerModelInfo(io.syndesis.server.connector.generator.swagger.SwaggerModelInfo) SyndesisSwaggerValidationRules(io.syndesis.server.connector.generator.swagger.SyndesisSwaggerValidationRules) ProcessingMessage(com.github.fge.jsonschema.core.report.ProcessingMessage) Entry(java.util.Map.Entry) RemoteUrl(io.swagger.parser.util.RemoteUrl) Optional(java.util.Optional) HttpMethod(io.swagger.models.HttpMethod) Json(io.syndesis.common.util.Json) JsonSchema(com.github.fge.jsonschema.main.JsonSchema) SwaggerParser(io.swagger.parser.SwaggerParser) Swagger(io.swagger.models.Swagger) SwaggerModelInfo(io.syndesis.server.connector.generator.swagger.SwaggerModelInfo) ProcessingException(com.github.fge.jsonschema.core.exceptions.ProcessingException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 44 with SwaggerParser

use of io.swagger.parser.SwaggerParser in project teiid by teiid.

the class TestSwaggerMetadataProcessor method getMetadata.

private static MetadataFactory getMetadata(SwaggerExecutionFactory ef, final String file) throws TranslatorException {
    SwaggerMetadataProcessor processor = new SwaggerMetadataProcessor(ef) {

        protected Swagger getSchema(WSConnection conn) throws TranslatorException {
            File f = new File(file);
            ObjectMapper objectMapper = new ObjectMapper();
            try (FileInputStream fis = new FileInputStream(f)) {
                JsonNode rootNode = objectMapper.readTree(fis);
                return new SwaggerParser().read(rootNode, true);
            } catch (IOException e) {
                throw new TranslatorException(e);
            }
        }
    };
    processor.setPreferredProduces("application/json");
    processor.setPreferredConsumes("application/json");
    processor.setPreferredScheme("http");
    Properties props = new Properties();
    MetadataFactory mf = new MetadataFactory("vdb", 1, "swagger", SystemMetadata.getInstance().getRuntimeTypeMap(), props, null);
    processor.process(mf, null);
    return mf;
}
Also used : SwaggerParser(io.swagger.parser.SwaggerParser) WSConnection(org.teiid.translator.ws.WSConnection) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) JsonNode(com.fasterxml.jackson.databind.JsonNode) TranslatorException(org.teiid.translator.TranslatorException) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileInputStream(java.io.FileInputStream)

Example 45 with SwaggerParser

use of io.swagger.parser.SwaggerParser in project service-proxy by membrane.

the class SwaggerRewriterInterceptor method init.

@Override
public void init() throws Exception {
    // inherit wsdl="..." from SoapProxy
    if (this.swagger == null || this.swagger.isNull()) {
        Rule parent = router.getParentProxy(this);
        if (parent instanceof SwaggerProxy) {
            setSwagger(((SwaggerProxy) parent).getSwagger());
        }
    }
    // use default if no SwaggerProxy is found
    if (this.swagger == null || this.swagger.isNull()) {
        String swaggerSource = IOUtils.toString(this.getRouter().getResolverMap().resolve(this.swaggerJson));
        this.swagger = new OpenAPIAdapter(new OpenAPIV3Parser().readContents(swaggerSource).getOpenAPI());
        if (this.swagger == null || this.swagger.isNull()) {
            this.swagger = new SwaggerAdapter(new SwaggerParser().parse(swaggerSource));
            if (this.swagger == null || swagger.isNull())
                throw new Exception("couldn't parse Swagger definition");
        }
        this.swaggerUrl = this.swaggerJson;
    }
}
Also used : SwaggerParser(io.swagger.parser.SwaggerParser) SwaggerProxy(com.predic8.membrane.core.rules.SwaggerProxy) Rule(com.predic8.membrane.core.rules.Rule) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser)

Aggregations

SwaggerParser (io.swagger.parser.SwaggerParser)91 Swagger (io.swagger.models.Swagger)44 Test (org.testng.annotations.Test)37 HashSet (java.util.HashSet)21 HashMap (java.util.HashMap)14 Path (io.swagger.models.Path)11 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)11 Map (java.util.Map)10 Operation (io.swagger.models.Operation)9 List (java.util.List)9 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)9 SwaggerDeserializationResult (io.swagger.parser.util.SwaggerDeserializationResult)8 Test (org.junit.Test)8 HttpMethod (io.swagger.models.HttpMethod)7 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)7 File (java.io.File)7 OAuth2Definition (io.swagger.models.auth.OAuth2Definition)6 SecuritySchemeDefinition (io.swagger.models.auth.SecuritySchemeDefinition)6 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)6