Java Code Examples for io.swagger.v3.oas.models.media.Schema#getDefault()
The following examples show how to use
io.swagger.v3.oas.models.media.Schema#getDefault() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HaskellHttpClientCodegen.java From openapi-generator with Apache License 2.0 | 6 votes |
@Override public String toDefaultValue(Schema p) { if (ModelUtils.isStringSchema(p)) { if (p.getDefault() != null) { return "\"" + escapeText((String) p.getDefault()) + "\""; } } else if (ModelUtils.isBooleanSchema(p)) { if (p.getDefault() != null) { if (p.getDefault().toString().equalsIgnoreCase("false")) return "False"; else return "True"; } } return null; }
Example 2
Source File: AbstractTypeScriptClientCodegen.java From openapi-generator with Apache License 2.0 | 6 votes |
@Override public String toDefaultValue(Schema p) { if (ModelUtils.isBooleanSchema(p)) { return UNDEFINED_VALUE; } else if (ModelUtils.isDateSchema(p)) { return UNDEFINED_VALUE; } else if (ModelUtils.isDateTimeSchema(p)) { return UNDEFINED_VALUE; } else if (ModelUtils.isNumberSchema(p) || ModelUtils.isIntegerSchema(p)) { if (p.getDefault() != null) { return p.getDefault().toString(); } return UNDEFINED_VALUE; } else if (ModelUtils.isStringSchema(p)) { if (p.getDefault() != null) { return "'" + (String) p.getDefault() + "'"; } return UNDEFINED_VALUE; } else { return UNDEFINED_VALUE; } }
Example 3
Source File: DartClientCodegen.java From openapi-generator with Apache License 2.0 | 6 votes |
@Override public String toDefaultValue(Schema schema) { if (ModelUtils.isMapSchema(schema)) { return "{}"; } else if (ModelUtils.isArraySchema(schema)) { return "[]"; } if (schema.getDefault() != null) { if (ModelUtils.isStringSchema(schema)) { return "\"" + schema.getDefault().toString().replaceAll("\"", "\\\"") + "\""; } return schema.getDefault().toString(); } else { return "null"; } }
Example 4
Source File: PerlClientCodegen.java From openapi-generator with Apache License 2.0 | 6 votes |
@Override public String toDefaultValue(Schema p) { if (ModelUtils.isBooleanSchema(p)) { if (p.getDefault() != null) { return p.getDefault().toString(); } } else if (ModelUtils.isDateSchema(p)) { // TODO } else if (ModelUtils.isDateTimeSchema(p)) { // TODO } else if (ModelUtils.isNumberSchema(p)) { if (p.getDefault() != null) { return p.getDefault().toString(); } } else if (ModelUtils.isIntegerSchema(p)) { if (p.getDefault() != null) { return p.getDefault().toString(); } } else if (ModelUtils.isStringSchema(p)) { if (p.getDefault() != null) { return "'" + p.getDefault() + "'"; } } return null; }
Example 5
Source File: Swift5ClientCodegen.java From openapi-generator with Apache License 2.0 | 6 votes |
@Override public String toDefaultValue(Schema p) { if (p.getEnum() != null && !p.getEnum().isEmpty()) { if (p.getDefault() != null) { if (ModelUtils.isStringSchema(p)) { return "." + toEnumVarName(escapeText((String) p.getDefault()), p.getType()); } else { return "." + toEnumVarName(escapeText(p.getDefault().toString()), p.getType()); } } } if (ModelUtils.isIntegerSchema(p) || ModelUtils.isNumberSchema(p) || ModelUtils.isBooleanSchema(p)) { if (p.getDefault() != null) { return p.getDefault().toString(); } } else if (ModelUtils.isStringSchema(p)) { if (p.getDefault() != null) { return "\"" + escapeText((String) p.getDefault()) + "\""; } } return null; }
Example 6
Source File: JavascriptApolloClientCodegen.java From openapi-generator with Apache License 2.0 | 6 votes |
@Override public String toDefaultValue(Schema p) { if (ModelUtils.isBooleanSchema(p)) { if (p.getDefault() != null) { return p.getDefault().toString(); } } else if (ModelUtils.isDateSchema(p)) { // TODO } else if (ModelUtils.isDateTimeSchema(p)) { // TODO } else if (ModelUtils.isNumberSchema(p)) { if (p.getDefault() != null) { return p.getDefault().toString(); } } else if (ModelUtils.isIntegerSchema(p)) { if (p.getDefault() != null) { return p.getDefault().toString(); } } else if (ModelUtils.isStringSchema(p)) { if (p.getDefault() != null) { return "'" + p.getDefault() + "'"; } } return null; }
Example 7
Source File: Swift4Codegen.java From openapi-generator with Apache License 2.0 | 6 votes |
@Override public String toDefaultValue(Schema p) { if (p.getEnum() != null && !p.getEnum().isEmpty()) { if (p.getDefault() != null) { if (ModelUtils.isStringSchema(p)) { return "." + toEnumVarName(escapeText((String) p.getDefault()), p.getType()); } else { return "." + toEnumVarName(escapeText(p.getDefault().toString()), p.getType()); } } } if (ModelUtils.isIntegerSchema(p) || ModelUtils.isNumberSchema(p) || ModelUtils.isBooleanSchema(p)) { if (p.getDefault() != null) { return p.getDefault().toString(); } } else if (ModelUtils.isStringSchema(p)) { if (p.getDefault() != null) { return "\"" + escapeText((String) p.getDefault()) + "\""; } } return null; }
Example 8
Source File: PythonAbstractConnexionServerCodegen.java From openapi-generator with Apache License 2.0 | 5 votes |
/** * Return the default value of the property * * @param p OpenAPI property object * @return string presentation of the default value of the property */ @Override public String toDefaultValue(Schema p) { if (ModelUtils.isBooleanSchema(p)) { if (p.getDefault() != null) { if (p.getDefault().toString().equalsIgnoreCase("false")) return "False"; else return "True"; } } else if (ModelUtils.isDateSchema(p)) { // TODO } else if (ModelUtils.isDateTimeSchema(p)) { // TODO } else if (ModelUtils.isNumberSchema(p)) { if (p.getDefault() != null) { return p.getDefault().toString(); } } else if (ModelUtils.isIntegerSchema(p)) { if (p.getDefault() != null) { return p.getDefault().toString(); } } else if (ModelUtils.isStringSchema(p)) { if (p.getDefault() != null) { return "'" + (String) p.getDefault() + "'"; } } return null; }
Example 9
Source File: GoClientExperimentalCodegen.java From openapi-generator with Apache License 2.0 | 5 votes |
@Override public String toDefaultValue(Schema p) { p = ModelUtils.getReferencedSchema(this.openAPI, p); if (ModelUtils.isStringSchema(p)) { if (p.getDefault() != null) { return "\"" + escapeText((String) p.getDefault()) + "\""; } return null; } return super.toDefaultValue(p); }
Example 10
Source File: AbstractGoCodegen.java From openapi-generator with Apache License 2.0 | 5 votes |
@Override public String toDefaultValue(Schema schema) { if (schema.getDefault() != null) { return schema.getDefault().toString(); } else { return null; } }
Example 11
Source File: RustClientCodegen.java From openapi-generator with Apache License 2.0 | 5 votes |
@Override public String toDefaultValue(Schema p) { if (p.getDefault() != null) { return p.getDefault().toString(); } else { return null; } }
Example 12
Source File: RClientCodegen.java From openapi-generator with Apache License 2.0 | 5 votes |
/** * Return the default value of the property * * @param p OpenAPI property object * @return string presentation of the default value of the property */ @Override public String toDefaultValue(Schema p) { if (ModelUtils.isBooleanSchema(p)) { if (p.getDefault() != null) { if (Boolean.valueOf(p.getDefault().toString()) == false) return "FALSE"; else return "TRUE"; } } else if (ModelUtils.isDateSchema(p)) { // TODO } else if (ModelUtils.isDateTimeSchema(p)) { // TODO } else if (ModelUtils.isNumberSchema(p)) { if (p.getDefault() != null) { return p.getDefault().toString(); } } else if (ModelUtils.isIntegerSchema(p)) { if (p.getDefault() != null) { return p.getDefault().toString(); } } else if (ModelUtils.isStringSchema(p)) { if (p.getDefault() != null) { if (Pattern.compile("\r\n|\r|\n").matcher((String) p.getDefault()).find()) return "'''" + p.getDefault() + "'''"; else return "'" + ((String) p.getDefault()).replaceAll("'","\'") + "'"; } } else if (ModelUtils.isArraySchema(p)) { if (p.getDefault() != null) { return p.getDefault().toString(); } } return null; }
Example 13
Source File: PythonClientCodegen.java From openapi-generator with Apache License 2.0 | 5 votes |
/** * Return the default value of the property * * @param p OpenAPI property object * @return string presentation of the default value of the property */ @Override public String toDefaultValue(Schema p) { if (ModelUtils.isBooleanSchema(p)) { if (p.getDefault() != null) { if (Boolean.valueOf(p.getDefault().toString()) == false) return "False"; else return "True"; } } else if (ModelUtils.isDateSchema(p)) { // TODO } else if (ModelUtils.isDateTimeSchema(p)) { // TODO } else if (ModelUtils.isNumberSchema(p)) { if (p.getDefault() != null) { return p.getDefault().toString(); } } else if (ModelUtils.isIntegerSchema(p)) { if (p.getDefault() != null) { return p.getDefault().toString(); } } else if (ModelUtils.isStringSchema(p)) { if (p.getDefault() != null) { if (Pattern.compile("\r\n|\r|\n").matcher((String) p.getDefault()).find()) return "'''" + p.getDefault() + "'''"; else return "'" + ((String) p.getDefault()).replaceAll("'", "\'") + "'"; } } else if (ModelUtils.isArraySchema(p)) { if (p.getDefault() != null) { return p.getDefault().toString(); } } return null; }
Example 14
Source File: RustServerCodegen.java From openapi-generator with Apache License 2.0 | 5 votes |
@Override public String toDefaultValue(Schema p) { String defaultValue = null; if ((ModelUtils.isNullable(p)) && (p.getDefault() != null) && (p.getDefault().toString().equalsIgnoreCase("null"))) return "swagger::Nullable::Null"; else if (ModelUtils.isBooleanSchema(p)) { if (p.getDefault() != null) { if (p.getDefault().toString().equalsIgnoreCase("false")) defaultValue = "false"; else defaultValue = "true"; } } else if (ModelUtils.isNumberSchema(p)) { if (p.getDefault() != null) { defaultValue = p.getDefault().toString(); } } else if (ModelUtils.isIntegerSchema(p)) { if (p.getDefault() != null) { defaultValue = p.getDefault().toString(); } } else if (ModelUtils.isStringSchema(p)) { if (p.getDefault() != null) { defaultValue = "\"" + (String) p.getDefault() + "\".to_string()"; } } if ((defaultValue != null) && (ModelUtils.isNullable(p))) defaultValue = "swagger::Nullable::Present(" + defaultValue + ")"; return defaultValue; }
Example 15
Source File: ObjcClientCodegen.java From openapi-generator with Apache License 2.0 | 5 votes |
/** * Return the default value of the schema * @param p OpenAPI schema object * @return string presentation of the default value of the schema */ @Override public String toDefaultValue(Schema p) { if (ModelUtils.isDateSchema(p)) { // TODO } else if (ModelUtils.isDateTimeSchema(p)) { // TODO } else if (ModelUtils.isNumberSchema(p)) { if (p.getDefault() != null) { return "@" + p.getDefault().toString(); } } else if (ModelUtils.isIntegerSchema(p)) { if (p.getDefault() != null) { return "@" + p.getDefault().toString(); } } else if (ModelUtils.isStringSchema(p)) { if (p.getDefault() != null) { return "@\"" + (String) p.getDefault() + "\""; } } else if (ModelUtils.isBooleanSchema(p)) { if (p.getDefault() != null) { if (p.getDefault().toString().equalsIgnoreCase("false")) return "@(NO)"; else return "@(YES)"; } } return null; }
Example 16
Source File: AbstractPhpCodegen.java From openapi-generator with Apache License 2.0 | 5 votes |
/** * Return the default value of the property * @param p OpenAPI property object * @return string presentation of the default value of the property */ @Override public String toDefaultValue(Schema p) { if (ModelUtils.isBooleanSchema(p)) { if (p.getDefault() != null) { return p.getDefault().toString(); } } else if (ModelUtils.isDateSchema(p)) { // TODO } else if (ModelUtils.isDateTimeSchema(p)) { // TODO } else if (ModelUtils.isNumberSchema(p)) { if (p.getDefault() != null) { return p.getDefault().toString(); } } else if (ModelUtils.isIntegerSchema(p)) { if (p.getDefault() != null) { return p.getDefault().toString(); } } else if (ModelUtils.isStringSchema(p)) { if (p.getDefault() != null) { return "'" + p.getDefault() + "'"; } } return null; }
Example 17
Source File: CLibcurlClientCodegen.java From openapi-generator with Apache License 2.0 | 5 votes |
@Override public String toDefaultValue(Schema p) { if (ModelUtils.isIntegerSchema(p) || ModelUtils.isNumberSchema(p) || ModelUtils.isBooleanSchema(p)) { if (p.getDefault() != null) { return p.getDefault().toString(); } } else if (ModelUtils.isStringSchema(p)) { if (p.getDefault() != null) { return "'" + escapeText((String) p.getDefault()) + "'"; } } return null; }
Example 18
Source File: AbstractFSharpCodegen.java From openapi-generator with Apache License 2.0 | 4 votes |
/** * Return the default value of the property * * @param p OpenAPI property object * @return string presentation of the default value of the property */ @Override public String toDefaultValue(Schema p) { if (ModelUtils.isBooleanSchema(p)) { if (p.getDefault() != null) { return p.getDefault().toString(); } } else if (ModelUtils.isDateSchema(p)) { if (p.getDefault() != null) { return "\"" + p.getDefault().toString() + "\""; } } else if (ModelUtils.isDateTimeSchema(p)) { if (p.getDefault() != null) { return "\"" + p.getDefault().toString() + "\""; } } else if (ModelUtils.isNumberSchema(p)) { if (p.getDefault() != null) { if (ModelUtils.isFloatSchema(p)) { // float return p.getDefault().toString() + "F"; } else if (ModelUtils.isDoubleSchema(p)) { // double return p.getDefault().toString() + "D"; } else { // decimal return p.getDefault().toString() + "M"; } } } else if (ModelUtils.isIntegerSchema(p)) { if (p.getDefault() != null) { return p.getDefault().toString(); } } else if (ModelUtils.isStringSchema(p)) { if (p.getDefault() != null) { String _default = (String) p.getDefault(); if (p.getEnum() == null) { return "\"" + _default + "\""; } else { // convert to enum var name later in postProcessModels return _default; } } } return null; }
Example 19
Source File: CppUE4ClientCodegen.java From openapi-generator with Apache License 2.0 | 4 votes |
@Override public String toDefaultValue(Schema p) { if (ModelUtils.isStringSchema(p)) { if (p.getDefault() != null) { return "TEXT(\"" + p.getDefault().toString() + "\")"; } else { return null; } } else if (ModelUtils.isBooleanSchema(p)) { if (p.getDefault() != null) { return p.getDefault().toString(); } else { return "false"; } } else if (ModelUtils.isDateSchema(p)) { return "FDateTime(0)"; } else if (ModelUtils.isDateTimeSchema(p)) { return "FDateTime(0)"; } else if (ModelUtils.isDoubleSchema(p)) { if (p.getDefault() != null) { return p.getDefault().toString(); } else { return "0.0"; } } else if (ModelUtils.isFloatSchema(p)) { if (p.getDefault() != null) { return p.getDefault().toString(); } else { return "0.0f"; } } else if (ModelUtils.isIntegerSchema(p)) { if (p.getDefault() != null) { return p.getDefault().toString(); } else { return "0"; } } else if (ModelUtils.isLongSchema(p)) { if (p.getDefault() != null) { return p.getDefault().toString(); } else { return "0"; } } return null; }
Example 20
Source File: CLibcurlClientCodegen.java From openapi-generator with Apache License 2.0 | 4 votes |
@Override public String toExampleValue(Schema schema) { String example = super.toExampleValue(schema); if (ModelUtils.isNullType(schema) && null != example) { // The 'null' type is allowed in OAS 3.1 and above. It is not supported by OAS 3.0.x, // though this tooling supports it. return "NULL"; } // correct "'"s into "'"s after toString() if (ModelUtils.isStringSchema(schema) && schema.getDefault() != null) { example = (String) schema.getDefault(); } if (StringUtils.isNotBlank(example) && !"null".equals(example)) { if (ModelUtils.isStringSchema(schema)) { example = "\"" + example + "\""; } return example; } if (schema.getEnum() != null && !schema.getEnum().isEmpty()) { // Enum case: example = schema.getEnum().get(0).toString(); /* if (ModelUtils.isStringSchema(schema)) { example = "'" + escapeText(example) + "'"; }*/ if (null == example) LOGGER.warn("Empty enum. Cannot built an example!"); return example; } else if (null != schema.get$ref()) { // $ref case: Map<String, Schema> allDefinitions = ModelUtils.getSchemas(this.openAPI); String ref = ModelUtils.getSimpleRef(schema.get$ref()); if (allDefinitions != null) { Schema refSchema = allDefinitions.get(ref); if (null == refSchema) { return "None"; } else { String refTitle = refSchema.getTitle(); if (StringUtils.isBlank(refTitle) || "null".equals(refTitle)) { refSchema.setTitle(ref); } return toExampleValue(refSchema); } } else { LOGGER.warn("allDefinitions not defined in toExampleValue!\n"); } } if (ModelUtils.isDateSchema(schema)) { example = "\"2013-10-20\""; return example; } else if (ModelUtils.isDateTimeSchema(schema)) { example = "\"2013-10-20T19:20:30+01:00\""; return example; } else if (ModelUtils.isBinarySchema(schema)) { example = "instantiate_binary_t(\"blah\", 5)"; return example; } else if (ModelUtils.isByteArraySchema(schema)) { example = "YQ=="; } else if (ModelUtils.isStringSchema(schema)) { // a BigDecimal: if ("Number".equalsIgnoreCase(schema.getFormat())) {return "1";} if (StringUtils.isNotBlank(schema.getPattern())) return "\"a\""; // I cheat here, since it would be too complicated to generate a string from a regexp int len = 0; if (null != schema.getMinLength()) len = schema.getMinLength().intValue(); if (len < 1) len = 1; example = ""; for (int i=0;i<len;i++) example += i; } else if (ModelUtils.isIntegerSchema(schema)) { if (schema.getMinimum() != null) example = schema.getMinimum().toString(); else example = "56"; } else if (ModelUtils.isNumberSchema(schema)) { if (schema.getMinimum() != null) example = schema.getMinimum().toString(); else example = "1.337"; } else if (ModelUtils.isBooleanSchema(schema)) { example = "1"; } else if (ModelUtils.isArraySchema(schema)) { example = "list_create()"; } else if (ModelUtils.isMapSchema(schema)) { example = "list_create()"; } else if (ModelUtils.isObjectSchema(schema)) { return null; // models are managed at moustache level } else { LOGGER.warn("Type " + schema.getType() + " not handled properly in toExampleValue"); } if (ModelUtils.isStringSchema(schema)) { example = "\"" + escapeText(example) + "\""; } return example; }