Search in sources :

Example 66 with OpenAPIV3Parser

use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.

the class OpenAPIV3ParserTest method testIssue1335.

@Test
public void testIssue1335() {
    final ParseOptions options = new ParseOptions();
    options.setResolve(true);
    SwaggerParseResult result = new OpenAPIV3Parser().readLocation("src/test/resources/issue1335.yaml", null, options);
    assertNotNull(result.getOpenAPI().getComponents().getExamples().get("ex1"));
}
Also used : ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) Test(org.testng.annotations.Test)

Example 67 with OpenAPIV3Parser

use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.

the class OpenAPIV3ParserTest method testIssue243.

@Test
public void testIssue243() {
    String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + "  version: 0.0.0\n" + "  title: Simple API\n" + "paths:\n" + "  /:\n" + "    get:\n" + "      responses:\n" + "        '200':\n" + "          description: OK\n" + "          content:\n" + "            '*/*':\n" + "              schema:\n" + "                $ref: '#/components/schemas/Simple'\n" + "components:\n" + "  schemas:\n" + "    Simple:\n" + "      type: string";
    SwaggerParseResult result = new OpenAPIV3Parser().readContents(yaml, null, null);
    assertNotNull(result.getOpenAPI());
}
Also used : SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) Test(org.testng.annotations.Test)

Example 68 with OpenAPIV3Parser

use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.

the class OpenAPIV3ParserTest method testDuplicateHttpStatusCodesYaml.

@Test
public void testDuplicateHttpStatusCodesYaml() {
    final String location = "src/test/resources/duplicateHttpStatusCodes.yaml";
    final ParseOptions options = new ParseOptions();
    options.setResolve(true);
    final OpenAPIV3Parser parser = new OpenAPIV3Parser();
    final SwaggerParseResult result = parser.readLocation(location, null, options);
    List<String> messages = result.getMessages();
    assertEquals(1, messages.size());
    assertEquals(messages.get(0), "Duplicate field 200 in `src/test/resources/duplicateHttpStatusCodes.yaml`");
}
Also used : ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) Test(org.testng.annotations.Test)

Example 69 with OpenAPIV3Parser

use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.

the class OpenAPIV3ParserTest method test30.

@Test
public void test30(@Injectable final List<AuthorizationValue> auths) throws Exception {
    String pathFile = FileUtils.readFileToString(new File("src/test/resources/oas3.yaml.template"));
    pathFile = pathFile.replace("${dynamicPort}", String.valueOf(this.serverPort));
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    SwaggerParseResult result = new OpenAPIV3Parser().readContents(pathFile, auths, options);
    Assert.assertNotNull(result);
    Assert.assertNotNull(result.getOpenAPI());
    assertEquals(result.getOpenAPI().getOpenapi(), "3.0.1");
    assertEquals(result.getOpenAPI().getComponents().getSchemas().get("OrderRef").getType(), "object");
}
Also used : ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) File(java.io.File) Test(org.testng.annotations.Test)

Example 70 with OpenAPIV3Parser

use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.

the class OpenAPIDeserializerTest method testResponses.

@Test
public void testResponses() {
    String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + "  version: ''\n" + "  title: ''\n" + "paths: {}\n" + "components:\n" + "  responses:\n" + "    foo:\n" + "      description: description\n" + "      bar: baz\n" + "      x-foo: bar";
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    SwaggerParseResult result = parser.readContents(yaml, null, null);
    List<String> messageList = result.getMessages();
    Set<String> messages = new HashSet<>(messageList);
    assertTrue(messages.contains("attribute components.responses.foo.bar is unexpected"));
    assertEquals(result.getOpenAPI().getComponents().getResponses().get("foo").getExtensions().get("x-foo").toString(), "bar");
}
Also used : SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)295 Test (org.testng.annotations.Test)279 OpenAPI (io.swagger.v3.oas.models.OpenAPI)219 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)184 ParseOptions (io.swagger.v3.parser.core.models.ParseOptions)169 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)83 Schema (io.swagger.v3.oas.models.media.Schema)83 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)80 StringSchema (io.swagger.v3.oas.models.media.StringSchema)77 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)76 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)75 ByteArraySchema (io.swagger.v3.oas.models.media.ByteArraySchema)66 MapSchema (io.swagger.v3.oas.models.media.MapSchema)63 BinarySchema (io.swagger.v3.oas.models.media.BinarySchema)25 QueryParameter (io.swagger.v3.oas.models.parameters.QueryParameter)25 DateSchema (io.swagger.v3.oas.models.media.DateSchema)24 DateTimeSchema (io.swagger.v3.oas.models.media.DateTimeSchema)24 Parameter (io.swagger.v3.oas.models.parameters.Parameter)23 HashSet (java.util.HashSet)22 PathParameter (io.swagger.v3.oas.models.parameters.PathParameter)17