forked from loafle/openapi-generator-original
parent
b7df040b6e
commit
afa8e56b4e
@ -6,6 +6,7 @@ import io.swagger.codegen.cmd.ConfigHelp;
|
|||||||
import io.swagger.codegen.cmd.Generate;
|
import io.swagger.codegen.cmd.Generate;
|
||||||
import io.swagger.codegen.cmd.Langs;
|
import io.swagger.codegen.cmd.Langs;
|
||||||
import io.swagger.codegen.cmd.Meta;
|
import io.swagger.codegen.cmd.Meta;
|
||||||
|
import io.swagger.codegen.cmd.Validate;
|
||||||
import io.swagger.codegen.cmd.Version;
|
import io.swagger.codegen.cmd.Version;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,6 +36,7 @@ public class SwaggerCodegen {
|
|||||||
Langs.class,
|
Langs.class,
|
||||||
Help.class,
|
Help.class,
|
||||||
ConfigHelp.class,
|
ConfigHelp.class,
|
||||||
|
Validate.class,
|
||||||
Version.class
|
Version.class
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
package io.swagger.codegen.cmd;
|
||||||
|
|
||||||
|
import io.airlift.airline.Command;
|
||||||
|
import io.airlift.airline.Option;
|
||||||
|
|
||||||
|
import io.swagger.parser.SwaggerParser;
|
||||||
|
import io.swagger.parser.util.SwaggerDeserializationResult;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Command(name = "validate", description = "Validate specification")
|
||||||
|
public class Validate implements Runnable {
|
||||||
|
|
||||||
|
@Option(name = {"-i", "--input-spec"}, title = "spec file", required = true,
|
||||||
|
description = "location of the swagger spec, as URL or file (required)")
|
||||||
|
private String spec;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
System.out.println("Validating spec file (" + spec + ")");
|
||||||
|
|
||||||
|
SwaggerParser parser = new SwaggerParser();
|
||||||
|
SwaggerDeserializationResult result = parser.readWithInfo(spec, null, true);
|
||||||
|
List<String> messageList = result.getMessages();
|
||||||
|
Set<String> messages = new HashSet<String>(messageList);
|
||||||
|
|
||||||
|
for (String message: messages) {
|
||||||
|
System.out.println(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (messages.size() > 0) {
|
||||||
|
throw new ValidateException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package io.swagger.codegen.cmd;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by takuro on 2017/05/02.
|
||||||
|
*/
|
||||||
|
public class ValidateException extends RuntimeException {
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user