io.swagger.v3.oas.models.info.License Java Examples

The following examples show how to use io.swagger.v3.oas.models.info.License. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OpenApiFeature.java    From cxf with Apache License 2.0 7 votes vote down vote up
/**
 * The info will be used only if there is no @OpenAPIDefinition annotation is present.
 */
private Info getInfo(final Properties properties) {
    final Info info = new Info()
            .title(getOrFallback(getTitle(), properties, TITLE_PROPERTY))
            .version(getOrFallback(getVersion(), properties, VERSION_PROPERTY))
            .description(getOrFallback(getDescription(), properties, DESCRIPTION_PROPERTY))
            .termsOfService(getOrFallback(getTermsOfServiceUrl(), properties, TERMS_URL_PROPERTY))
            .contact(new Contact()
                    .name(getOrFallback(getContactName(), properties, CONTACT_PROPERTY))
                    .email(getContactEmail())
                    .url(getContactUrl()))
            .license(new License()
                    .name(getOrFallback(getLicense(), properties, LICENSE_PROPERTY))
                    .url(getOrFallback(getLicenseUrl(), properties, LICENSE_URL_PROPERTY)));

    if (info.getLicense().getName() == null) {
        info.getLicense().setName(DEFAULT_LICENSE_VALUE);
    }

    if (info.getLicense().getUrl() == null && DEFAULT_LICENSE_VALUE.equals(info.getLicense().getName())) {
        info.getLicense().setUrl(DEFAULT_LICENSE_URL);
    }

    return info;
}
 
Example #2
Source File: OverviewDocument.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
private void appendLicenseInfo(Section overviewDoc, Info info) {
    License license = info.getLicense();
    if (null != license) {
        StringBuilder sb = new StringBuilder();
        if (StringUtils.isNotBlank(license.getUrl())) {
            sb.append(license.getUrl()).append("[");
        }
        sb.append(license.getName());
        if (StringUtils.isNotBlank(license.getUrl())) {
            sb.append("]");
        }
        BlockImpl paragraph = new ParagraphBlockImpl(overviewDoc);
        paragraph.setSource(sb.toString());
        overviewDoc.append(paragraph);
    }
}
 
Example #3
Source File: BeaconRestApi.java    From teku with Apache License 2.0 6 votes vote down vote up
private static OpenApiOptions getOpenApiOptions(
    final JsonProvider jsonProvider, final TekuConfiguration config) {
  final JacksonModelConverterFactory factory =
      new JacksonModelConverterFactory(jsonProvider.getObjectMapper());

  final Info applicationInfo =
      new Info()
          .title(StringUtils.capitalize(VersionProvider.CLIENT_IDENTITY))
          .version(VersionProvider.IMPLEMENTATION_VERSION)
          .description(
              "A minimal API specification for the beacon node, which enables a validator "
                  + "to connect and perform its obligations on the Ethereum 2.0 phase 0 beacon chain.")
          .license(
              new License()
                  .name("Apache 2.0")
                  .url("https://www.apache.org/licenses/LICENSE-2.0.html"));
  final OpenApiOptions options =
      new OpenApiOptions(applicationInfo).modelConverterFactory(factory);
  if (config.isRestApiDocsEnabled()) {
    options.path("/swagger-docs").swagger(new SwaggerOptions("/swagger-ui"));
  }
  return options;
}
 
Example #4
Source File: OpenAPIBuilder.java    From springdoc-openapi with Apache License 2.0 6 votes vote down vote up
/**
 * Resolve properties info.
 *
 * @param info the info
 * @return the info
 */
private Info resolveProperties(Info info) {
	PropertyResolverUtils propertyResolverUtils = context.getBean(PropertyResolverUtils.class);
	resolveProperty(info::getTitle, info::title, propertyResolverUtils);
	resolveProperty(info::getDescription, info::description, propertyResolverUtils);
	resolveProperty(info::getVersion, info::version, propertyResolverUtils);
	resolveProperty(info::getTermsOfService, info::termsOfService, propertyResolverUtils);

	License license = info.getLicense();
	if (license != null) {
		resolveProperty(license::getName, license::name, propertyResolverUtils);
		resolveProperty(license::getUrl, license::url, propertyResolverUtils);
	}

	Contact contact = info.getContact();
	if (contact != null) {
		resolveProperty(contact::getName, contact::name, propertyResolverUtils);
		resolveProperty(contact::getEmail, contact::email, propertyResolverUtils);
		resolveProperty(contact::getUrl, contact::url, propertyResolverUtils);
	}
	return info;
}
 
Example #5
Source File: SpringDocTestApp.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@Bean
public OpenAPI customOpenAPI() {
	return new OpenAPI()
			.components(new Components().addSecuritySchemes("basicScheme",
					new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic")))
			.info(new Info().title("Tweet API").version("v0")
					.license(new License().name("Apache 2.0").url("http://springdoc.org")));
}
 
Example #6
Source File: MCRRestV2App.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
private void setupOAS() {
    OpenAPI oas = new OpenAPI();
    Info oasInfo = new Info();
    oas.setInfo(oasInfo);
    oasInfo.setVersion(MCRCoreVersion.getVersion());
    oasInfo.setTitle(getApplicationName());
    License oasLicense = new License();
    oasLicense.setName("GNU General Public License, version 3");
    oasLicense.setUrl("http://www.gnu.org/licenses/gpl-3.0.txt");
    oasInfo.setLicense(oasLicense);
    URI baseURI = URI.create(MCRFrontendUtil.getBaseURL());
    Server oasServer = new Server();
    oasServer.setUrl(baseURI.resolve("api").toString());
    oas.addServersItem(oasServer);
    SwaggerConfiguration oasConfig = new SwaggerConfiguration()
        .openAPI(oas)
        .resourcePackages(Stream.of(getRestPackages()).collect(Collectors.toSet()))
        .ignoredRoutes(
            MCRConfiguration2.getString("MCR.RestAPI.V2.OpenAPI.IgnoredRoutes")
                .map(MCRConfiguration2::splitValue)
                .orElseGet(Stream::empty)
                .collect(Collectors.toSet()))
        .prettyPrint(true);
    try {
        new JaxrsOpenApiContextBuilder()
            .application(getApplication())
            .openApiConfiguration(oasConfig)
            .buildContext(true);
    } catch (OpenApiConfigurationException e) {
        throw new InternalServerErrorException(e);
    }
}
 
Example #7
Source File: SwaggerLicense.java    From swagger-maven-plugin with MIT License 5 votes vote down vote up
public License createLicenseModel() {
    License license = new License();

    if (name != null) {
        license.setName(name);
    }

    if (url != null) {
        license.setUrl(url);
    }

    return license;
}
 
Example #8
Source File: SpringBatchRestCoreAutoConfiguration.java    From spring-batch-rest with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public OpenAPI customOpenAPI() {
    return new OpenAPI()
            .components(new Components())
            .info(new Info()
                    .title("Spring Batch REST")
                    .version(buildProperties == null ? null : String.format("%s  -  Build time %s", buildProperties.getVersion(), buildProperties.getTime()))
                    .description("REST API for controlling and viewing <a href=\"https://spring.io/projects/spring-batch\">" +
                            "Spring Batch</a> jobs and their <a href=\"http://www.quartz-scheduler.org\">Quartz</a> schedules.")
                    .license(new License().name("Apache License 2.0").url("http://github.com/chrisgleissner/spring-batch-rest/blob/master/LICENSE")));
}
 
Example #9
Source File: SwaggerConfig.java    From POC with Apache License 2.0 5 votes vote down vote up
@Bean
public OpenAPI springShopOpenAPI() {
	return new OpenAPI()
			.info(new Info().title("SpringShop API").description("Spring shop sample application").version("v0.0.1")
					.license(new License().name("Apache 2.0").url("http://springdoc.org")))
			.externalDocs(new ExternalDocumentation().description("SpringShop Wiki Documentation")
					.url("https://springshop.wiki.github.org/docs"));
}
 
Example #10
Source File: SwaggerConverter.java    From swagger-parser with Apache License 2.0 5 votes vote down vote up
private License convert(io.swagger.models.License v2License) {
    if (v2License == null) {
        return null;
    }

    License license = new License();
    license.setExtensions(convert(v2License.getVendorExtensions()));
    license.setName(v2License.getName());
    license.setUrl(v2License.getUrl());

    return license;
}
 
Example #11
Source File: OpenAPIDeserializer.java    From swagger-parser with Apache License 2.0 5 votes vote down vote up
public License getLicense(ObjectNode node, String location, ParseResult result) {
    if (node == null)
        return null;

    License license = new License();

    String value = getString("name", node, true, location, result);
    if(StringUtils.isNotBlank(value)) {
        license.setName(value);
    }

    value = getString("url", node, false, location, result);
    if(StringUtils.isNotBlank(value)) {
        try {
           new URL(value);
        }
        catch (Exception e) {
            result.warning(location,value);
        }
        license.setUrl(value);
    }

    Map <String,Object> extensions = getExtensions(node);
    if(extensions != null && extensions.size() > 0) {
        license.setExtensions(extensions);
    }

    Set<String> keys = getKeys(node);
    for(String key : keys) {
        if(!LICENSE_KEYS.contains(key) && !key.startsWith("x-")) {
            result.extra(location, key, node.get(key));
        }
    }

    return license;
}
 
Example #12
Source File: OpenAPIDeserializerTest.java    From swagger-parser with Apache License 2.0 5 votes vote down vote up
@Test(dataProvider = "data")
public void readInfoObject(JsonNode rootNode) throws Exception {


    final OpenAPIDeserializer deserializer = new OpenAPIDeserializer();
    final SwaggerParseResult result = deserializer.deserialize(rootNode);

    Assert.assertNotNull(result);

    final OpenAPI openAPI = result.getOpenAPI();
    Assert.assertNotNull(openAPI);
    Assert.assertEquals(openAPI.getOpenapi(),"3.0.1");


    final Info info = openAPI.getInfo();
    Assert.assertNotNull(info);
    Assert.assertEquals(info.getTitle(), "Sample Pet Store App");
    Assert.assertEquals(info.getDescription(), "This is a sample server Petstore");
    Assert.assertEquals(info.getTermsOfService(), "http://swagger.io/terms/");
    Assert.assertNotNull(info.getExtensions().get("x-info"));
    Assert.assertEquals(info.getExtensions().get("x-info").toString(),"info extension");

    final Contact contact = info.getContact();
    Assert.assertNotNull(contact);
    Assert.assertEquals(contact.getName(),"API Support");
    Assert.assertEquals(contact.getUrl(),"http://www.example.com/support");
    Assert.assertEquals(contact.getEmail(),"[email protected]");
    Assert.assertNotNull(contact.getExtensions().get("x-contact"));
    Assert.assertEquals(contact.getExtensions().get("x-contact").toString(),"contact extension");

    final License license = info.getLicense();
    Assert.assertNotNull(license);
    Assert.assertEquals(license.getName(), "Apache 2.0");
    Assert.assertEquals(license.getUrl(), "http://www.apache.org/licenses/LICENSE-2.0.html");
    Assert.assertNotNull(license.getExtensions());

    Assert.assertEquals(info.getVersion(), "1.0.1");

}
 
Example #13
Source File: Bootstrap.java    From submarine with Apache License 2.0 5 votes vote down vote up
@Override
public void init(ServletConfig config) throws ServletException {

  OpenAPI oas = new OpenAPI();
  Info info = new Info()
           .title("Submarine Experiment API")
           .description("The Submarine REST API allows you to create, list, and get experiments. The\n" +
                   "API is hosted under the /v1/experiment route on the Submarine server. For example,\n" +
                   "to list experiments on a server hosted at http://localhost:8080, access\n" +
                   "http://localhost:8080/api/v1/experiment/")
           .termsOfService("http://swagger.io/terms/")
           .contact(new Contact()
           .email("[email protected]"))
           .version("0.4.0")
           .license(new License()
           .name("Apache 2.0")
           .url("http://www.apache.org/licenses/LICENSE-2.0.html"));

  oas.info(info);
  List<Server> servers = new ArrayList<>();
  servers.add(new Server().url("/api"));
  oas.servers(servers);
  SwaggerConfiguration oasConfig = new SwaggerConfiguration()
          .openAPI(oas)
          .resourcePackages(Stream.of("org.apache.submarine.server.rest").collect(Collectors.toSet()));

  try {
    new JaxrsOpenApiContextBuilder()
            .servletConfig(config)
            .openApiConfiguration(oasConfig)
            .buildContext(true);
  } catch (OpenApiConfigurationException e) {
    throw new ServletException(e.getMessage(), e);
  }
}
 
Example #14
Source File: SpringDocTestApp.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@Bean
public OpenAPI customOpenAPI() {
	return new OpenAPI()
			.components(new Components().addSecuritySchemes("basicScheme",
					new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic")))
			.info(new Info().title("Tweet API").version("v0")
					.license(new License().name("Apache 2.0").url("http://springdoc.org")));
}
 
Example #15
Source File: SpringDocTestApp.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@Bean
public OpenAPI customOpenAPI() {
	return new OpenAPI()
			.components(new Components().addSecuritySchemes("basicScheme",
					new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic")))
			.info(new Info().title("Tweet API").version("v0")
					.license(new License().name("Apache 2.0").url("http://springdoc.org")));
}
 
Example #16
Source File: SpringDocTestApp.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@Bean
public OpenAPI customOpenAPI() {
	return new OpenAPI()
			.components(new Components().addSecuritySchemes("basicScheme",
					new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic")))
			.info(new Info().title("Tweet API").version("v0")
					.license(new License().name("Apache 2.0").url("http://springdoc.org")));
}
 
Example #17
Source File: SpringDocTestApp.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@Bean
public OpenAPI customOpenAPI() {
	return new OpenAPI()
			.components(new Components().addSecuritySchemes("basicScheme",
					new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic")))
			.info(new Info().title("Tweet API").version("v0")
					.license(new License().name("Apache 2.0").url("http://springdoc.org")));
}
 
Example #18
Source File: SpringDocApp68Test.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@Bean
public OpenAPI customOpenAPI() {
	return new OpenAPI()
			.components(new Components().addSecuritySchemes("basicScheme",
					new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic")))
			.info(new Info().title("Tweet API").version("v0")
					.license(new License().name("Apache 2.0").url("http://springdoc.org")));
}
 
Example #19
Source File: JaxRsActivatorNew.java    From pnc with Apache License 2.0 5 votes vote down vote up
private void configureSwagger() {
    OpenAPI oas = new OpenAPI();
    Info info = new Info().title("PNC")
            .description("PNC build system")
            .termsOfService("http://swagger.io/terms/")
            .license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0.html"));
    oas.info(info);
    oas.addServersItem(new Server().url("/pnc-rest-new"));

    final SecurityScheme authScheme = getAuthScheme();
    if (authScheme == null) {
        logger.warn("Not adding auth scheme to openapi definition as auth scheme could not been generated.");
    } else {
        oas.schemaRequirement(KEYCLOAK_AUTH, authScheme);
        oas.addSecurityItem(new SecurityRequirement().addList(KEYCLOAK_AUTH));
    }

    SwaggerConfiguration oasConfig = new SwaggerConfiguration().openAPI(oas);

    try {
        new JaxrsOpenApiContextBuilder().servletConfig(servletConfig)
                .application(this)
                .openApiConfiguration(oasConfig)
                .buildContext(true);
    } catch (OpenApiConfigurationException ex) {
        throw new IllegalArgumentException("Failed to setup OpenAPI configuration", ex);
    }
}
 
Example #20
Source File: SpringDocApp110Test.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@Bean
public OpenAPI customOpenAPI(@Value("${application-description}") String appDesciption, @Value("${application-version}") String appVersion) {

	return new OpenAPI()
			.info(new Info()
					.title("sample application API")
					.version(appVersion)
					.description(appDesciption)
					.termsOfService("http://swagger.io/terms/")
					.license(new License().name("Apache 2.0").url("http://springdoc.org")));
}
 
Example #21
Source File: SpringDocApp105Test.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@Bean
public OpenAPI customOpenAPI() {
	return new OpenAPI()
			.components(new Components().addSecuritySchemes("basicScheme",
					new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic")))
			.info(new Info().title("Petstore API").version("v0").description(
					"This is a sample server Petstore server.  You can find out more about     Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).      For this sample, you can use the api key `special-key` to test the authorization     filters.")
					.termsOfService("http://swagger.io/terms/")
					.license(new License().name("Apache 2.0").url("http://springdoc.org")));
}
 
Example #22
Source File: SpringDocApp1Test.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@Bean
public OpenAPI customOpenAPI() {
	return new OpenAPI()
			.components(new Components().addSecuritySchemes("basicScheme",
					new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic")))
			.info(new Info().title("SpringShop API").version("v0")
					.license(new License().name("Apache 2.0").url("http://springdoc.org")));
}
 
Example #23
Source File: SpringDocTestApp.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@Bean
public OpenAPI customOpenAPI() {
	return new OpenAPI()
			.components(new Components()
					.addSecuritySchemes("basicScheme",
							new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic"))
					.addParameters("myHeader1",
							new Parameter().in("header").schema(new StringSchema()).name("myHeader1"))
					.addHeaders("myHeader2",
							new Header().description("myHeader2 header").schema(new StringSchema())))
			.info(new Info().title("Petstore API").version("v0").description(
					"This is a sample server Petstore server.  You can find out more about     Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).      For this sample, you can use the api key `special-key` to test the authorization     filters.")
					.termsOfService("http://swagger.io/terms/")
					.license(new License().name("Apache 2.0").url("http://springdoc.org")));
}
 
Example #24
Source File: SpringDocApp112Test.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@Bean
public OpenAPI customOpenAPI(@Value("${application-description}") String appDesciption, @Value("${application-version}") String appVersion) {
	return new OpenAPI()
			.info(new Info()
					.title("sample application API")
					.version(appVersion)
					.description(appDesciption)
					.termsOfService("http://swagger.io/terms/")
					.license(new License().name("Apache 2.0").url("http://springdoc.org")));
}
 
Example #25
Source File: SpringDocApp111Test.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@Bean
public OpenAPI customOpenAPI(@Value("${application-description}") String appDesciption, @Value("${application-version}") String appVersion) {
	return new OpenAPI()
			.info(new Info()
					.title("sample application API")
					.version(appVersion)
					.description(appDesciption)
					.termsOfService("http://swagger.io/terms/")
					.license(new License().name("Apache 2.0").url("http://springdoc.org")));
}
 
Example #26
Source File: SpringDocApp2Test.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@Bean
public OpenAPI customOpenAPI() {
	return new OpenAPI()
			.components(new Components().addSecuritySchemes("basicScheme",
					new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic")))
			.info(new Info().title("Petstore API").version("v0").description(
					"This is a sample server Petstore server.  You can find out more about     Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).      For this sample, you can use the api key `special-key` to test the authorization     filters.")
					.termsOfService("http://swagger.io/terms/")
					.license(new License().name("Apache 2.0").url("http://springdoc.org")));
}
 
Example #27
Source File: SpringDocTestApp.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@Bean
public OpenAPI customOpenAPI() {
	return new OpenAPI()
			.components(new Components().addSecuritySchemes("basicScheme",
					new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic")))
			.info(new Info().title("Petstore API").version("v0").description(
					"This is a sample server Petstore server.  You can find out more about     Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).      For this sample, you can use the api key `special-key` to test the authorization     filters.")
					.termsOfService("http://swagger.io/terms/")
					.license(new License().name("Apache 2.0").url("http://springdoc.org")));
}
 
Example #28
Source File: Application.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public OpenAPI customOpenAPI(@Value("${springdoc.version}") String appVersion) {
    return new OpenAPI().info(new Info().title("Foobar API")
        .version(appVersion)
        .description("This is a sample Foobar server created using springdocs - a library for OpenAPI 3 with spring boot.")
        .termsOfService("http://swagger.io/terms/")
        .license(new License().name("Apache 2.0")
            .url("http://springdoc.org")));
}
 
Example #29
Source File: GenerateRestClients.java    From konduit-serving with Apache License 2.0 4 votes vote down vote up
private static void createApiInfo(OpenAPI openAPI) {
    try (InputStream is = GenerateRestClients.class.getClassLoader().getResourceAsStream("META-INF/konduit-serving-clients-git.properties")) {
        if (is == null) {
            throw new IllegalStateException("Cannot find konduit-serving-clients-git.properties on classpath");
        }
        Properties gitProperties = new Properties();
        gitProperties.load(is);
        String projectVersion = gitProperties.getProperty("git.build.version");
        String commitId = gitProperties.getProperty("git.commit.id").substring(0, 8);

        openAPI.info(new Info()
                .title("Konduit Serving REST API")
                .version(String.format("%s | Commit: %s", projectVersion, commitId))
                .description("RESTful API for various operations inside konduit-serving")
                .license(new License()
                        .name("Apache 2.0")
                        .url("https://github.com/KonduitAI/konduit-serving/blob/master/LICENSE"))
                .contact(new Contact()
                        .url("https://konduit.ai/contact")
                        .name("Konduit K.K.")
                        .email("[email protected]")))
                .tags(Collections.singletonList(
                        new Tag()
                                .name("inference")
                                .description("Inference server operations")))
                .externalDocs(new ExternalDocumentation()
                        .description("Online documentation")
                        .url("https://serving.konduit.ai"))
                .path("/predict", new PathItem()
                        .summary("Predicts an output based on the given JSON (key/value) or binary string")
                        .description("Takes a JSON string of key value pairs or a binary data string (protobuf) as input " +
                                "and processes it in the pipeline. The output could be json or a binary string based on " +
                                "the accept header value (application/json or application/octet-stream respectively).")
                        .post(new Operation()
                                .operationId("predict")
                                .addTagsItem("inference")
                                .requestBody(new RequestBody()
                                        .required(true)
                                        .content(new Content()
                                                .addMediaType(APPLICATION_JSON.toString(),
                                                        new MediaType().schema(new MapSchema()))
                                                .addMediaType(APPLICATION_OCTET_STREAM.toString(),
                                                        new MediaType().schema(new BinarySchema()))
                                        )
                                ).responses(new ApiResponses()
                                        .addApiResponse("200", new ApiResponse()
                                                .description("Successful operation")
                                                .content(new Content()
                                                        .addMediaType(APPLICATION_JSON.toString(),
                                                                new MediaType().schema(new MapSchema()))
                                                        .addMediaType(APPLICATION_OCTET_STREAM.toString(),
                                                                new MediaType().schema(new BinarySchema()))
                                                )
                                        ).addApiResponse("500", new ApiResponse()
                                                .description("Internal server error")
                                                .content(new Content()
                                                        .addMediaType(APPLICATION_JSON.toString(), new MediaType()
                                                                .schema(new ObjectSchema().$ref("#/components/schemas/ErrorResponse"))
                                                        )
                                                )
                                        )
                                )
                        )
                );
    } catch (IOException e) {
        throw new IllegalStateException(e.getMessage());
    }
}
 
Example #30
Source File: OpenAPIDeserializer.java    From swagger-parser with Apache License 2.0 4 votes vote down vote up
public Info getInfo(ObjectNode node, String location, ParseResult result) {
    if (node == null)
        return null;

    Info info = new Info();

    String value = getString("title", node, true, location, result);
    if(StringUtils.isNotBlank(value)) {
        info.setTitle(value);
    }

    value = getString("description", node, false, location, result);
    if(StringUtils.isNotBlank(value)) {
        info.setDescription(value);
    }

    value = getString("termsOfService", node, false, location, result);
    if(StringUtils.isNotBlank(value)) {
        info.setTermsOfService(value);
    }

    ObjectNode obj = getObject("contact", node, false, "contact", result);
    Contact contact = getContact(obj, String.format("%s.%s", location, "contact"), result);
    if(obj != null) {
        info.setContact(contact);
    }
    obj = getObject("license", node, false, location, result);
    License license = getLicense(obj, String.format("%s.%s", location, "license"), result);
    if(obj != null) {
        info.setLicense(license);
    }

    value = getString("version", node, true, location, result);
    if(StringUtils.isNotBlank(value)) {
        info.setVersion(value);
    }

    Map <String,Object> extensions = getExtensions(node);
    if(extensions != null && extensions.size() > 0) {
        info.setExtensions(extensions);
    }

    Set<String> keys = getKeys(node);
    for(String key : keys) {
        if(!INFO_KEYS.contains(key) && !key.startsWith("x-")) {
            result.extra(location, key, node.get(key));
        }
    }

    return info;
}