Merge remote-tracking branch 'origin' into 4.0.x

This commit is contained in:
William Cheng
2018-11-30 10:16:16 +08:00
188 changed files with 1199 additions and 6335 deletions

View File

@@ -32,6 +32,7 @@ import org.slf4j.LoggerFactory;
import static org.openapitools.codegen.config.CodegenConfiguratorUtils.*;
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
@@ -246,6 +247,11 @@ public class Generate implements Runnable {
}
if (isNotEmpty(spec)) {
if (!spec.matches("^http(s)?://.*") && !new File(spec).exists()) {
System.err.println("[error] The spec file is not found: " + spec);
System.err.println("[error] Check the path of the OpenAPI spec and try again.");
System.exit(1);
}
configurator.setInputSpec(spec);
}

View File

@@ -64,7 +64,7 @@ public class GenerateTest {
@Test
public void testRequiredArgs_ShortArgs() throws Exception {
setupAndRunTest("-i", "swagger.yaml", "-g", "java", "-o", "src/main/java", false, null);
setupAndRunTest("-i", "src/test/resources/swagger.yaml", "-g", "java", "-o", "src/main/java", false, null);
new FullVerifications() {
{
}
@@ -73,7 +73,7 @@ public class GenerateTest {
@Test
public void testRequiredArgs_LongArgs() throws Exception {
setupAndRunTest("--input-spec", "swagger.yaml", "--generator-name", "java", "--output",
setupAndRunTest("--input-spec", "src/test/resources/swagger.yaml", "--generator-name", "java", "--output",
"src/main/java", false, null);
new FullVerifications() {
{
@@ -220,7 +220,7 @@ public class GenerateTest {
@Test
public void testConfig() throws Exception {
setupAndRunTest("-i", "swagger.yaml", "-g", "java", "-o", "src/main/java", true,
setupAndRunTest("-i", "src/test/resources/swagger.yaml", "-g", "java", "-o", "src/main/java", true,
"config.json", "-c", "config.json");
new FullVerifications() {
@@ -228,7 +228,7 @@ public class GenerateTest {
}
};
setupAndRunTest("-i", "swagger.yaml", "-g", "java", "-o", "src/main/java", true,
setupAndRunTest("-i", "src/test/resources/swagger.yaml", "-g", "java", "-o", "src/main/java", true,
"config.json", "--config", "config.json");
new FullVerifications() {
@@ -570,7 +570,7 @@ public class GenerateTest {
}
private void setupAndRunGenericTest(String... additionalParameters) {
setupAndRunTest("-i", "swagger.yaml", "-g", "java", "-o", "src/main/java", false, null,
setupAndRunTest("-i", "src/test/resources/swagger.yaml", "-g", "java", "-o", "src/main/java", false, null,
additionalParameters);
}
}

View File

@@ -0,0 +1,109 @@
openapi: "3.0.0"
info:
version: 1.0.0
title: Swagger Petstore
license:
name: MIT
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets:
get:
summary: List all pets
operationId: listPets
tags:
- pets
parameters:
- name: limit
in: query
description: How many items to return at one time (max 100)
required: false
schema:
type: integer
format: int32
responses:
'200':
description: A paged array of pets
headers:
x-next:
description: A link to the next page of responses
schema:
type: string
content:
application/json:
schema:
$ref: "#/components/schemas/Pets"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
post:
summary: Create a pet
operationId: createPets
tags:
- pets
responses:
'201':
description: Null response
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
/pets/{petId}:
get:
summary: Info for a specific pet
operationId: showPetById
tags:
- pets
parameters:
- name: petId
in: path
required: true
description: The id of the pet to retrieve
schema:
type: string
responses:
'200':
description: Expected response to a valid request
content:
application/json:
schema:
$ref: "#/components/schemas/Pets"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
components:
schemas:
Pet:
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
Pets:
type: array
items:
$ref: "#/components/schemas/Pet"
Error:
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string