Search in sources :

Example 41 with StringSchema

use of io.swagger.v3.oas.models.media.StringSchema in project flow by vaadin.

the class SchemaResolverTest method should_ReturnNullableOptional_When_GivenTypeIsAnOptionalString.

@Test
public void should_ReturnNullableOptional_When_GivenTypeIsAnOptionalString() {
    ResolvedType resolvedType = mockReferencedTypeOf(Optional.class);
    ResolvedReferenceType resolvedReferenceType = resolvedType.asReferenceType();
    List<Pair<ResolvedTypeParameterDeclaration, ResolvedType>> pairs = Collections.singletonList(new Pair<>(null, mockReferencedTypeOf(String.class)));
    when(resolvedReferenceType.getTypeParametersMap()).thenReturn(pairs);
    Map<String, GeneratorType> usedTypes = new HashMap<>();
    SchemaResolver schemaResolver = new SchemaResolver(new GeneratorType(resolvedType), usedTypes);
    Schema schema = schemaResolver.resolve();
    Assert.assertTrue(schema instanceof StringSchema);
    Assert.assertTrue(schema.getNullable());
    Assert.assertTrue(usedTypes.isEmpty());
}
Also used : ResolvedReferenceType(com.github.javaparser.resolution.types.ResolvedReferenceType) HashMap(java.util.HashMap) BooleanSchema(io.swagger.v3.oas.models.media.BooleanSchema) DateSchema(io.swagger.v3.oas.models.media.DateSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) NumberSchema(io.swagger.v3.oas.models.media.NumberSchema) DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) Schema(io.swagger.v3.oas.models.media.Schema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ResolvedType(com.github.javaparser.resolution.types.ResolvedType) Pair(com.github.javaparser.utils.Pair) Test(org.junit.Test)

Example 42 with StringSchema

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

the class OpenAPIResolverTest method testSharedPathParametersTest.

@Test(description = "resolve shared path parameters")
public void testSharedPathParametersTest() {
    final OpenAPI swagger = new OpenAPI();
    Operation operation = new Operation().responses(new ApiResponses().addApiResponse("200", new ApiResponse().description("ok!")));
    PathItem path = new PathItem().get(operation);
    path.addParametersItem(new QueryParameter().name("username").schema(new StringSchema()));
    swagger.path("/fun", path);
    final OpenAPI resolved = new OpenAPIResolver(swagger, null).resolve();
    assertNull(resolved.getPaths().get("/fun").getParameters());
    assertTrue(resolved.getPaths().get("/fun").getGet().getParameters().size() == 1);
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) QueryParameter(io.swagger.v3.oas.models.parameters.QueryParameter) OpenAPIResolver(io.swagger.v3.parser.OpenAPIResolver) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Operation(io.swagger.v3.oas.models.Operation) OpenAPI(io.swagger.v3.oas.models.OpenAPI) ApiResponses(io.swagger.v3.oas.models.responses.ApiResponses) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) Test(org.testng.annotations.Test)

Example 43 with StringSchema

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

the class OpenAPIV3ParserTest method testIssue146.

@Test
public void testIssue146() {
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    final OpenAPI openAPI = parser.read("src/test/resources/issue_146.yaml");
    assertNotNull(openAPI);
    QueryParameter p = ((QueryParameter) openAPI.getPaths().get("/checker").getGet().getParameters().get(0));
    StringSchema pp = (StringSchema) ((ArraySchema) p.getSchema()).getItems();
    assertTrue("registration".equalsIgnoreCase(pp.getEnum().get(0)));
}
Also used : QueryParameter(io.swagger.v3.oas.models.parameters.QueryParameter) StringSchema(io.swagger.v3.oas.models.media.StringSchema) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 44 with StringSchema

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

the class OpenAPIDeserializerTest method propertyTest.

@Test
public void propertyTest(@Injectable List<AuthorizationValue> auths) {
    String yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /primitiveBody/inline:\n" + "    post:\n" + "      x-swagger-router-controller: TestController\n" + "      operationId: inlineRequiredBody\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              type: object\n" + "              properties:\n" + "                name:\n" + "                  type: string\n" + "        required: true\n" + "      responses:\n" + "        '200':\n" + "          description: ok!";
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    SwaggerParseResult result = parser.readContents(yaml, auths, options);
    OpenAPI openAPI = result.getOpenAPI();
    Map<String, Schema> properties = openAPI.getPaths().get("/primitiveBody/inline").getPost().getRequestBody().getContent().get("application/json").getSchema().getProperties();
    assertTrue(properties.get("name") instanceof StringSchema);
}
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) ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) StringSchema(io.swagger.v3.oas.models.media.StringSchema) 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 45 with StringSchema

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

the class OpenAPIDeserializerTest method testArrayQueryParam.

@Test
public void testArrayQueryParam() throws Exception {
    String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "paths:\n" + "  /pet/findByStatus:\n" + "    get:\n" + "      parameters:\n" + "        - name: status\n" + "          in: query\n" + "          description: Status values that need to be considered for filter\n" + "          required: false\n" + "          style: pipeDelimited\n" + "          schema:\n" + "            type: array\n" + "            items:\n" + "              type: string\n" + "            default: available\n" + "      responses:\n" + "        '200':\n" + "          description: successful operation\n" + "          content:\n" + "            '*/*':\n" + "              schema:\n" + "                $ref: #/components/schemas/PetArray\n" + "info:\n" + "  version: ''\n" + "  title: ''";
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    SwaggerParseResult result = parser.readContents(yaml, null, null);
    OpenAPI openAPI = result.getOpenAPI();
    Parameter param = openAPI.getPaths().get("/pet/findByStatus").getGet().getParameters().get(0);
    assertTrue(param instanceof QueryParameter);
    QueryParameter qp = (QueryParameter) param;
    Schema p = qp.getSchema();
    assertEquals(p.getType(), "array");
    assertTrue(((ArraySchema) p).getItems() instanceof StringSchema);
}
Also used : QueryParameter(io.swagger.v3.oas.models.parameters.QueryParameter) ByteArraySchema(io.swagger.v3.oas.models.media.ByteArraySchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) 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) Parameter(io.swagger.v3.oas.models.parameters.Parameter) QueryParameter(io.swagger.v3.oas.models.parameters.QueryParameter) StringSchema(io.swagger.v3.oas.models.media.StringSchema) 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

StringSchema (io.swagger.v3.oas.models.media.StringSchema)88 Test (org.testng.annotations.Test)79 Schema (io.swagger.v3.oas.models.media.Schema)69 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)53 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)52 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)47 OpenAPI (io.swagger.v3.oas.models.OpenAPI)40 PathItem (io.swagger.v3.oas.models.PathItem)22 Operation (io.swagger.v3.oas.models.Operation)21 MediaType (io.swagger.v3.oas.models.media.MediaType)21 Content (io.swagger.v3.oas.models.media.Content)20 DateTimeSchema (io.swagger.v3.oas.models.media.DateTimeSchema)19 MapSchema (io.swagger.v3.oas.models.media.MapSchema)19 NumberSchema (io.swagger.v3.oas.models.media.NumberSchema)19 DateSchema (io.swagger.v3.oas.models.media.DateSchema)17 Components (io.swagger.v3.oas.models.Components)15 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)15 Parameter (io.swagger.v3.oas.models.parameters.Parameter)15 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)15 QueryParameter (io.swagger.v3.oas.models.parameters.QueryParameter)14