Search in sources :

Example 56 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 57 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 58 with StringSchema

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

the class SchemaResolverTest method should_ReturnNullableArray_When_GivenTypeIsAListString.

@Test
public void should_ReturnNullableArray_When_GivenTypeIsAListString() {
    ResolvedType resolvedType = mockReferencedTypeOf(Collection.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 ArraySchema);
    Assert.assertTrue(schema.getNullable());
    Assert.assertTrue(((ArraySchema) schema).getItems() instanceof StringSchema);
    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) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) 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 59 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 60 with StringSchema

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

the class SchemaResolver method createEnumTypeSchema.

private Schema createEnumTypeSchema() {
    ResolvedReferenceType resolvedReferenceType = type.asResolvedType().asReferenceType();
    List<String> entries = resolvedReferenceType.getTypeDeclaration().orElseThrow(IllegalArgumentException::new).asEnum().getEnumConstants().stream().map(ResolvedEnumConstantDeclaration::getName).collect(Collectors.toList());
    String qualifiedName = resolvedReferenceType.getQualifiedName();
    usedTypes.put(qualifiedName, type);
    StringSchema schema = new StringSchema();
    schema.name(qualifiedName);
    schema.setEnum(entries);
    schema.$ref(getFullQualifiedNameRef(qualifiedName));
    return schema;
}
Also used : ResolvedReferenceType(com.github.javaparser.resolution.types.ResolvedReferenceType) StringSchema(io.swagger.v3.oas.models.media.StringSchema)

Aggregations

StringSchema (io.swagger.v3.oas.models.media.StringSchema)89 Test (org.testng.annotations.Test)79 Schema (io.swagger.v3.oas.models.media.Schema)70 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)54 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)53 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 MapSchema (io.swagger.v3.oas.models.media.MapSchema)20 NumberSchema (io.swagger.v3.oas.models.media.NumberSchema)20 DateTimeSchema (io.swagger.v3.oas.models.media.DateTimeSchema)19 DateSchema (io.swagger.v3.oas.models.media.DateSchema)17 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)16 Components (io.swagger.v3.oas.models.Components)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