Search in sources :

Example 66 with ParseOptions

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

the class InlineModelResolverTest method testIssue1018.

@Test
public void testIssue1018() throws Exception {
    ParseOptions options = new ParseOptions();
    options.setFlatten(true);
    OpenAPI openAPI = new OpenAPIV3Parser().read("flatten.json", null, options);
    assertNotNull(openAPI);
    assertNotNull(openAPI.getComponents().getSchemas().get("ReturnInformation_manufacturer_signin_credentials").getRequired());
}
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)

Example 67 with ParseOptions

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

the class InlineModelResolverTest method testInlineItemsSchema.

@Test(description = "https://github.com/swagger-api/swagger-parser/issues/1527")
public void testInlineItemsSchema() throws Exception {
    ParseOptions options = new ParseOptions();
    options.setFlatten(true);
    OpenAPI openAPI = new OpenAPIV3Parser().read("flatten.json", null, options);
    assertNotNull(openAPI);
    assertNotNull(openAPI.getComponents().getSchemas().get("inline_response_200"));
}
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)

Example 68 with ParseOptions

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

the class OpenAPIV3ParserTest method testValidateExternalRefsTrue.

@Test(description = "option true, adds Original Location to messages when ref is relative/local")
public void testValidateExternalRefsTrue() {
    ParseOptions options = new ParseOptions();
    options.setValidateExternalRefs(true);
    options.setResolve(true);
    SwaggerParseResult result = new OpenAPIV3Parser().readLocation("./swos-443/root.yaml", null, options);
    OpenAPI openAPI = result.getOpenAPI();
    assertNotNull(openAPI);
    assertNotNull(result.getMessages());
    assertEquals(result.getMessages().size(), 19);
    assertTrue(result.getMessages().contains("attribute components.requestBodies.NewItem.asdasd is unexpected (./ref.yaml)"));
    assertTrue(result.getMessages().contains("attribute components.requestBodies.NewItem.descasdasdription is unexpected (./ref.yaml)"));
    assertTrue(result.getMessages().contains("attribute components.responses.GeneralError.descrsaiption is unexpected (./ref.yaml)"));
    assertTrue(result.getMessages().contains("attribute components.responses.GeneralError.asdas is unexpected (./ref.yaml)"));
    assertTrue(result.getMessages().contains("attribute components.responses.GeneralError.description is missing (./ref.yaml)"));
    assertTrue(result.getMessages().contains("attribute components.schemas.Examples.nonExpected is unexpected (./ref.yaml)"));
    assertTrue(result.getMessages().contains("attribute components.parameters.skipParam.[skip].in is not of type `[query|header|path|cookie]` (./ref.yaml)"));
    assertTrue(result.getMessages().contains("attribute components.securitySchemes.api_key.namex is unexpected (./ref.yaml)"));
    assertTrue(result.getMessages().contains("attribute components.securitySchemes.api_key.name is missing (./ref.yaml)"));
    assertTrue(result.getMessages().contains("attribute components.callbacks.webhookVerificationEvent.postx is unexpected (./ref.yaml)"));
    assertTrue(result.getMessages().contains("attribute components.headers.X-Rate-Limit-Limit.descriptasdd is unexpected (./ref.yaml)"));
    assertTrue(result.getMessages().contains("attribute components.links.unsubscribe.parametersx is unexpected (./ref.yaml)"));
    assertTrue(result.getMessages().contains("attribute components.examples.response-example.summaryx is unexpected (./ref.yaml)"));
    assertTrue(result.getMessages().contains("attribute components.examples.response-example. value and externalValue are both present (./ref.yaml)"));
    assertTrue(result.getMessages().contains("attribute components.callbacks.failed.wrongField is not of type `object` (./ref.yaml)"));
    assertTrue(result.getMessages().contains("attribute paths.~1refPet(get).responses is missing (./ref.yaml)"));
    // error message in main file
    assertTrue(result.getMessages().contains("attribute components.schemas.InvalidSchema.invalid is unexpected"));
    assertTrue(result.getMessages().contains("attribute components.schemas.ErrorModel.properties is not of type `object` (./ref.yaml)"));
    assertTrue(result.getMessages().contains("attribute components.schemas.Examples.properties is not of type `object` (./ref.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) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 69 with ParseOptions

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

the class OpenAPIV3ParserTest method testIssue1367.

@Test
public void testIssue1367() {
    OpenAPIV3Parser openApiParser = new OpenAPIV3Parser();
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    options.setResolveCombinators(true);
    options.setResolveFully(true);
    options.setFlatten(true);
    SwaggerParseResult parseResult = openApiParser.readLocation("issue-1367.yaml", null, options);
    OpenAPI openAPI = parseResult.getOpenAPI();
    assertTrue(((Schema) openAPI.getComponents().getSchemas().get("TestDTO").getProperties().get("choice")).getEnum() != null);
}
Also used : ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) ByteArraySchema(io.swagger.v3.oas.models.media.ByteArraySchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) 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 70 with ParseOptions

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

the class OpenAPIV3ParserTest method testIssue1518.

@Test
public void testIssue1518() {
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    SwaggerParseResult result = new OpenAPIV3Parser().readLocation("issue-1518/api.json", null, options);
    OpenAPI openAPI = result.getOpenAPI();
    assertTrue(((Schema) openAPI.getComponents().getSchemas().get("Analemmata").getProperties().get("tashotSipe")).get$ref().equals("#/components/schemas/TashotSipe"));
    assertTrue(openAPI.getComponents().getSchemas().get("analemmata") == null);
}
Also used : ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) ByteArraySchema(io.swagger.v3.oas.models.media.ByteArraySchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) 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)

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