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());
}
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);
}
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)));
}
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);
}
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);
}
Aggregations