yaml swagger: "2.0" info: version: "1.0.0" host: "localhost:8080" basePath: "/api" schemes: - "http" paths: /users: get: responses: 200: schema: type: "array" items: $ref: "#/definitions/User" definitions: User: type: "object" properties: id: type: "integer" name: type: "string" bash java -jar swagger-codegen-cli.jar generate -i <path_to_swagger_file> -l java -o <output_directory> <dependency> <groupId>com.example</groupId> <artifactId>api-client</artifactId> <version>1.0.0</version> </dependency> ApiClient apiClient = new ApiClient(); apiClient.setBasePath("http://localhost:8080/api"); DefaultApi api = new DefaultApi(apiClient); try { List<User> users = api.getUsers(); for (User user : users) { System.out.println("User: " + user.getName()); } } catch (ApiException e) { System.err.println("Exception when calling API: " + e.getMessage()); }


上一篇:
下一篇:
切换中文