Search in sources :

Example 71 with Paths

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

the class OpenAPIV3ParserTest method testCodegenIssue4555.

@Test
public void testCodegenIssue4555() throws Exception {
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    String yaml = "openapi: 3.0.0\n" + "info:\n" + "  title: test\n" + "  version: \"0.0.1\"\n" + "\n" + "paths:\n" + "  '/contents/{id}':\n" + "    parameters:\n" + "      - name: id\n" + "        in: path\n" + "        description: test\n" + "        required: true\n" + "        schema:\n" + "          type: integer\n" + "  get:\n" + "    description: test\n" + "    responses:\n" + "      '200':\n" + "        description: OK\n" + "        schema: null\n" + "        $ref: '#/components/schemas/Content'\n" + "components:\n" + "  schemas:\n" + "    Content:\n" + "      type: object\n" + "      title: \t\ttest";
    final SwaggerParseResult result = parser.readContents(yaml, null, null);
    // can't parse with tabs!
    assertNull(result.getOpenAPI());
}
Also used : SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) Test(org.testng.annotations.Test)

Example 72 with Paths

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

the class InlineModelResolver method flattenPaths.

private void flattenPaths(Map<String, PathItem> paths) {
    if (paths == null) {
        return;
    }
    for (String pathname : paths.keySet()) {
        PathItem path = paths.get(pathname);
        for (Operation operation : path.readOperations()) {
            flattenBody(pathname, operation.getRequestBody());
            flattenParams(pathname, operation.getParameters());
            flattenResponses(pathname, operation.getResponses());
        }
    }
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) Operation(io.swagger.v3.oas.models.Operation)

Example 73 with Paths

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

the class OpenAPIV3ParserTest method testIssue243.

@Test
public void testIssue243() {
    String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + "  version: 0.0.0\n" + "  title: Simple API\n" + "paths:\n" + "  /:\n" + "    get:\n" + "      responses:\n" + "        '200':\n" + "          description: OK\n" + "          content:\n" + "            '*/*':\n" + "              schema:\n" + "                $ref: '#/components/schemas/Simple'\n" + "components:\n" + "  schemas:\n" + "    Simple:\n" + "      type: string";
    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 74 with Paths

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

the class OpenAPIDeserializerTest method testResponses.

@Test
public void testResponses() {
    String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + "  version: ''\n" + "  title: ''\n" + "paths: {}\n" + "components:\n" + "  responses:\n" + "    foo:\n" + "      description: description\n" + "      bar: baz\n" + "      x-foo: bar";
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    SwaggerParseResult result = parser.readContents(yaml, null, null);
    List<String> messageList = result.getMessages();
    Set<String> messages = new HashSet<>(messageList);
    assertTrue(messages.contains("attribute components.responses.foo.bar is unexpected"));
    assertEquals(result.getOpenAPI().getComponents().getResponses().get("foo").getExtensions().get("x-foo").toString(), "bar");
}
Also used : SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 75 with Paths

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

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