Search in sources :

Example 21 with ParseOptions

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

the class OpenAPIDeserializerTest method testDiscriminatorObject.

@Test
void testDiscriminatorObject(@Injectable List<AuthorizationValue> auths) {
    String yaml = "openapi: '3.0.1'\n" + "components:\n" + "  schemas:\n" + "    Pet:\n" + "      type: object\n" + "      required:\n" + "      - pet_type\n" + "      properties:\n" + "        pet_type:\n" + "          type: string\n" + "      discriminator:\n" + "        propertyName: pet_type\n" + "        mapping:\n" + "          cachorro: Dog\n" + "    Cat:\n" + "      allOf:\n" + "      - $ref: '#/components/schemas/Pet'\n" + "      - type: object\n" + "        # all other properties specific to a `Cat`\n" + "        properties:\n" + "          name:\n" + "            type: string\n" + "    Dog:\n" + "      allOf:\n" + "      - $ref: '#/components/schemas/Pet'\n" + "      - type: object\n" + "        # all other properties specific to a `Dog`\n" + "        properties:\n" + "          bark:\n" + "            type: string\n" + "    Lizard:\n" + "      allOf:\n" + "      - $ref: '#/components/schemas/Pet'\n" + "      - type: object\n" + "        # all other properties specific to a `Lizard`\n" + "        properties:\n" + "          lovesRocks:\n" + "            type: boolean";
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    SwaggerParseResult result = parser.readContents(yaml, auths, options);
    List<String> messageList = result.getMessages();
    Set<String> messages = new HashSet<>(messageList);
    assertEquals(result.getOpenAPI().getComponents().getSchemas().get("Pet").getDiscriminator().getPropertyName(), "pet_type");
    assertEquals(result.getOpenAPI().getComponents().getSchemas().get("Pet").getDiscriminator().getMapping().get("cachorro"), "Dog");
    assertTrue(messages.contains("attribute paths is missing"));
    assertTrue(messages.contains("attribute info 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) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 22 with ParseOptions

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

the class OpenAPIParserTest method testIssue768.

@Test
public void testIssue768() {
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    SwaggerParseResult result = new OpenAPIParser().readLocation("issue768-main.yaml", null, options);
    assertNotNull(result);
    OpenAPI openAPI = result.getOpenAPI();
    assertNotNull(openAPI);
    Components components = openAPI.getComponents();
    assertNotNull(components);
    Map<String, Schema> schemas = components.getSchemas();
    assertNotNull(schemas);
    assertEquals(schemas.size(), 1);
}
Also used : Components(io.swagger.v3.oas.models.Components) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) Schema(io.swagger.v3.oas.models.media.Schema) ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.junit.Test)

Example 23 with ParseOptions

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

the class OpenAPIParserTest method testIssue258.

@Test
public void testIssue258() {
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    SwaggerParseResult result = new OpenAPIParser().readLocation("duplicateOperationId.json", null, options);
    System.out.println(result.getMessages());
    assertNotNull(result);
    assertNotNull(result.getOpenAPI());
    assertEquals(result.getMessages().get(0), "attribute paths.'/pets/{id}'(post).operationId is repeated");
}
Also used : ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) Test(org.junit.Test)

Example 24 with ParseOptions

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

the class OpenAPIParserTest method testIssue1143.

@Test
public void testIssue1143() {
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    SwaggerParseResult result = new OpenAPIParser().readLocation("issue-1143.json", null, options);
    assertNotNull(result.getOpenAPI());
    assertNotNull(result.getOpenAPI().getComponents().getSchemas().get("RedisResource"));
    assertNotNull(result.getOpenAPI().getComponents().getSchemas().get("identificacion_usuario_aplicacion"));
}
Also used : ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) Test(org.junit.Test)

Example 25 with ParseOptions

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

the class OpenAPIParserTest method testIssueRelativeRefs2.

@Test
public void testIssueRelativeRefs2() {
    String location = "exampleSpecs/specs/my-domain/test-api/v1/test-api-swagger_v1.json";
    ParseOptions po = new ParseOptions();
    po.setResolve(true);
    SwaggerParseResult result = new OpenAPIParser().readLocation(location, null, po);
    assertNotNull(result.getOpenAPI());
    OpenAPI openAPI = result.getOpenAPI();
    Map<String, Schema> schemas = openAPI.getComponents().getSchemas();
    Assert.assertTrue(schemas.get("confirmMessageType_v01").getProperties().get("resources") instanceof ArraySchema);
    ArraySchema arraySchema = (ArraySchema) schemas.get("confirmMessageType_v01").getProperties().get("resources");
    Schema prop = (Schema) arraySchema.getItems().getProperties().get("resourceID");
    assertEquals(prop.get$ref(), "#/components/schemas/simpleIDType_v01");
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) Schema(io.swagger.v3.oas.models.media.Schema) ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.junit.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