|
11 | 11 |
|
12 | 12 | import com.mrv.yangtools.codegen.SwaggerGenerator; |
13 | 13 | import com.mrv.yangtools.codegen.impl.path.rfc8040.PathHandlerBuilder; |
14 | | -import com.mrv.yangtools.codegen.impl.postprocessor.PathPrunner; |
15 | | -import com.mrv.yangtools.codegen.impl.postprocessor.RemoveUnusedDefinitions; |
16 | | -import com.mrv.yangtools.codegen.impl.postprocessor.SingleParentInheritenceModel; |
| 14 | +import com.mrv.yangtools.codegen.impl.postprocessor.*; |
17 | 15 | import com.mrv.yangtools.common.ContextHelper; |
| 16 | +import io.swagger.models.auth.BasicAuthDefinition; |
18 | 17 | import org.kohsuke.args4j.Argument; |
19 | 18 | import org.kohsuke.args4j.CmdLineException; |
20 | 19 | import org.kohsuke.args4j.CmdLineParser; |
@@ -68,8 +67,14 @@ public class Generator { |
68 | 67 | @Option(name = "-use-namespaces", usage="Use namespaces in resource URI") |
69 | 68 | public boolean useNamespaces = false; |
70 | 69 |
|
| 70 | + @Option(name = "-authentication", usage="Authentication definition") |
| 71 | + public AuthenticationMechanism authenticationMechanism = AuthenticationMechanism.NONE; |
| 72 | + |
71 | 73 | OutputStream out = System.out; |
72 | 74 |
|
| 75 | + public enum AuthenticationMechanism { |
| 76 | + BASIC, NONE |
| 77 | + } |
73 | 78 |
|
74 | 79 | public enum ElementType { |
75 | 80 | DATA, RPC, DATA_AND_RPC; |
@@ -118,7 +123,12 @@ protected void generate() throws IOException, ReactorException { |
118 | 123 | .format(outputFormat).consumes(contentType).produces(contentType) |
119 | 124 | .host("localhost:1234").elements(map(elementType)) |
120 | 125 | .pathHandler(pathHandler) |
121 | | - .appendPostProcessor(new PathPrunner("/operations").withType("tapi.common.GlobalClass")); |
| 126 | + .appendPostProcessor(new PathPrunner("/operations").withType("tapi.common.GlobalClass")) |
| 127 | + .appendPostProcessor(new CollapseTypes()); |
| 128 | + |
| 129 | + if(AuthenticationMechanism.BASIC.equals(authenticationMechanism)) { |
| 130 | + generator.appendPostProcessor(new AddSecurityDefinitions().withSecurityDefinition("api_sec", new BasicAuthDefinition())); |
| 131 | + } |
122 | 132 |
|
123 | 133 | if(simplified) { |
124 | 134 | generator.appendPostProcessor(new SingleParentInheritenceModel()); |
|
0 commit comments