Search in sources :

Example 56 with Paths

use of io.swagger.v3.oas.models.Paths in project swagger-parser by swagger-api.

the class OpenAPIDeserializerTest method testAdditionalPropertiesBoolean.

@Test
public void testAdditionalPropertiesBoolean() {
    String yaml = "openapi: 3.0.0\n" + "info:\n" + "  title: Test\n" + "  version: 1.0.0\n" + "paths:\n" + "  \"/store/inventory\":\n" + "    post:\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              additionalProperties: true\n" + "      responses:\n" + "        '200':\n" + "          description: successful operation\n" + "          content:\n" + "            application/json:\n" + "              schema:\n" + "                additionalProperties: false\n";
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    SwaggerParseResult result = parser.readContents(yaml, null, null);
    assertEquals(result.getMessages(), emptyList());
    OpenAPI openAPI = result.getOpenAPI();
    Schema body = openAPI.getPaths().get("/store/inventory").getPost().getRequestBody().getContent().get("application/json").getSchema();
    assertEquals(body.getAdditionalProperties(), Boolean.TRUE);
    assertEquals(body.getClass(), MapSchema.class);
    Schema response = openAPI.getPaths().get("/store/inventory").getPost().getResponses().get("200").getContent().get("application/json").getSchema();
    assertEquals(response.getAdditionalProperties(), Boolean.FALSE);
    assertEquals(response.getClass(), ObjectSchema.class);
}
Also used : DateSchema(io.swagger.v3.oas.models.media.DateSchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) 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) BinarySchema(io.swagger.v3.oas.models.media.BinarySchema) 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 Paths

use of io.swagger.v3.oas.models.Paths in project swagger-parser by swagger-api.

the class OpenAPIDeserializerTest method testIssue247.

@Test
public void testIssue247() {
    String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + "  description: bleh\n" + "  version: 2.0.0\n" + "  title: Test\n" + "paths:\n" + "  /:\n" + "    get:\n" + "      responses:\n" + "        '200':\n" + "          description: OK\n" + "    parameters: []\n" + "components:\n" + "  schemas:\n" + "    Pet:\n" + "      allOf:\n" + "        - type: object\n" + "          required:\n" + "            - id\n" + "          properties:\n" + "            id:\n" + "              type: integer\n" + "              format: int64";
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    SwaggerParseResult result = parser.readContents(yaml, null, null);
    OpenAPI openAPI = result.getOpenAPI();
    assertNotNull(openAPI.getComponents().getSchemas().get("Pet"));
}
Also used : 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 58 with Paths

use of io.swagger.v3.oas.models.Paths in project swagger-parser by swagger-api.

the class OpenAPIDeserializerTest method testValidatorIssue50.

@Test
public void testValidatorIssue50() {
    String yaml = "openapi: 3.0.0\n" + "servers:\n" + "  - url: 'http://local.xxx.com/'\n" + "info:\n" + "  version: 2.0.0\n" + "  title: Beanhunter API\n" + "  description: Description of the api goes here.\n" + "paths:\n" + "  /city:\n" + "    get:\n" + "      description: test description\n" + "components:\n" + "  schemas:\n" + "    Endpoints:\n" + "      title: Endpoints object\n" + "      properties:\n" + "        links: {}";
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    SwaggerParseResult result = parser.readContents(yaml, null, null);
    assertTrue(result.getMessages().size() == 1);
}
Also used : SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) Test(org.testng.annotations.Test)

Example 59 with Paths

use of io.swagger.v3.oas.models.Paths in project swagger-parser by swagger-api.

the class NetworkReferenceTest method testValidateExternalRefsTrueRemote.

@Test(description = "option true, adds Original Location to messages when ref is remote")
public void testValidateExternalRefsTrueRemote() throws Exception {
    ParseOptions options = new ParseOptions();
    options.setValidateExternalRefs(true);
    options.setResolve(true);
    new Expectations() {

        {
            remoteUrl.urlToString("http://localhost:8080/swos-443/root.yaml", new ArrayList<>());
            result = issue_443_yaml;
            remoteUrl.urlToString("http://localhost:8080/swos-443/ref.yaml", new ArrayList<>());
            result = issue_443_ref_yaml;
        }
    };
    SwaggerParseResult result = new OpenAPIV3Parser().readLocation("http://localhost:8080/swos-443/root.yaml", null, options);
    OpenAPI openAPI = result.getOpenAPI();
    assertNotNull(result.getMessages());
    assertEquals(result.getMessages().size(), 19);
    assertNotNull(openAPI);
    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"));
}
Also used : Expectations(mockit.Expectations) 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 Paths

use of io.swagger.v3.oas.models.Paths in project swagger-parser by swagger-api.

the class OpenAPIDeserializerTest method testIssue1072.

@Test
public void testIssue1072() throws Exception {
    String yaml = "openapi: 3.0.0\n" + "info:\n" + "  title: Test\n" + "  version: 1.0.0\n" + "\n" + "paths:\n" + "  /value:\n" + "    get:\n" + "      operationId: getValues\n" + "      responses:\n" + "        200:\n" + "          description: Successful response\n" + "          content:\n" + "            application/json:\n" + "              schema:\n" + "                $ref: '#/components/schemas/ComponentA'\n" + "components:\n" + "  schemas:\n" + "    ComponentA:\n" + "      description: Component A\n" + "      type: object\n" + "      allOf:\n" + "        - type: object\n" + "          properties:\n" + "            attributeWithoutType:\n" + "              allOf:\n" + "              - $ref: '#/components/schemas/ComponentB'\n" + "              default: \"coucou\"\n" + "            attributeWithWrongType:\n" + "              type: object\n" + "              allOf:\n" + "                - $ref: '#/components/schemas/ComponentB'\n" + "              default: \"coucou\"\n" + "            correctAttribute:\n" + "              type: string\n" + "              allOf:\n" + "                - $ref: '#/components/schemas/ComponentB'\n" + "              default: \"coucou\"\n" + "    ComponentB:\n" + "      description: Component B\n" + "      type: string";
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    SwaggerParseResult result = parser.readContents(yaml, null, null);
    OpenAPI openAPI = result.getOpenAPI();
    assertNotNull(openAPI);
}
Also used : 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

Test (org.testng.annotations.Test)154 OpenAPI (io.swagger.v3.oas.models.OpenAPI)145 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)75 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)70 PathItem (io.swagger.v3.oas.models.PathItem)61 Operation (io.swagger.v3.oas.models.Operation)46 Paths (io.swagger.v3.oas.models.Paths)45 Schema (io.swagger.v3.oas.models.media.Schema)40 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)36 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)33 Components (io.swagger.v3.oas.models.Components)32 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)27 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)27 StringSchema (io.swagger.v3.oas.models.media.StringSchema)25 ByteArraySchema (io.swagger.v3.oas.models.media.ByteArraySchema)23 Parameter (io.swagger.v3.oas.models.parameters.Parameter)23 Info (io.swagger.v3.oas.models.info.Info)21 MapSchema (io.swagger.v3.oas.models.media.MapSchema)21 ParseOptions (io.swagger.v3.parser.core.models.ParseOptions)21 DateSchema (io.swagger.v3.oas.models.media.DateSchema)19