use of io.swagger.v3.oas.models.info.Info in project swagger-parser by swagger-api.
the class OpenAPIParserTest method testIssue813.
@Test
public void testIssue813() throws Exception {
String inputSpec = "{\n" + " \"swagger\": \"2.0\",\n" + " \"info\": {\n" + " \"description\": \"This is a sample server Petstore server. You can find out more about Swagger at <a href=\\\"http://swagger.io\\\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \\\"special-key\\\" to test the authorization filters\",\n" + " \"version\": \"1.0.0\",\n" + " \"title\": \"Swagger Petstore\",\n" + " \"termsOfService\": \"http://helloreverb.com/terms/\",\n" + " \"contact\": {\n" + " \"email\": \"apiteam@wordnik.com\"\n" + " },\n" + " \"license\": {\n" + " \"name\": \"Apache-2.0\",\n" + " \"url\": \"http://www.apache.org/licenses/LICENSE-2.0.html\"\n" + " }\n" + " },\n" + " \"host\": \"petstore.swagger.io\",\n" + " \"basePath\": \"/v2\",\n" + " \"schemes\": [\n" + " \"http\"\n" + " ],\n" + " \"paths\": {\n" + " \"/pet\": {\n" + " \"post\": {\n" + " \"tags\": [\n" + " \"pet\"\n" + " ],\n" + " \"summary\": \"Add a new pet to the store\",\n" + " \"description\": \"\",\n" + " \"operationId\": \"addPet\",\n" + " \"consumes\": [\n" + " \"application/json\",\n" + " \"application/xml\"\n" + " ],\n" + " \"produces\": [\n" + " \"application/json\",\n" + " \"application/xml\"\n" + " ],\n" + " \"parameters\": [{\n" + " \"in\": \"body\",\n" + " \"name\": \"body\",\n" + " \"description\": \"Pet object that needs to be added to the store\",\n" + " \"required\": false,\n" + " \"schema\": {\n" + " \"$ref\": \"#/definitions/Pet\"\n" + " }\n" + " }],\n" + " \"responses\": {\n" + " \"405\": {\n" + " \"description\": \"Invalid input\"\n" + " }\n" + " },\n" + " \"security\": [{\n" + " \"petstore_auth\": [\n" + " \"write:pets\",\n" + " \"read:pets\"\n" + " ]\n" + " }]\n" + " },\n" + " \"put\": {\n" + " \"tags\": [\n" + " \"pet\"\n" + " ],\n" + " \"summary\": \"Update an existing pet\",\n" + " \"description\": \"\",\n" + " \"operationId\": \"updatePet\",\n" + " \"consumes\": [\n" + " \"application/json\",\n" + " \"application/xml\"\n" + " ],\n" + " \"produces\": [\n" + " \"application/json\",\n" + " \"application/xml\"\n" + " ],\n" + " \"parameters\": [{\n" + " \"in\": \"body\",\n" + " \"name\": \"body\",\n" + " \"description\": \"Pet object that needs to be added to the store\",\n" + " \"required\": false,\n" + " \"schema\": {\n" + " \"$ref\": \"#/definitions/Pet\"\n" + " }\n" + " }],\n" + " \"responses\": {\n" + " \"405\": {\n" + " \"description\": \"Validation exception\"\n" + " },\n" + " \"404\": {\n" + " \"description\": \"Pet not found\"\n" + " },\n" + " \"400\": {\n" + " \"description\": \"Invalid ID supplied\"\n" + " }\n" + " },\n" + " \"security\": [{\n" + " \"petstore_auth\": [\n" + " \"write:pets\",\n" + " \"read:pets\"\n" + " ]\n" + " }]\n" + " }\n" + " },\n" + " \"securityDefinitions\": {\n" + " \"api_key\": {\n" + " \"type\": \"apiKey\",\n" + " \"name\": \"api_key\",\n" + " \"in\": \"header\"\n" + " },\n" + " \"petstore_auth\": {\n" + " \"type\": \"oauth2\",\n" + " \"authorizationUrl\": \"http://petstore.swagger.io/api/oauth/dialog\",\n" + " \"flow\": \"implicit\",\n" + " \"scopes\": {\n" + " \"write:pets\": \"modify pets in your account\",\n" + " \"read:pets\": \"read your pets\"\n" + " }\n" + " }\n" + " },\n" + " \"definitions\": {\n" + " \"Pet\": {\n" + " \"required\": [\n" + " \"name\",\n" + " \"photoUrls\"\n" + " ],\n" + " \"properties\": {\n" + " \"id\": {\n" + " \"type\": \"integer\",\n" + " \"format\": \"int64\"\n" + " },\n" + " \"category\": {\n" + " \"$ref\": \"#/definitions/Category\"\n" + " },\n" + " \"name\": {\n" + " \"type\": \"string\",\n" + " \"example\": \"doggie\"\n" + " },\n" + " \"photoUrls\": {\n" + " \"type\": \"array\",\n" + " \"xml\": {\n" + " \"name\": \"photoUrl\",\n" + " \"wrapped\": true\n" + " },\n" + " \"items\": {\n" + " \"type\": \"string\"\n" + " }\n" + " },\n" + " \"tags\": {\n" + " \"type\": \"array\",\n" + " \"xml\": {\n" + " \"name\": \"tag\",\n" + " \"wrapped\": true\n" + " },\n" + " \"items\": {\n" + " \"$ref\": \"#/definitions/Tag\"\n" + " }\n" + " },\n" + " \"status\": {\n" + " \"type\": \"string\",\n" + " \"description\": \"pet status in the store\",\n" + " \"enum\": [\n" + " \"available\",\n" + " \"pending\",\n" + " \"sold\"\n" + " ]\n" + " }\n" + " },\n" + " \"xml\": {\n" + " \"name\": \"Pet\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + "}";
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setFlatten(true);
SwaggerParseResult result = new OpenAPIParser().readContents(inputSpec, null, options);
assertTrue(result.getOpenAPI() != null);
}
use of io.swagger.v3.oas.models.info.Info in project swagger-parser by swagger-api.
the class V2ConverterTest method testIssue15.
@Test(description = "Convert extensions everywhere applicable #15")
public void testIssue15() throws Exception {
OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_15_JSON);
assertNotNull(oas);
Info info = oas.getInfo();
assertNotNull(info.getExtensions().get("x-apis-json"));
assertNotNull(info.getLicense().getExtensions().get("x-notes"));
assertNotNull(oas.getExternalDocs().getExtensions().get("x-docs-extension"));
assertNotNull(oas.getTags().get(0).getExtensions().get("x-tag-extension"));
assertNotNull(oas.getTags().get(0).getExternalDocs().getExtensions().get("x-tag-docs-extension"));
PathItem pathItem = oas.getPaths().get("/something");
assertNotNull(pathItem.getExtensions().get("x-path-item-extension"));
Operation get = pathItem.getGet();
assertNotNull(get.getExtensions().get("x-version"));
assertNotNull(get.getExternalDocs().getExtensions().get("x-operation-docs-extension"));
assertNotNull(get.getResponses().get("200").getExtensions().get("x-response-extension"));
ArraySchema schema = (ArraySchema) get.getParameters().get(0).getSchema();
assertNull(schema.getItems().getExtensions().get(X_EXAMPLE));
Map<String, SecurityScheme> securitySchemes = oas.getComponents().getSecuritySchemes();
assertNotNull(securitySchemes);
assertNotNull(securitySchemes.get("OAuth2Implicit").getExtensions().get("x-auth-extension"));
}
use of io.swagger.v3.oas.models.info.Info in project swagger-parser by swagger-api.
the class V2ConverterTest method testIssue755.
@Test(description = "OpenAPI v2 converter - Conversion of a spec without a info section")
public void testIssue755() throws Exception {
final OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_755_YAML);
assertNotNull(oas);
}
use of io.swagger.v3.oas.models.info.Info in project swagger-core by swagger-api.
the class SwaggerSerializerTest method convertSpec.
@Test(description = "it should convert a spec")
public void convertSpec() 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 Map<String, Object> map = new HashMap<String, Object>();
map.put("name", "value");
info.addExtension("x-test2", map);
info.addExtension("x-test", "value");
final OpenAPI swagger = new OpenAPI().info(info).addServersItem(new Server().url("http://petstore.swagger.io")).schema("Person", personModel).schema("Error", errorModel);
final Operation get = new Operation().summary("finds pets in the system").description("a longer description").addTagsItem("Pet Operations").operationId("get pet by id").deprecated(true);
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("application/json", new MediaType().schema(new Schema().$ref("Person")).example("fun")));
final ApiResponse errorResponse = new ApiResponse().description("error response").addLink("myLink", new Link().description("a link").operationId("theLinkedOperationId").addParameter("userId", "gah")).content(new Content().addMediaType("application/json", new MediaType().schema(new Schema().$ref("Error"))));
get.responses(new ApiResponses().addApiResponse("200", response).addApiResponse("default", errorResponse));
final Operation post = new Operation().summary("adds a new pet").description("you can add a new pet this way").addTagsItem("Pet Operations").operationId("add pet").responses(new ApiResponses().addApiResponse("default", errorResponse)).requestBody(new RequestBody().description("the pet to add").content(new Content().addMediaType("*/*", new MediaType().schema(new Schema().$ref("Person")))));
swagger.paths(new Paths().addPathItem("/pets", new PathItem().get(get).post(post)));
final String swaggerJson = Json.mapper().writeValueAsString(swagger);
Json.prettyPrint(swagger);
final OpenAPI rebuilt = Json.mapper().readValue(swaggerJson, OpenAPI.class);
SerializationMatchers.assertEqualsToJson(rebuilt, swaggerJson);
}
use of io.swagger.v3.oas.models.info.Info in project swagger-core by swagger-api.
the class SwaggerSerializerTest method writeSpecWithParameterReferences.
@Test(description = "it should write a spec with parameter references")
public void writeSpecWithParameterReferences() throws IOException {
final Schema personModel = ModelConverters.getInstance().read(Person.class).get("Person");
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 swagger = new OpenAPI().info(info).addServersItem(new Server().url("http://petstore.swagger.io")).schema("Person", personModel);
final QueryParameter parameter = (QueryParameter) new QueryParameter().name("id").description("a common get parameter").schema(new IntegerSchema());
final Operation get = new Operation().summary("finds pets in the system").description("a longer description").operationId("get pet by id").addParametersItem(new Parameter().$ref("#/parameters/Foo"));
swagger.components(new Components().addParameters("Foo", parameter)).path("/pets", new PathItem().get(get));
final String swaggerJson = Json.mapper().writeValueAsString(swagger);
final OpenAPI rebuilt = Json.mapper().readValue(swaggerJson, OpenAPI.class);
assertEquals(Json.pretty(rebuilt), Json.pretty(swagger));
}
Aggregations