Search in sources :

Example 1 with Info

use of io.swagger.models.Info in project java-chassis by ServiceComb.

the class TestDefinition method testMicroserviceMetaManager.

@Test
public void testMicroserviceMetaManager() throws Exception {
    MicroserviceMetaManager microserviceMetaManager = new MicroserviceMetaManager();
    microserviceMetaManager.getOrCreateMicroserviceMeta("testname");
    Assert.assertEquals("microservice meta manager", microserviceMetaManager.getName());
    Assert.assertEquals("Not allow regsiter repeat data, name=%s, key=%s", microserviceMetaManager.getRegisterErrorFmt());
    Assert.assertEquals(0, microserviceMetaManager.getAllSchemaMeta("testname").size());
    Swagger oSwagger = new Swagger();
    Info oInfo = new Info();
    oInfo.setVendorExtension("x-java-interface", "java.lang.String");
    oSwagger.setInfo(oInfo);
    Assert.assertEquals("java.lang.String", (ClassUtils.getJavaInterface(oSwagger)).getName());
    oInfo.setVendorExtension("x-java-class", "java.lang.String");
}
Also used : MicroserviceMetaManager(io.servicecomb.core.definition.MicroserviceMetaManager) Swagger(io.swagger.models.Swagger) Info(io.swagger.models.Info) Test(org.junit.Test)

Example 2 with Info

use of io.swagger.models.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 Model personModel = ModelConverters.getInstance().read(Person.class).get("Person");
    final Model 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.setVendorExtension("x-test2", map);
    info.setVendorExtension("x-test", "value");
    final Swagger swagger = new Swagger().info(info).host("petstore.swagger.io").securityDefinition("api-key", new ApiKeyAuthDefinition("key", In.HEADER)).scheme(Scheme.HTTP).consumes("application/json").produces("application/json").model("Person", personModel).model("Error", errorModel);
    final Operation get = new Operation().produces("application/json").summary("finds pets in the system").description("a longer description").tag("Pet Operations").operationId("get pet by id").deprecated(true);
    get.parameter(new QueryParameter().name("tags").description("tags to filter by").required(false).property(new StringProperty()));
    get.parameter(new PathParameter().name("petId").description("pet to fetch").property(new LongProperty()));
    final Response response = new Response().description("pets returned").schema(new RefProperty().asDefault("Person")).example("application/json", "fun!");
    final Response errorResponse = new Response().description("error response").schema(new RefProperty().asDefault("Error"));
    get.response(200, response).defaultResponse(errorResponse);
    final Operation post = new Operation().summary("adds a new pet").description("you can add a new pet this way").tag("Pet Operations").operationId("add pet").defaultResponse(errorResponse).parameter(new BodyParameter().description("the pet to add").schema(new RefModel().asDefault("Person")));
    swagger.path("/pets", new Path().get(get).post(post));
    final String swaggerJson = Json.mapper().writeValueAsString(swagger);
    final Swagger rebuilt = Json.mapper().readValue(swaggerJson, Swagger.class);
    SerializationMatchers.assertEqualsToJson(rebuilt, swaggerJson);
}
Also used : Path(io.swagger.models.Path) QueryParameter(io.swagger.models.parameters.QueryParameter) RefModel(io.swagger.models.RefModel) HashMap(java.util.HashMap) Error(io.swagger.models.Error) StringProperty(io.swagger.models.properties.StringProperty) Operation(io.swagger.models.Operation) Info(io.swagger.models.Info) BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) Contact(io.swagger.models.Contact) RefProperty(io.swagger.models.properties.RefProperty) Response(io.swagger.models.Response) ApiKeyAuthDefinition(io.swagger.models.auth.ApiKeyAuthDefinition) Swagger(io.swagger.models.Swagger) LongProperty(io.swagger.models.properties.LongProperty) Model(io.swagger.models.Model) RefModel(io.swagger.models.RefModel) Person(io.swagger.models.Person) Test(org.testng.annotations.Test)

Example 3 with Info

use of io.swagger.models.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 Model 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 Swagger swagger = new Swagger().info(info).host("petstore.swagger.io").securityDefinition("api-key", new ApiKeyAuthDefinition("key", In.HEADER)).scheme(Scheme.HTTP).consumes("application/json").produces("application/json").model("Person", personModel);
    final QueryParameter parameter = new QueryParameter().name("id").description("a common get parameter").property(new LongProperty());
    final Operation get = new Operation().produces("application/json").summary("finds pets in the system").description("a longer description").tag("Pet Operations").operationId("get pet by id").parameter(new RefParameter("foo"));
    swagger.parameter("foo", parameter).path("/pets", new Path().get(get));
    final String swaggerJson = Json.mapper().writeValueAsString(swagger);
    final Swagger rebuilt = Json.mapper().readValue(swaggerJson, Swagger.class);
    assertEquals(Json.pretty(swagger), Json.pretty(rebuilt));
}
Also used : Path(io.swagger.models.Path) ApiKeyAuthDefinition(io.swagger.models.auth.ApiKeyAuthDefinition) QueryParameter(io.swagger.models.parameters.QueryParameter) RefParameter(io.swagger.models.parameters.RefParameter) Swagger(io.swagger.models.Swagger) LongProperty(io.swagger.models.properties.LongProperty) Model(io.swagger.models.Model) RefModel(io.swagger.models.RefModel) Operation(io.swagger.models.Operation) Info(io.swagger.models.Info) Person(io.swagger.models.Person) Contact(io.swagger.models.Contact) Test(org.testng.annotations.Test)

Example 4 with Info

use of io.swagger.models.Info in project swagger-core by swagger-api.

the class ReaderTest method readerTest1.

@Test
public void readerTest1() {
    final Swagger swagger = new Swagger();
    Reader.read(swagger, Collections.<Class<?>>singleton(ResourceWithAnnotations.class));
    Assert.assertNotNull(swagger);
    final Info info = swagger.getInfo();
    Assert.assertNotNull(info);
    Assert.assertEquals(info.getTitle(), "Test title");
    Assert.assertEquals(info.getDescription(), "Test description");
    Assert.assertEquals(info.getVersion(), "1.0.0");
    Assert.assertEquals(info.getTermsOfService(), "link_to_terms");
    Assert.assertEquals(info.getContact().getName(), "Author");
    Assert.assertEquals(info.getContact().getEmail(), "author@mail");
    Assert.assertEquals(info.getContact().getUrl(), "site");
    Assert.assertEquals(info.getLicense().getName(), "License");
    Assert.assertEquals(info.getLicense().getUrl(), "license_url");
    Assert.assertEquals(info.getVendorExtensions().get("x-ext1_prop1"), "ext1_val1");
    Assert.assertEquals(info.getVendorExtensions().get("x-ext1_prop2"), "x-ext1_val2");
    Assert.assertEquals(swagger.getHost(), "host");
    Assert.assertEquals(swagger.getBasePath(), "/api");
    Assert.assertNotNull(swagger.getPath("/resources/testMethod3"));
    Assert.assertNotNull(swagger.getDefinitions().get("SampleData"));
    Assert.assertEquals(swagger.getExternalDocs().getDescription(), "docs");
    Assert.assertEquals(swagger.getExternalDocs().getUrl(), "url_to_docs");
    Path path = swagger.getPath("/resources/testMethod3");
    Assert.assertNotNull(path);
    Operation get = path.getGet();
    Assert.assertNotNull(get);
    Assert.assertEquals("value", get.getVendorExtensions().get("x-name"));
}
Also used : Path(io.swagger.models.Path) ResourceWithAnnotations(io.swagger.servlet.resources.ResourceWithAnnotations) Swagger(io.swagger.models.Swagger) Operation(io.swagger.models.Operation) Info(io.swagger.models.Info) Test(org.testng.annotations.Test)

Example 5 with Info

use of io.swagger.models.Info in project swagger-core by swagger-api.

the class BeanConfig method updateInfoFromConfig.

private void updateInfoFromConfig() {
    info = getSwagger().getInfo();
    if (info == null) {
        info = new Info();
    }
    if (StringUtils.isNotBlank(description)) {
        info.description(description);
    }
    if (StringUtils.isNotBlank(title)) {
        info.title(title);
    }
    if (StringUtils.isNotBlank(version)) {
        info.version(version);
    }
    if (StringUtils.isNotBlank(termsOfServiceUrl)) {
        info.termsOfService(termsOfServiceUrl);
    }
    if (contact != null) {
        this.info.contact(new Contact().name(contact));
    }
    if (license != null && licenseUrl != null) {
        this.info.license(new License().name(license).url(licenseUrl));
    }
    if (schemes != null) {
        for (String scheme : schemes) {
            reader.getSwagger().scheme(Scheme.forValue(scheme));
        }
    }
    reader.getSwagger().setInfo(info);
}
Also used : License(io.swagger.models.License) Info(io.swagger.models.Info) Contact(io.swagger.models.Contact)

Aggregations

Info (io.swagger.models.Info)43 Swagger (io.swagger.models.Swagger)30 Contact (io.swagger.models.Contact)14 Operation (io.swagger.models.Operation)11 Path (io.swagger.models.Path)10 License (io.swagger.models.License)8 QueryParameter (io.swagger.models.parameters.QueryParameter)8 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 Test (org.testng.annotations.Test)8 ApiKeyAuthDefinition (io.swagger.models.auth.ApiKeyAuthDefinition)5 BodyParameter (io.swagger.models.parameters.BodyParameter)5 PathParameter (io.swagger.models.parameters.PathParameter)5 Model (io.swagger.models.Model)4 RefModel (io.swagger.models.RefModel)4 Response (io.swagger.models.Response)4 OAuth2Definition (io.swagger.models.auth.OAuth2Definition)4 Parameter (io.swagger.models.parameters.Parameter)4 RefProperty (io.swagger.models.properties.RefProperty)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4