Search in sources :

Example 31 with Info

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

the class OpenAPIV3ParserTest method testIncompatibleRefs.

@Test
public void testIncompatibleRefs() {
    String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "paths:\n" + "  /test:\n" + "    post:\n" + "      responses:\n" + "        '200':\n" + "          $ref: '#/components/schemas/Schema'\n" + "        '400':\n" + "          definitions: this is right\n" + "          description: Bad Request\n" + "          content:\n" + "            '*/*':\n" + "              schema:\n" + "                $ref: '#/components/schemas/Schema'\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              $ref: '#/components/schemas/Schema'\n" + "        required: true\n" + "info:\n" + "  version: ''\n" + "  title: ''\n" + "components:\n" + "  schemas:\n" + "    Schema: {}";
    SwaggerParseResult result = new OpenAPIV3Parser().readContents(yaml, null, null);
    assertNotNull(result.getOpenAPI());
}
Also used : SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) Test(org.testng.annotations.Test)

Example 32 with Info

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

the class OpenAPIV3ParserTest method testParseRefPathParameters.

@Test
public void testParseRefPathParameters() throws Exception {
    String yaml = "openAPI: '2.0'\n" + "info:\n" + "  title: test\n" + "  version: '0.0.0'\n" + "parameters:\n" + "  report-id:\n" + "    name: id\n" + "    in: path\n" + "    type: string\n" + "    required: true\n" + "paths:\n" + "  /reports/{id}:\n" + "    parameters:\n" + "        - $ref: '#/parameters/report-id'\n" + "    put:\n" + "      parameters:\n" + "        - name: id\n" + "          in: body\n" + "          required: true\n" + "          schema:\n" + "            $ref: '#/components/schemas/report'\n" + "      responses:\n" + "        200:\n" + "          description: ok\n" + "definitions:\n" + "  report:\n" + "    type: object\n" + "    properties:\n" + "      id:\n" + "        type: string\n" + "      name:\n" + "        type: string\n" + "    required:\n" + "    - id\n" + "    - name\n";
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    OpenAPI openAPI = (parser.readContents(yaml, null, null)).getOpenAPI();
}
Also used : OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 33 with Info

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

the class ResolverCacheTest method testLoadExternalRefResponseWithNoContent.

@Test
public void testLoadExternalRefResponseWithNoContent() throws Exception {
    final RefFormat format = RefFormat.URL;
    final String ref = "http://my.company.com/path/to/main.yaml";
    final String contentsOfExternalFile = "openapi: 3.0.0\n" + "\n" + "info:\n" + "  version: 1.0.0\n" + "  title: Response include test case child\n" + "\n" + "components:\n" + "  responses:\n" + "    200:\n" + "      description: Success\n";
    new Expectations() {

        {
            RefUtils.readExternalUrlRef(ref, format, auths, "http://my.company.com/path/parent.json");
            times = 1;
            result = contentsOfExternalFile;
        }
    };
    ResolverCache cache = new ResolverCache(openAPI, auths, "http://my.company.com/path/parent.json");
    ApiResponse response = cache.loadRef(ref + "#/components/responses/200", RefFormat.URL, ApiResponse.class);
    assertNotNull(response);
    assertEquals(response.getDescription(), "Success");
    assertNull(response.getContent());
}
Also used : Expectations(mockit.Expectations) RefFormat(io.swagger.v3.parser.models.RefFormat) ResolverCache(io.swagger.v3.parser.ResolverCache) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) Test(org.testng.annotations.Test)

Example 34 with Info

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

the class OAIDeserializationTest method testDeserializeSimpleDefinition.

@Test
public void testDeserializeSimpleDefinition() throws Exception {
    String json = "{\n" + "  \"openapi\": \"3.0.1\",\n" + "  \"info\": {\n" + "    \"title\": \"Swagger Petstore\",\n" + "    \"description\": \"This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.\",\n" + "    \"termsOfService\": \"http://swagger.io/terms/\",\n" + "    \"contact\": {\n" + "      \"email\": \"apiteam@swagger.io\"\n" + "    },\n" + "    \"license\": {\n" + "      \"name\": \"Apache 2.0\",\n" + "      \"url\": \"http://www.apache.org/licenses/LICENSE-2.0.html\"\n" + "    },\n" + "    \"version\": \"1.0.0\"\n" + "  }\n" + "}";
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    SwaggerParseResult result = new OpenAPIV3Parser().readContents(json, null, options);
    assertNotNull(result.getOpenAPI());
}
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 35 with Info

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

the class OpenAPIV3ParserTest method testConverterIssue17.

@Test
public void testConverterIssue17() throws Exception {
    String yaml = "openapi: 3.0.0\n" + "info:\n" + "  version: 0.0.0\n" + "  title: nada\n" + "paths:\n" + "  /persons:\n" + "    get:\n" + "      parameters:\n" + "        - name: testParam\n" + "          in: query\n" + "          style: form\n" + "          schema:\n" + "            type: array\n" + "            items:\n" + "              type: string\n" + "      responses:\n" + "        '200':\n" + "          description: Successful response\n" + "          content:\n" + "            '*/*':\n" + "              schema:\n" + "                $ref: '#/components/schemas/Content'\n" + "components:\n" + "  schemas:\n" + "    Content:\n" + "      type: object";
    ParseOptions options = new ParseOptions();
    options.setResolve(false);
    SwaggerParseResult result = new OpenAPIV3Parser().readContents(yaml, null, options);
    assertNotNull(result.getOpenAPI());
    assertEquals((result.getOpenAPI().getPaths().get("/persons").getGet().getResponses().get("200").getContent().get("*/*").getSchema()).get$ref(), "#/components/schemas/Content");
}
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)

Aggregations

Test (org.testng.annotations.Test)91 OpenAPI (io.swagger.v3.oas.models.OpenAPI)77 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)60 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)56 Info (io.swagger.v3.oas.models.info.Info)39 Schema (io.swagger.v3.oas.models.media.Schema)24 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)22 StringSchema (io.swagger.v3.oas.models.media.StringSchema)22 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)19 Components (io.swagger.v3.oas.models.Components)18 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)18 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)17 Parameter (io.swagger.v3.oas.models.parameters.Parameter)17 ByteArraySchema (io.swagger.v3.oas.models.media.ByteArraySchema)15 QueryParameter (io.swagger.v3.oas.models.parameters.QueryParameter)15 ParseOptions (io.swagger.v3.parser.core.models.ParseOptions)15 BinarySchema (io.swagger.v3.oas.models.media.BinarySchema)14 MapSchema (io.swagger.v3.oas.models.media.MapSchema)14 DateSchema (io.swagger.v3.oas.models.media.DateSchema)13 DateTimeSchema (io.swagger.v3.oas.models.media.DateTimeSchema)13