Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.parser.core.models.ParseOptions;
import io.swagger.v3.parser.core.models.SwaggerParseResult;
import io.swagger.v3.parser.util.DeserializationUtils;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;

public class OpenAPIV3ParserLargeFilesTest {

@BeforeSuite
@BeforeClass
public static void init() {
System.setProperty("maxYamlCodePoints", "10000000");
DeserializationUtils.getOptions().setMaxYamlCodePoints(10000000);
}

@AfterClass
public void cleanUpAfterAllTests() {
public static void cleanUpAfterAllTests() {
System.clearProperty("maxYamlCodePoints");
DeserializationUtils.getOptions().setMaxYamlCodePoints(3 * 1024 * 1024);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ private String readResourceAsString(String resourceName) throws IOException {
return new String(buffer.toByteArray(), StandardCharsets.UTF_8);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.swagger.v3.parser.test;



import io.swagger.v3.core.util.Yaml;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.swagger.v3.parser.test;

import io.swagger.v3.core.util.Json;
import io.swagger.v3.oas.models.media.Discriminator;
import io.swagger.v3.oas.models.responses.ApiResponse;
import io.swagger.v3.parser.OpenAPIV3Parser;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package io.swagger.v3.parser.test;

import io.swagger.v3.core.util.Json;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.examples.Example;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.parser.OpenAPIV3Parser;
import io.swagger.v3.parser.core.models.ParseOptions;
import io.swagger.v3.parser.core.models.SwaggerParseResult;
import org.testng.annotations.Test;

import static org.testng.Assert.*;
Expand Down Expand Up @@ -54,7 +52,7 @@ public void testSchemaDefaultNotSet() {

OpenAPI openAPI = new OpenAPIV3Parser().readContents(yaml, null, null).getOpenAPI();
assertNotNull(openAPI);

Schema schema = openAPI.getComponents().getSchemas().get("NoDefaultSchema");
assertNotNull(schema);
assertNull(schema.getDefault(), "Default should be null");
Expand All @@ -76,7 +74,7 @@ public void testSchemaExampleExplicitlyNull() {

OpenAPI openAPI = new OpenAPIV3Parser().readContents(yaml, null, null).getOpenAPI();
assertNotNull(openAPI);


Schema schema = openAPI.getComponents().getSchemas().get("NullExampleSchema");
assertNotNull(schema);
Expand All @@ -98,7 +96,7 @@ public void testSchemaExampleNotSet() {

OpenAPI openAPI = new OpenAPIV3Parser().readContents(yaml, null, null).getOpenAPI();
assertNotNull(openAPI);


Schema schema = openAPI.getComponents().getSchemas().get("NoExampleSchema");
assertNotNull(schema);
Expand All @@ -120,7 +118,7 @@ public void testExampleValueExplicitlyNull() {

OpenAPI openAPI = new OpenAPIV3Parser().readContents(yaml, null, null).getOpenAPI();
assertNotNull(openAPI);


Example example = openAPI.getComponents().getExamples().get("NullExample");
assertNotNull(example);
Expand All @@ -142,7 +140,7 @@ public void testExampleValueNotSet() {

OpenAPI openAPI = new OpenAPIV3Parser().readContents(yaml, null, null).getOpenAPI();
assertNotNull(openAPI);


Example example = openAPI.getComponents().getExamples().get("NoValueExample");
assertNotNull(example);
Expand Down Expand Up @@ -204,7 +202,7 @@ public void testAnyOfNullExampleNotPropagated() {
ParseOptions options = new ParseOptions();
options.setResolveFully(true);
options.setResolveCombinators(true);

OpenAPI openAPI = new OpenAPIV3Parser().readContents(yaml, null, options).getOpenAPI();
assertNotNull(openAPI);

Expand Down Expand Up @@ -236,10 +234,10 @@ public void testOneOfExplicitNullExamplePreserved() {
ParseOptions options = new ParseOptions();
options.setResolveFully(true);
options.setResolveCombinators(true);

OpenAPI openAPI = new OpenAPIV3Parser().readContents(yaml, null, options).getOpenAPI();
assertNotNull(openAPI);

Schema combined = openAPI.getComponents().getSchemas().get("CombinedSchema");
assertNotNull(combined);
assertNull(combined.getExample(), "Example should be null");
Expand Down Expand Up @@ -314,11 +312,11 @@ public void testParameterSchemaExampleNullVsNotSet() {

java.util.List<io.swagger.v3.oas.models.parameters.Parameter> params = openAPI.getPaths().get("/test").getGet().getParameters();
assertEquals(params.size(), 2);

Schema nullSchema = params.get(0).getSchema();
assertNull(nullSchema.getExample());
assertTrue(nullSchema.getExampleSetFlag(), "Should be explicitly set to null");

Schema noExampleSchema = params.get(1).getSchema();
assertNull(noExampleSchema.getExample());
assertFalse(noExampleSchema.getExampleSetFlag(), "Should not be set");
Expand Down Expand Up @@ -348,13 +346,13 @@ public void testMediaTypeExampleNullVsNotSet() {

OpenAPI openAPI = new OpenAPIV3Parser().readContents(yaml, null, null).getOpenAPI();
assertNotNull(openAPI);

io.swagger.v3.oas.models.media.Content content = openAPI.getPaths().get("/test").getPost().getRequestBody().getContent();

io.swagger.v3.oas.models.media.MediaType jsonMedia = content.get("application/json");
assertNull(jsonMedia.getExample());
assertTrue(jsonMedia.getExampleSetFlag(), "Should be explicitly set to null");

io.swagger.v3.oas.models.media.MediaType xmlMedia = content.get("application/xml");
assertNull(xmlMedia.getExample());
assertFalse(xmlMedia.getExampleSetFlag(), "Should not be set");
Expand Down Expand Up @@ -383,13 +381,13 @@ public void testHeaderSchemaExampleNullVsNotSet() {

OpenAPI openAPI = new OpenAPIV3Parser().readContents(yaml, null, null).getOpenAPI();
assertNotNull(openAPI);

java.util.Map<String, io.swagger.v3.oas.models.headers.Header> headers = openAPI.getPaths().get("/test").getGet().getResponses().get("200").getHeaders();

Schema nullSchema = headers.get("X-Null-Example").getSchema();
assertNull(nullSchema.getExample());
assertTrue(nullSchema.getExampleSetFlag(), "Should be explicitly set to null");

Schema noExampleSchema = headers.get("X-No-Example").getSchema();
assertNull(noExampleSchema.getExample());
assertFalse(noExampleSchema.getExampleSetFlag(), "Should not be set");
Expand Down Expand Up @@ -426,7 +424,7 @@ public void testAllOfMultipleDifferentDefaults() {
ParseOptions options = new ParseOptions();
options.setResolveFully(true);
options.setResolveCombinators(true);

OpenAPI openAPI = new OpenAPIV3Parser().readContents(yaml, null, options).getOpenAPI();
assertNotNull(openAPI);

Expand Down Expand Up @@ -461,10 +459,10 @@ public void testResolveFullyWithoutCombinators() {
ParseOptions options = new ParseOptions();
options.setResolveFully(true);
options.setResolveCombinators(false);

OpenAPI openAPI = new OpenAPIV3Parser().readContents(yaml, null, options).getOpenAPI();
assertNotNull(openAPI);


Schema extended = openAPI.getComponents().getSchemas().get("ExtendedSchema");
assertNotNull(extended);
Expand Down
Loading