Search in sources :

Example 21 with Info

use of io.swagger.v3.oas.models.info.Info 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 22 with Info

use of io.swagger.v3.oas.models.info.Info 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 23 with Info

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

the class OpenAPIDeserializerTest method testStyleInvalid.

@Test
public void testStyleInvalid() {
    String json = "{" + "    \"openapi\": \"3.0.0\"," + "    \"info\": {" + "        \"title\": \"realize\"," + "        \"version\": \"0.0.0\"" + "    }," + "    \"paths\": {" + "        \"/realize/{param}\": {" + "            \"post\": {" + "                \"parameters\": [" + "                    {" + "                        \"name\": \"param\"," + "                        \"in\": \"path\"," + "" + "                        \"style\": \"DERP\"," + "                        \"required\": true," + "" + "                        \"schema\": {" + "                            \"type\": \"string\"," + "                            \"nullable\": false," + "                            \"minLength\": 1" + "                        }" + "                    }" + "                ]," + "                \"responses\": {" + "                    \"200\": {" + "                        \"description\": \"Success\"," + "                        \"content\": {" + "                            \"application/json\": {" + "                                \"schema\": {" + "                                    \"type\": \"object\"" + "                                }" + "                            }" + "                        }" + "                    }" + "                }" + "            }" + "        }" + "    }" + "}";
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    SwaggerParseResult result = parser.readContents(json, null, null);
    assertTrue(result.getMessages().size() == 1);
    assertEquals(result.getMessages().get(0), "attribute paths.'/realize/{param}'(post).parameters.[param].style is not of type `StyleEnum`");
}
Also used : SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) Test(org.testng.annotations.Test)

Example 24 with Info

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

the class OpenAPIDeserializerTest method testBodyContent.

@Test
public void testBodyContent() {
    String json = "{" + "  \"openapi\": \"3.0.0\"," + "  \"info\": {" + "    \"title\": \"Operations\"," + "    \"version\": \"0.0.0\"" + "  }," + "  \"paths\": {" + "    \"/operations\": {" + "      \"post\": {" + "        \"requestBody\": {" + "            \"description\": \"Content empty\"," + "            \"content\": {" + "            }" + "        }," + "        \"responses\": {" + "          \"default\": {" + "            \"description\": \"None\"" + "          }" + "        }" + "      }," + "      \"put\": {" + "        \"requestBody\": {" + "            \"description\": \"Content undefined\"" + "        }," + "        \"responses\": {" + "          \"default\": {" + "            \"description\": \"None\"" + "          }" + "        }" + "      }" + "    }" + "  }" + "}";
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    SwaggerParseResult result = parser.readContents(json, null, null);
    Operation post = result.getOpenAPI().getPaths().get("/operations").getPost();
    assertEquals(post.getRequestBody().getContent(), null, "Empty content");
    assertEquals(result.getMessages().contains("attribute paths.'/operations'(post).requestBody.content with no media type is unsupported"), true, "Empty content error reported");
    Operation put = result.getOpenAPI().getPaths().get("/operations").getPut();
    assertEquals(put.getRequestBody().getContent(), null, "Empty content");
    assertEquals(result.getMessages().contains("attribute paths.'/operations'(put).requestBody.content is missing"), true, "Missing content error reported");
    assertEquals(result.getMessages().size(), 2, "Messages");
}
Also used : SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) Operation(io.swagger.v3.oas.models.Operation) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) Test(org.testng.annotations.Test)

Example 25 with Info

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

the class OpenAPIDeserializerTest method testIssue386.

@Test
public void testIssue386() {
    String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + "  description: bleh\n" + "  version: 2.0.0\n" + "  title: Test\n" + "paths:\n" + "  /foo:\n" + "    post:\n" + "      responses:\n" + "        '200':\n" + "          description: OK\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              type: object\n" + "              enum:\n" + "                - id: fun\n" + "              properties:\n" + "                id:\n" + "                  type: string\n" + "components:\n" + "  schemas:\n" + "    Fun:\n" + "      type: object\n" + "      properties:\n" + "        complex:\n" + "          enum:\n" + "            - id: 110\n" + "          type: object\n" + "          properties:\n" + "            id:\n" + "              type: string\n" + "    MyEnum:\n" + "      type: integer\n" + "      enum:\n" + "        - value: 3\n" + "          description: Value 1\n" + "        - value: 10\n" + "          description: Value 2";
    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)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