use of io.swagger.v3.oas.models.PathItem in project swagger-core by swagger-api.
the class Ticket2926Test method testExtensionsInMapDeserializeAndSerialize.
@Test
public void testExtensionsInMapDeserializeAndSerialize() throws Exception {
String yaml = "openapi: 3.0.1\n" + "info:\n" + " title: My title\n" + " description: API under test\n" + " version: 1.0.7\n" + " x-info: test\n" + "servers:\n" + "- url: http://localhost:9999/api\n" + " x-server: test\n" + " description: desc\n" + " variables: \n" + " serVar: \n" + " description: desc\n" + " x-serverVariable: test\n" + "paths:\n" + " /foo/bar:\n" + " get:\n" + " callbacks:\n" + " /foo/bar:\n" + " get:\n" + " description: getoperation\n" + " x-callback: test\n" + " responses:\n" + " default:\n" + " description: it works!\n" + " content:\n" + " application/json:\n" + " schema:\n" + " title: inline_response_200\n" + " type: object\n" + " properties:\n" + " name:\n" + " type: string\n" + " x-mediatype: test\n" + " x-response: test\n" + " x-responses: test\n" + " x-responses-object: \n" + " aaa: bbb\n" + " x-responses-array: \n" + " - aaa\n" + " - bbb\n" + " x-operation: test\n" + " x-pathitem: test\n" + " x-paths: test\n" + "x-openapi-object: \n" + " aaa: bbb\n" + "x-openapi-array: \n" + " - aaa\n" + " - bbb\n" + "x-openapi: test";
OpenAPI aa = Yaml.mapper().readValue(yaml, OpenAPI.class);
SerializationMatchers.assertEqualsToYaml(aa, yaml);
}
use of io.swagger.v3.oas.models.PathItem in project swagger-core by swagger-api.
the class SpecFilter method removeBrokenReferenceDefinitions.
protected OpenAPI removeBrokenReferenceDefinitions(OpenAPI openApi) {
if (openApi == null || openApi.getComponents() == null || openApi.getComponents().getSchemas() == null) {
return openApi;
}
Set<String> referencedDefinitions = new TreeSet<>();
if (openApi.getPaths() != null) {
for (String resourcePath : openApi.getPaths().keySet()) {
PathItem pathItem = openApi.getPaths().get(resourcePath);
addPathItemSchemaRef(pathItem, referencedDefinitions);
}
}
referencedDefinitions.addAll(resolveAllNestedRefs(referencedDefinitions, referencedDefinitions, openApi));
openApi.getComponents().getSchemas().keySet().retainAll(referencedDefinitions.stream().map(s -> (String) RefUtils.extractSimpleName(s).getLeft()).collect(Collectors.toSet()));
return openApi;
}
use of io.swagger.v3.oas.models.PathItem in project swagger-core by swagger-api.
the class OpenAPI3_1SerializationTest method testPathItemsRefSerialization.
@Test
public void testPathItemsRefSerialization() {
OpenAPI openAPI = new OpenAPI().openapi("3.1.0").path("/pathTest", new PathItem().$ref("#/components/pathItems/pathTest").description("This is a ref path item").summary("ref path item")).components(new Components().addPathItem("pathTest", new PathItem().description("test path item").get(new Operation().operationId("testPathItem").responses(new ApiResponses().addApiResponse("200", new ApiResponse().description("response description"))))));
SerializationMatchers.assertEqualsToYaml31(openAPI, "openapi: 3.1.0\n" + "paths:\n" + " /pathTest:\n" + " $ref: '#/components/pathItems/pathTest'\n" + " description: This is a ref path item\n" + " summary: ref path item\n" + "components:\n" + " pathItems:\n" + " pathTest:\n" + " description: test path item\n" + " get:\n" + " operationId: testPathItem\n" + " responses:\n" + " \"200\":\n" + " description: response description");
SerializationMatchers.assertEqualsToJson31(openAPI, "{\n" + " \"openapi\" : \"3.1.0\",\n" + " \"paths\" : {\n" + " \"/pathTest\" : {\n" + " \"summary\" : \"ref path item\",\n" + " \"description\" : \"This is a ref path item\",\n" + " \"$ref\" : \"#/components/pathItems/pathTest\"\n" + " }\n" + " },\n" + " \"components\" : {\n" + " \"pathItems\" : {\n" + " \"pathTest\" : {\n" + " \"description\" : \"test path item\",\n" + " \"get\" : {\n" + " \"operationId\" : \"testPathItem\",\n" + " \"responses\" : {\n" + " \"200\" : {\n" + " \"description\" : \"response description\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + "}");
}
use of io.swagger.v3.oas.models.PathItem in project swagger-core by swagger-api.
the class SecurityDefinitionTest method createModelWithSecurityRequirements.
@Test(description = "it should create a model with security requirements")
public void createModelWithSecurityRequirements() throws IOException {
final Schema personModel = ModelConverters.getInstance().read(Person.class).get("Person");
final Schema errorModel = ModelConverters.getInstance().read(Error.class).get("Error");
final Info info = new Info().version("1.0.0").title("Swagger Petstore");
final Contact contact = new Contact().name("Swagger API Team").email("foo@bar.baz").url("http://swagger.io");
info.setContact(contact);
final OpenAPI oas = new OpenAPI().info(info).addServersItem(new Server().url("http://petstore.swagger.io")).schema("Person", personModel).schema("Error", errorModel);
oas.schemaRequirement("githubAccessCode", new SecurityScheme().flows(new OAuthFlows().authorizationCode(new OAuthFlow().scopes(new Scopes().addString("user:email", "Grants read access to a user’s email addresses.")))));
final Operation get = new Operation().summary("finds pets in the system").description("a longer description").addTagsItem("Pet Operations").operationId("get pet by id");
get.addParametersItem(new Parameter().in("query").name("tags").description("tags to filter by").required(false).schema(new StringSchema()));
get.addParametersItem(new Parameter().in("path").name("petId").description("pet to fetch").schema(new IntegerSchema().format("int64")));
final ApiResponse response = new ApiResponse().description("pets returned").content(new Content().addMediaType("*/*", new MediaType().schema(new Schema().$ref("Person"))));
final ApiResponse errorResponse = new ApiResponse().description("error response").content(new Content().addMediaType("*/*", new MediaType().schema(new Schema().$ref("Error"))));
get.responses(new ApiResponses().addApiResponse("200", response).addApiResponse("default", errorResponse)).addSecurityItem(new SecurityRequirement().addList("internal_oauth2", "user:email")).addSecurityItem(new SecurityRequirement().addList("api_key"));
oas.path("/pets", new PathItem().get(get));
final String json = ResourceUtils.loadClassResource(getClass(), "ModelWithSecurityRequirements.json");
SerializationMatchers.assertEqualsToJson(oas, json);
}
use of io.swagger.v3.oas.models.PathItem in project swagger-core by swagger-api.
the class OpenAPI3_1SerializationTest method testRequestBodyRefSerialization.
@Test
public void testRequestBodyRefSerialization() {
OpenAPI openAPI = new OpenAPI().openapi("3.1.0").path("/test", new PathItem().description("test path item").post(new Operation().operationId("testPathItem").requestBody(new RequestBody().$ref("#/components/requestBodies/body").description("ref request body")))).components(new Components().addRequestBodies("body", new RequestBody().content(new Content().addMediaType("application/json", new MediaType().schema(new ObjectSchema())))));
SerializationMatchers.assertEqualsToYaml31(openAPI, "openapi: 3.1.0\n" + "paths:\n" + " /test:\n" + " description: test path item\n" + " post:\n" + " operationId: testPathItem\n" + " requestBody:\n" + " description: ref request body\n" + " $ref: '#/components/requestBodies/body'\n" + "components:\n" + " requestBodies:\n" + " body:\n" + " content:\n" + " application/json:\n" + " schema: {}");
SerializationMatchers.assertEqualsToJson31(openAPI, "{\n" + " \"openapi\" : \"3.1.0\",\n" + " \"paths\" : {\n" + " \"/test\" : {\n" + " \"description\" : \"test path item\",\n" + " \"post\" : {\n" + " \"operationId\" : \"testPathItem\",\n" + " \"requestBody\" : {\n" + " \"description\" : \"ref request body\",\n" + " \"$ref\" : \"#/components/requestBodies/body\"\n" + " }\n" + " }\n" + " }\n" + " },\n" + " \"components\" : {\n" + " \"requestBodies\" : {\n" + " \"body\" : {\n" + " \"content\" : {\n" + " \"application/json\" : {\n" + " \"schema\" : { }\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + "}");
}
Aggregations