Search in sources :

Example 56 with ParseOptions

use of io.swagger.v3.parser.core.models.ParseOptions in project swagger-parser by swagger-api.

the class OpenAPIV3ParserTest method testIssueFlattenAdditionalPropertiesSchemaInlineModelTrue.

@Test
public void testIssueFlattenAdditionalPropertiesSchemaInlineModelTrue() {
    OpenAPIV3Parser openApiParser = new OpenAPIV3Parser();
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    options.setFlatten(true);
    options.setFlattenComposedSchemas(true);
    options.setCamelCaseFlattenNaming(true);
    SwaggerParseResult parseResult = openApiParser.readLocation("additionalPropertiesFlatten.yaml", null, options);
    OpenAPI openAPI = parseResult.getOpenAPI();
    // responses
    assertNotNull(openAPI.getComponents().getSchemas().get("InlineResponseMap200"));
    assertEquals(((ComposedSchema) openAPI.getComponents().getSchemas().get("InlineResponseMap200")).getOneOf().get(0).get$ref(), "#/components/schemas/Macaw1");
    assertNotNull(openAPI.getComponents().getSchemas().get("InlineResponseMapItems404"));
    assertEquals(((ComposedSchema) openAPI.getComponents().getSchemas().get("InlineResponseMapItems404")).getAnyOf().get(0).get$ref(), "#/components/schemas/Macaw2");
}
Also used : ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 57 with ParseOptions

use of io.swagger.v3.parser.core.models.ParseOptions in project swagger-parser by swagger-api.

the class OpenAPIV3ParserTest method testEmptyQueryParameterExample.

@Test
public void testEmptyQueryParameterExample() {
    final ParseOptions options = new ParseOptions();
    options.setResolve(true);
    SwaggerParseResult result = new OpenAPIV3Parser().readLocation("src/test/resources/emptyQueryParameter.yaml", null, options);
    assertEquals("", result.getOpenAPI().getPaths().get("/foo").getGet().getParameters().get(0).getExample());
}
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 58 with ParseOptions

use of io.swagger.v3.parser.core.models.ParseOptions in project swagger-parser by swagger-api.

the class OpenAPIV3ParserTest method issue1455_testResolveFullyV2_shouldNotThrowNPE.

@Test
public void issue1455_testResolveFullyV2_shouldNotThrowNPE() throws Exception {
    String pathFile = FileUtils.readFileToString(new File("src/test/resources/swagger.json"));
    pathFile = pathFile.replace("${dynamicPort}", String.valueOf(this.serverPort));
    ParseOptions options = new ParseOptions();
    options.setResolveFully(true);
    SwaggerParseResult result = new OpenAPIV3Parser().readContents(pathFile, new ArrayList<>(), options);
    Assert.assertNotNull(result);
    Assert.assertNull(result.getOpenAPI());
    Assert.assertNotNull(result.getMessages());
    Assert.assertEquals(result.getMessages().size(), 1);
    Assert.assertEquals(result.getMessages().get(0), "attribute openapi is missing");
}
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 59 with ParseOptions

use of io.swagger.v3.parser.core.models.ParseOptions in project swagger-parser by swagger-api.

the class OpenAPIV3ParserTest method testDeserializeExampleFlag.

@Test
public void testDeserializeExampleFlag() {
    OpenAPIV3Parser openApiParser = new OpenAPIV3Parser();
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    options.setResolveCombinators(true);
    options.setResolveFully(true);
    options.setFlatten(true);
    SwaggerParseResult parseResult = openApiParser.readLocation("exampleFlag.yaml", null, options);
    OpenAPI openAPI = parseResult.getOpenAPI();
    assertTrue(openAPI.getComponents().getSchemas().get("TestDTO").getExampleSetFlag());
    assertNull(openAPI.getComponents().getSchemas().get("TestDTO").getExample());
    assertTrue(openAPI.getComponents().getSchemas().get("TestString").getExampleSetFlag());
    assertNull(openAPI.getComponents().getSchemas().get("TestString").getExample());
    assertTrue(openAPI.getComponents().getSchemas().get("TestNumber").getExampleSetFlag());
    assertNull(openAPI.getComponents().getSchemas().get("TestNumber").getExample());
    assertFalse(openAPI.getComponents().getSchemas().get("TestDTOMissing").getExampleSetFlag());
    assertNull(openAPI.getComponents().getSchemas().get("TestDTOMissing").getExample());
    assertFalse(openAPI.getComponents().getSchemas().get("TestStringMissing").getExampleSetFlag());
    assertNull(openAPI.getComponents().getSchemas().get("TestStringMissing").getExample());
    assertFalse(openAPI.getComponents().getSchemas().get("TestNumberMissing").getExampleSetFlag());
    assertNull(openAPI.getComponents().getSchemas().get("TestNumberMissing").getExample());
}
Also used : ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 60 with ParseOptions

use of io.swagger.v3.parser.core.models.ParseOptions in project swagger-parser by swagger-api.

the class OpenAPIV3ParserTest method testIssue811.

@Test
public void testIssue811() {
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    final OpenAPI openAPI = new OpenAPIV3Parser().readLocation("oapi-reference-test/index.yaml", null, options).getOpenAPI();
    Assert.assertNotNull(openAPI);
    Assert.assertEquals(openAPI.getPaths().get("/").getGet().getResponses().get("200").getContent().get("application/json").getSchema().get$ref(), "#/components/schemas/schema-with-reference");
}
Also used : ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Aggregations

ParseOptions (io.swagger.v3.parser.core.models.ParseOptions)202 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)172 Test (org.testng.annotations.Test)166 OpenAPI (io.swagger.v3.oas.models.OpenAPI)144 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)140 Schema (io.swagger.v3.oas.models.media.Schema)52 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)51 StringSchema (io.swagger.v3.oas.models.media.StringSchema)46 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)44 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)40 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)36 ByteArraySchema (io.swagger.v3.oas.models.media.ByteArraySchema)25 MapSchema (io.swagger.v3.oas.models.media.MapSchema)23 Test (org.junit.Test)20 File (java.io.File)12 Parameter (io.swagger.v3.oas.models.parameters.Parameter)11 Expectations (mockit.Expectations)11 HashSet (java.util.HashSet)10 QueryParameter (io.swagger.v3.oas.models.parameters.QueryParameter)9 PathItem (io.swagger.v3.oas.models.PathItem)8