use of io.swagger.v3.oas.annotations.media.ArraySchema in project swagger-parser by swagger-api.
the class V2ConverterTest method testIssue1.
@Test(description = "Missing array item type in parameters")
public void testIssue1() throws Exception {
OpenAPI oas = getConvertedOpenAPIFromJsonFile(PET_STORE_JSON);
Parameter statusParameter = oas.getPaths().get(PET_FIND_BY_STATUS_PATH).getGet().getParameters().get(0);
assertNotNull(statusParameter);
assertTrue(statusParameter.getSchema() instanceof ArraySchema);
ArraySchema arraySchema = (ArraySchema) statusParameter.getSchema();
assertEquals(ARRAY_TYPE, arraySchema.getType());
assertEquals(ENUM_SIZE, arraySchema.getItems().getEnum().size());
}
use of io.swagger.v3.oas.annotations.media.ArraySchema in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method testYamlArrayResponseRemoteRefs.
@Test(description = "resolve array response remote refs in yaml")
public void testYamlArrayResponseRemoteRefs() {
final OpenAPI swagger = new OpenAPI();
swagger.path("/fun", new PathItem().get(new Operation().responses(new ApiResponses().addApiResponse("200", new ApiResponse().content(new Content().addMediaType("*/*", new MediaType().schema(new ArraySchema().items(new Schema().$ref(replacePort(REMOTE_REF_YAML))))))))));
final OpenAPI resolved = new OpenAPIResolver(swagger, null).resolve();
final ApiResponse response = swagger.getPaths().get("/fun").getGet().getResponses().get("200");
final ArraySchema array = (ArraySchema) response.getContent().get("*/*").getSchema();
assertNotNull(array.getItems());
assertEquals(array.getItems().get$ref(), "#/components/schemas/Tag");
assertNotNull(swagger.getComponents().getSchemas().get("Tag"));
}
use of io.swagger.v3.oas.annotations.media.ArraySchema in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method testUpdateInternalReferencesOfExternalFiles.
@Test(description = "update internal references of external files")
public void testUpdateInternalReferencesOfExternalFiles() {
ParseOptions options = new ParseOptions();
options.setResolve(true);
OpenAPI openAPI = new OpenAPIV3Parser().read("internal-references-in-external-files/main.yaml", null, options);
ComposedSchema commonSchema = (ComposedSchema) openAPI.getComponents().getSchemas().get("common");
assertEquals(commonSchema.getAllOf().get(0).get$ref(), "#/components/schemas/core");
assertEquals(((Schema) commonSchema.getAllOf().get(1).getProperties().get("direct")).get$ref(), "#/components/schemas/core");
assertEquals(((ArraySchema) commonSchema.getAllOf().get(1).getProperties().get("referenced")).getItems().get$ref(), "#/components/schemas/core");
Schema coreSchema = openAPI.getComponents().getSchemas().get("core");
assertEquals(((Schema) coreSchema.getProperties().get("inner")).get$ref(), "#/components/schemas/innerCore");
}
use of io.swagger.v3.oas.annotations.media.ArraySchema in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method pathsResolver.
@Test
public void pathsResolver() throws Exception {
final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
String pathFile = FileUtils.readFileToString(new File("src/test/resources/oas3.yaml.template"));
pathFile = pathFile.replace("${dynamicPort}", String.valueOf(this.serverPort));
final JsonNode rootNode = mapper.readTree(pathFile.getBytes());
final OpenAPIDeserializer deserializer = new OpenAPIDeserializer();
final SwaggerParseResult result = deserializer.deserialize(rootNode);
Assert.assertNotNull(result);
final OpenAPI openAPI = result.getOpenAPI();
Assert.assertNotNull(openAPI);
assertEquals(new OpenAPIResolver(openAPI, new ArrayList<>(), null).resolve(), openAPI);
// internal url pathItem
assertEquals(openAPI.getPaths().get("/pathItemRef2"), openAPI.getPaths().get("/pet"));
// internal array schema inside operation -> responses -> content
ArraySchema schema = (ArraySchema) openAPI.getPaths().get("/pet").getPut().getResponses().get("400").getContent().get("application/json").getSchema();
assertEquals(schema.getItems().get$ref(), "#/components/schemas/VeryComplexType");
// replace of parameters in operation and remove the ones from the pathItem
Assert.assertNotNull(openAPI.getPaths().get("/pet").getPost().getParameters());
Assert.assertNull(openAPI.getPaths().get("/pet").getParameters());
// remote ref pathItem
assertEquals(openAPI.getPaths().get("/pathItemRef").getSummary(), "summary");
assertEquals(openAPI.getPaths().get("/pathItemRef").getPost().getResponses().get("405").getDescription(), "Invalid input");
// internal pathItem operation -> response -> schema
Assert.assertNotNull(openAPI.getPaths().get("/pet/{petId}").getGet().getResponses());
assertEquals(openAPI.getPaths().get("/pet/{petId}").getGet().getResponses().get("200").getContent().get("application/xml").getSchema().get$ref(), "#/components/schemas/Pet");
// internal pathItem -> operation -> callback -> pathItem -> operation -> response -> schema
assertEquals(openAPI.getPaths().get("/pet/{petId}").getGet().getCallbacks().get("mainHook").get("$request.body#/url").getPost().getResponses().get("200").getContent().get("application/xml").getSchema().get$ref(), "#/components/schemas/Pet");
// internal pathItem -> operation -> requestBody
Schema id = (Schema) openAPI.getPaths().get("/pet/findByStatus").getGet().getRequestBody().getContent().get("multipart/mixed").getSchema().getProperties().get("id");
assertEquals(id.get$ref(), "#/components/schemas/Pet");
// internal parameter url
assertEquals(openAPI.getPaths().get("/store/inventory").getGet().getParameters().get(0), openAPI.getComponents().getParameters().get("limitParam"));
}
use of io.swagger.v3.oas.annotations.media.ArraySchema in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method testIssue85.
@Test
public void testIssue85(@Injectable final List<AuthorizationValue> auths) {
String yaml = "openapi: '3.0.1'\n" + "paths: \n" + " /test/method: \n" + " post: \n" + " parameters: \n" + " - \n" + " in: \"path\"\n" + " name: \"body\"\n" + " required: false\n" + " schema: \n" + " $ref: '#/components/Schemas/StructureA'\n" + "components: \n" + " schemas:\n" + " StructureA: \n" + " type: object\n" + " properties: \n" + " someProperty: \n" + " type: string\n" + " arrayOfOtherType: \n" + " type: array\n" + " items: \n" + " $ref: '#/definitions/StructureB'\n" + " StructureB: \n" + " type: object\n" + " properties: \n" + " someProperty: \n" + " type: string\n";
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setResolveFully(true);
OpenAPI openAPI = new OpenAPIV3Parser().readContents(yaml, auths, options).getOpenAPI();
ResolverFully resolverUtil = new ResolverFully();
resolverUtil.resolveFully(openAPI);
Parameter param = openAPI.getPaths().get("/test/method").getPost().getParameters().get(0);
Schema schema = param.getSchema();
assertNotNull(schema.getProperties().get("someProperty"));
ArraySchema am = (ArraySchema) schema.getProperties().get("arrayOfOtherType");
assertNotNull(am);
Schema prop = am.getItems();
assertTrue(prop instanceof Schema);
}
Aggregations