Java Code Examples for io.swagger.models.Response#getSchema()
The following examples show how to use
io.swagger.models.Response#getSchema() .
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: CppRestClientCodegen.java From TypeScript-Microservices with MIT License | 6 votes |
@Override public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map<String, Model> definitions, Swagger swagger) { CodegenOperation op = super.fromOperation(path, httpMethod, operation, definitions, swagger); if (operation.getResponses() != null && !operation.getResponses().isEmpty()) { Response methodResponse = findMethodResponse(operation.getResponses()); if (methodResponse != null) { if (methodResponse.getSchema() != null) { CodegenProperty cm = fromProperty("response", methodResponse.getSchema()); op.vendorExtensions.put("x-codegen-response", cm); if(cm.datatype == "HttpContent") { op.vendorExtensions.put("x-codegen-response-ishttpcontent", true); } } } } return op; }
Example 2
Source File: PistacheServerCodegen.java From TypeScript-Microservices with MIT License | 6 votes |
@Override public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map<String, Model> definitions, Swagger swagger) { CodegenOperation op = super.fromOperation(path, httpMethod, operation, definitions, swagger); if (operation.getResponses() != null && !operation.getResponses().isEmpty()) { Response methodResponse = findMethodResponse(operation.getResponses()); if (methodResponse != null) { if (methodResponse.getSchema() != null) { CodegenProperty cm = fromProperty("response", methodResponse.getSchema()); op.vendorExtensions.put("x-codegen-response", cm); if(cm.datatype == "HttpContent") { op.vendorExtensions.put("x-codegen-response-ishttpcontent", true); } } } } String pathForPistache = path.replaceAll("\\{(.*?)}", ":$1"); op.vendorExtensions.put("x-codegen-pistache-path", pathForPistache); return op; }
Example 3
Source File: AbstractAdaCodegen.java From TypeScript-Microservices with MIT License | 6 votes |
@Override public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map<String, Model> definitions, Swagger swagger) { CodegenOperation op = super.fromOperation(path, httpMethod, operation, definitions, swagger); if (operation.getResponses() != null && !operation.getResponses().isEmpty()) { Response methodResponse = findMethodResponse(operation.getResponses()); if (methodResponse != null) { if (methodResponse.getSchema() != null) { CodegenProperty cm = fromProperty("response", methodResponse.getSchema()); op.vendorExtensions.put("x-codegen-response", cm); if(cm.datatype == "HttpContent") { op.vendorExtensions.put("x-codegen-response-ishttpcontent", true); } } } } return op; }
Example 4
Source File: ApiGatewaySdkSwaggerApiImporter.java From aws-apigateway-importer with Apache License 2.0 | 6 votes |
private Optional<Model> getModel(RestApi api, Response response) { String modelName; // if the response references a proper model, look for a model matching the model name if (response.getSchema() != null && response.getSchema().getType().equals("ref")) { modelName = ((RefProperty) response.getSchema()).getSimpleRef(); } else { // if the response has an embedded schema, look for a model matching the generated name modelName = generateModelName(response); } try { Model model = api.getModelByName(modelName); if (model.getName() != null) { return Optional.of(model); } } catch (Exception ignored) {} return Optional.empty(); }
Example 5
Source File: SpecificationDiff.java From swagger-diff with Apache License 2.0 | 5 votes |
private static Property getResponseProperty(Operation operation) { Map<String, Response> responses = operation.getResponses(); // temporary workaround for missing response messages if (responses == null) return null; Response response = responses.get("200"); return null == response ? null : response.getSchema(); }
Example 6
Source File: AbstractOktaJavaClientCodegen.java From okta-sdk-java with Apache License 2.0 | 5 votes |
private Property getArrayPropertyFromOperation(Operation operation) { if (operation != null && operation.getResponses() != null) { Response response = operation.getResponses().get("200"); if (response != null) { return response.getSchema(); } } return null; }
Example 7
Source File: SwaggerInventory.java From swagger-parser with Apache License 2.0 | 5 votes |
public void process(Response response) { this.responses.add(response); if(response.getSchema() != null) { this.process(response.getSchema()); } }
Example 8
Source File: DefaultCodegen.java From TypeScript-Microservices with MIT License | 4 votes |
/** * Convert Swagger Response object to Codegen Response object * * @param responseCode HTTP response code * @param response Swagger Response object * @return Codegen Response object */ public CodegenResponse fromResponse(String responseCode, Response response) { CodegenResponse r = CodegenModelFactory.newInstance(CodegenModelType.RESPONSE); if ("default".equals(responseCode)) { r.code = "0"; } else { r.code = responseCode; } r.message = escapeText(response.getDescription()); r.schema = response.getSchema(); r.examples = toExamples(response.getExamples()); r.jsonSchema = Json.pretty(response); r.vendorExtensions = response.getVendorExtensions(); addHeaders(response, r.headers); r.hasHeaders = !r.headers.isEmpty(); if (r.schema != null) { Property responseProperty = response.getSchema(); responseProperty.setRequired(true); CodegenProperty cm = fromProperty("response", responseProperty); if (responseProperty instanceof ArrayProperty) { ArrayProperty ap = (ArrayProperty) responseProperty; CodegenProperty innerProperty = fromProperty("response", ap.getItems()); r.baseType = innerProperty.baseType; } else { if (cm.complexType != null) { r.baseType = cm.complexType; } else { r.baseType = cm.baseType; } } r.dataType = cm.datatype; if (Boolean.TRUE.equals(cm.isString) && Boolean.TRUE.equals(cm.isUuid)) { r.isUuid = true; } else if (Boolean.TRUE.equals(cm.isByteArray)) { r.isByteArray = true; } else if (Boolean.TRUE.equals(cm.isString)) { r.isString = true; } else if (Boolean.TRUE.equals(cm.isBoolean)) { r.isBoolean = true; } else if (Boolean.TRUE.equals(cm.isLong)) { r.isLong = true; r.isNumeric = true; } else if (Boolean.TRUE.equals(cm.isInteger)) { r.isInteger = true; r.isNumeric = true; } else if (Boolean.TRUE.equals(cm.isNumber)) { r.isNumber = true; r.isNumeric = true; } else if (Boolean.TRUE.equals(cm.isDouble)) { r.isDouble = true; r.isNumeric = true; } else if (Boolean.TRUE.equals(cm.isFloat)) { r.isFloat = true; r.isNumeric = true; } else if (Boolean.TRUE.equals(cm.isBinary)) { r.isBinary = true; } else if (Boolean.TRUE.equals(cm.isFile)) { r.isFile = true; } else if (Boolean.TRUE.equals(cm.isDate)) { r.isDate = true; } else if (Boolean.TRUE.equals(cm.isDateTime)) { r.isDateTime = true; } else { LOGGER.debug("Property type is not primitive: " + cm.datatype); } if (cm.isContainer) { r.simpleType = false; r.containerType = cm.containerType; r.isMapContainer = "map".equals(cm.containerType); r.isListContainer = "list".equalsIgnoreCase(cm.containerType) || "array".equalsIgnoreCase(cm.containerType); } else { r.simpleType = true; } r.primitiveType = (r.baseType == null || languageSpecificPrimitives().contains(r.baseType)); } if (r.baseType == null) { r.isMapContainer = false; r.isListContainer = false; r.primitiveType = true; r.simpleType = true; } return r; }
Example 9
Source File: ProtoApiFromOpenApi.java From api-compiler with Apache License 2.0 | 4 votes |
/** * Returns {@link TypeInfo} corresponding to the response object. * * <p>In case we cannot resolve the schema we fallback to the following well known types: * <li>'Value' type : If there is more than one success response codes or the success code schema * represents a non message type. * <li>'List' type : If the response schema represents an array. * <li>'Empty' type : If there are no responses or there are no response for success code. */ private TypeInfo getResponseTypeInfo(Service.Builder serviceBuilder, Operation operation) { if (operation.getResponses() == null) { return WellKnownType.EMPTY.toTypeInfo(); } int successCodeCount = 0; Response successResponse = null; for (String responseCode : operation.getResponses().keySet()) { Response response = operation.getResponses().get(responseCode); if (isSuccessCode(responseCode)) { successCodeCount++; if (response.getSchema() != null) { successResponse = response; } } else { // TODO (guptasu): Handle other cases like 4xx errors and non-RefProperty Schemas. } } if (successCodeCount == 1 && successResponse != null && successResponse.getSchema() != null) { TypeInfo responseTypeInfo = typeBuilder.ensureNamed( serviceBuilder, typeBuilder.getTypeInfo(serviceBuilder, successResponse.getSchema()), NameConverter.operationIdToResponseMessageName(operation.getOperationId())); if (responseTypeInfo.cardinality() == Cardinality.CARDINALITY_REPEATED) { // TODO (guptasu): Seems like we cannot create custom ListValue, something like // ListString. Therefore falling back to ListValue. Can we do better than this ? return WellKnownType.LIST.toTypeInfo(); } else if (responseTypeInfo.kind() != Kind.TYPE_MESSAGE) { return WellKnownType.VALUE.toTypeInfo(); } else { return responseTypeInfo; } } else if (successCodeCount == 0) { return WellKnownType.EMPTY.toTypeInfo(); } else { // TODO (guptasu): Due to multiple schemas for successful response code return type for the // operation is generalized as Value type. return WellKnownType.VALUE.toTypeInfo(); } }