Search in sources :

Example 86 with Paths

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

the class OpenAPIV3ParserTest method testIssue1644_NullValue.

@Test
public void testIssue1644_NullValue() throws Exception {
    ParseOptions options = new ParseOptions();
    String issue1644 = "openapi: 3.0.0\n" + "info:\n" + "  title: Operations\n" + "  version: 0.0.0\n" + "paths:\n" + "  \"/operations\":\n" + "    post:\n" + "      parameters:\n" + "        - name: param0\n" + "          schema:\n" + "            type: string\n" + "      responses:\n" + "        default:\n" + "          description: None\n";
    SwaggerParseResult result = new OpenAPIV3Parser().readContents(issue1644, null, options);
    Assert.assertNotNull(result);
    Assert.assertNotNull(result.getOpenAPI());
    assertEquals(result.getMessages().size(), 1);
    assertTrue(result.getMessages().contains("attribute paths.'/operations'(post).parameters.[param0].in is missing"));
    assertFalse(result.getMessages().contains("attribute paths.'/operations'(post).parameters.[param0].in is not of type `string`"));
}
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 87 with Paths

use of io.swagger.v3.oas.models.Paths 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 88 with Paths

use of io.swagger.v3.oas.models.Paths 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 89 with Paths

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

the class ResolverFully method resolveFully.

public void resolveFully(OpenAPI openAPI) {
    Components components = openAPI.getComponents();
    if (components != null && components.getRequestBodies() != null) {
        requestBodies = components.getRequestBodies();
        if (requestBodies == null) {
            requestBodies = new HashMap<>();
        }
    }
    if (components != null && components.getSchemas() != null) {
        schemas = components.getSchemas();
        if (schemas == null) {
            schemas = new HashMap<>();
        }
    }
    if (components != null && components.getExamples() != null) {
        examples = components.getExamples();
        if (examples == null) {
            examples = new HashMap<>();
        }
    }
    if (components != null && components.getHeaders() != null) {
        headers = components.getHeaders();
        if (headers == null) {
            headers = new HashMap<>();
        }
    }
    if (components != null && components.getParameters() != null) {
        parameters = components.getParameters();
        if (parameters == null) {
            parameters = new HashMap<>();
        }
    }
    if (components != null && components.getLinks() != null) {
        links = components.getLinks();
        if (links == null) {
            links = new HashMap<>();
        }
    }
    if (components != null && components.getCallbacks() != null) {
        callbacks = components.getCallbacks();
        if (callbacks == null) {
            callbacks = new HashMap<>();
        }
    }
    Paths paths = openAPI.getPaths();
    if (paths != null) {
        for (String pathname : paths.keySet()) {
            PathItem pathItem = paths.get(pathname);
            resolvePath(pathItem);
        }
    }
}
Also used : Components(io.swagger.v3.oas.models.Components) PathItem(io.swagger.v3.oas.models.PathItem) Paths(io.swagger.v3.oas.models.Paths)

Example 90 with Paths

use of io.swagger.v3.oas.models.Paths 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)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