Skip to content

Instantly share code, notes, and snippets.

import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.NotNull;
@RestController
@RequestMapping("/users")
class UserResource {
@GetMapping()
List<User> allUsers() { /* ... */ }
import React, { useEffect, useState } from 'react';
import { Configuration, User, UserResourceApi, UserRolesEnum } from "./api/src";
const config = new Configuration({
basePath: window.location.origin, // 1
});
const userApi = new UserResourceApi(config); // 2
const isAdmin = (user: User) => user.roles.includes(UserRolesEnum.ADMIN)
@rzymek
rzymek / api.sh
Last active December 23, 2020 14:13
#!/bin/bash
rm -rf src/api
npx @openapitools/openapi-generator-cli generate \
-i http://localhost:8080/v2/api-docs \
-g typescript-fetch \
-o src/api
"scripts": {
"api": "openapi-generator generate -i http://localhost:8080/v2/api-docs -g typescript-fetch --skip-validate-spec -o src/api/"
},
"devDependencies": {
"@openapitools/openapi-generator-cli": "^1.0.12-4.3.0"
}
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-bean-validators</artifactId>
<version>2.9.2</version>
</dependency>
@Configuration @EnableSwagger2
@Import(BeanValidatorPluginsConfiguration.class)
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).select()
.apis(RequestHandlerSelectors.basePackage(getClass().getPackageName()))
.paths(PathSelectors.any()).build();
}
}
@rzymek
rzymek / call-hierarchy-to-dot.awk
Created January 21, 2020 20:03
Intellij Idea Call Hierarchy to graphviz dot file
# awk -f call-hierarchy-to-graph.awk call-stack.txt |dot -Tpng -o call-stack.png
BEGIN {
print "digraph {"
path[-1]="start"
}
{
depth=(match($0, /[^ ]/)-1)/4;
gsub(/^ +/,"")
@rzymek
rzymek / gcloud-run.sh
Created January 19, 2020 20:56
gcloud run docker
#!/bin/bash
set -eu
cd `dirname $0`
docker build . -t gcr.io/sandbox-p/spring
docker push gcr.io/sandbox-p/spring
gcloud run deploy spring \
--image=gcr.io/sandbox-p/spring \
--platform managed \
--region europe-west1 \
--allow-unauthenticated