Search in sources :

Example 66 with SwaggerParser

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

the class UnifiedXmlDataShapeGeneratorShapeValidityTest method specifications.

@Parameters
public static Iterable<Object[]> specifications() {
    final List<String> specifications = Collections.singletonList("/swagger/petstore.swagger.json");
    final List<Object[]> parameters = new ArrayList<>();
    specifications.forEach(specification -> {
        String specificationContent;
        try (InputStream in = UnifiedXmlDataShapeGenerator.class.getResourceAsStream(specification)) {
            specificationContent = IOUtils.toString(in, StandardCharsets.UTF_8);
        } catch (final IOException e) {
            throw new AssertionError("Unable to load swagger specification in path: " + specification, e);
        }
        final SwaggerParser parser = new SwaggerParser();
        final Swagger swagger = parser.parse(specificationContent);
        swagger.getPaths().forEach((path, operations) -> {
            operations.getOperationMap().forEach((method, operation) -> {
                final Optional<BodyParameter> bodyParameter = BaseDataShapeGenerator.findBodyParameter(operation);
                if (!bodyParameter.isPresent()) {
                    // only parameters
                    return;
                }
                parameters.add(new Object[] { specificationContent, swagger, operation, specification });
            });
        });
    });
    return parameters;
}
Also used : SwaggerParser(io.swagger.parser.SwaggerParser) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Swagger(io.swagger.models.Swagger) ArrayList(java.util.ArrayList) IOException(java.io.IOException) BodyParameter(io.swagger.models.parameters.BodyParameter) Parameters(org.junit.runners.Parameterized.Parameters)

Example 67 with SwaggerParser

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

the class LegacyConverterTest method testIssue43.

@Test
public void testIssue43() throws Exception {
    new Expectations() {

        {
            remoteUrl.urlToString("http://gateway.marvel.com/docs", new ArrayList<AuthorizationValue>());
            result = marvel_json;
            remoteUrl.urlToString("http://gateway.marvel.com/docs/public", new ArrayList<AuthorizationValue>());
            result = public_json;
        }
    };
    SwaggerParser parser = new SwaggerParser();
    SwaggerDeserializationResult result = parser.readWithInfo("http://gateway.marvel.com/docs", null, true);
    Assert.assertNotNull(result.getSwagger());
}
Also used : Expectations(mockit.Expectations) SwaggerParser(io.swagger.parser.SwaggerParser) AuthorizationValue(io.swagger.models.auth.AuthorizationValue) SwaggerDeserializationResult(io.swagger.parser.util.SwaggerDeserializationResult) Test(org.testng.annotations.Test)

Example 68 with SwaggerParser

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

the class LegacyConverterTest method testIssueFun.

@Test
public void testIssueFun() throws Exception {
    new Expectations() {

        {
            remoteUrl.urlToString("http://localhost:8080/api-docs", new ArrayList<AuthorizationValue>());
            result = resources_json;
            remoteUrl.urlToString("http://localhost:8080/api-docs/pet", new ArrayList<AuthorizationValue>());
            result = pet_json;
            remoteUrl.urlToString("http://localhost:8080/api-docs/store", new ArrayList<AuthorizationValue>());
            result = store_json;
            remoteUrl.urlToString("http://localhost:8080/api-docs/user", new ArrayList<AuthorizationValue>());
            result = user_json;
            remoteUrl.urlToString("http://localhost:8080/api-docs", null);
            result = resources_json;
            remoteUrl.urlToString("http://localhost:8080/api-docs/pet", null);
            result = pet_json;
            remoteUrl.urlToString("http://localhost:8080/api-docs/store", null);
            result = store_json;
            remoteUrl.urlToString("http://localhost:8080/api-docs/user", null);
            result = user_json;
        }
    };
    SwaggerParser parser = new SwaggerParser();
    SwaggerDeserializationResult result = parser.readWithInfo("http://localhost:8080/api-docs", null, true);
    Swagger swagger = parser.read("http://localhost:8080/api-docs");
    Assert.assertNotNull(swagger);
}
Also used : Expectations(mockit.Expectations) SwaggerParser(io.swagger.parser.SwaggerParser) AuthorizationValue(io.swagger.models.auth.AuthorizationValue) SwaggerDeserializationResult(io.swagger.parser.util.SwaggerDeserializationResult) Swagger(io.swagger.models.Swagger) Test(org.testng.annotations.Test)

Example 69 with SwaggerParser

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

the class ParserExtensionsTest method readAllExtensions.

@Test
public void readAllExtensions() throws Exception {
    SwaggerParser parser = new SwaggerParser();
    List<SwaggerParserExtension> extensions = parser.getExtensions();
    assertTrue(extensions.size() == 2, "Didn't find 2 extensions as expected");
}
Also used : SwaggerParser(io.swagger.parser.SwaggerParser) SwaggerParserExtension(io.swagger.parser.SwaggerParserExtension) Test(org.testng.annotations.Test)

Example 70 with SwaggerParser

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

the class SwaggerDeserializerTest method testIssue161.

@Test
public void testIssue161() {
    String yaml = "swagger: '2.0'\n" + "paths:\n" + "  /users:\n" + "    get:\n" + "      parameters:\n" + "        - in: query\n" + "          name: name\n" + "          type: string\n" + "          minLength: 10\n" + "          maxLength: 100\n" + "          required: false\n" + "      responses:\n" + "        default:\n" + "          description: ok";
    SwaggerParser parser = new SwaggerParser();
    SwaggerDeserializationResult result = parser.readWithInfo(yaml);
    Set<String> messages = new HashSet<String>(result.getMessages());
    assertFalse(messages.contains("attribute paths.'/users'(get).[name].maxLength is unexpected"));
}
Also used : SwaggerParser(io.swagger.parser.SwaggerParser) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

SwaggerParser (io.swagger.parser.SwaggerParser)94 Swagger (io.swagger.models.Swagger)47 Test (org.testng.annotations.Test)37 HashSet (java.util.HashSet)21 HashMap (java.util.HashMap)15 Path (io.swagger.models.Path)12 ArrayList (java.util.ArrayList)12 IOException (java.io.IOException)11 Operation (io.swagger.models.Operation)10 Map (java.util.Map)10 List (java.util.List)9 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)9 SwaggerDeserializationResult (io.swagger.parser.util.SwaggerDeserializationResult)8 File (java.io.File)8 Test (org.junit.Test)8 HttpMethod (io.swagger.models.HttpMethod)7 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)7 OAuth2Definition (io.swagger.models.auth.OAuth2Definition)6 SecuritySchemeDefinition (io.swagger.models.auth.SecuritySchemeDefinition)6 Parameter (io.swagger.models.parameters.Parameter)6