mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2026-03-17 11:09:11 +00:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user