Obtain the example value from examples (#419)

* Fix error: "GET operations can not have a requestBody"
* Add support for "examples" in addition to "support example"
This commit is contained in:
Jérémie Bresson
2018-06-30 06:58:30 +02:00
committed by GitHub
parent 0c11718917
commit 1f1a47c57b
3 changed files with 94 additions and 12 deletions

View File

@@ -24,6 +24,7 @@ import com.samskivert.mustache.Mustache.Compiler;
import io.swagger.v3.core.util.Json;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.examples.Example;
import io.swagger.v3.oas.models.headers.Header;
import io.swagger.v3.oas.models.media.*;
import io.swagger.v3.oas.models.parameters.CookieParameter;
@@ -1092,6 +1093,14 @@ public class DefaultCodegen implements CodegenConfig {
return;
}
if (parameter.getExamples() != null && !parameter.getExamples().isEmpty()) {
Example example = parameter.getExamples().values().iterator().next();
if(example.getValue() != null) {
codegenParameter.example = example.getValue().toString();
return;
}
}
Schema schema = parameter.getSchema();
if (schema != null && schema.getExample() != null) {
codegenParameter.example = schema.getExample().toString();
@@ -1121,6 +1130,14 @@ public class DefaultCodegen implements CodegenConfig {
return;
}
if (mediaType.getExamples() != null && !mediaType.getExamples().isEmpty()) {
Example example = mediaType.getExamples().values().iterator().next();
if(example.getValue() != null) {
codegenParameter.example = example.getValue().toString();
return;
}
}
setParameterExampleValue(codegenParameter);
}