private bool TryBuildResponseBody(string methodName, OperationResponse response, Func<string, string> typeNamer, out IType responseType) { bool handled = false; responseType = null; if (SwaggerOperationProducesJson()) { if (response.Schema != null) { string referenceKey; if (response.Schema.Reference != null) { referenceKey = response.Schema.Reference.StripDefinitionPath(); response.Schema.Reference = referenceKey; } else { referenceKey = typeNamer(methodName); } responseType = response.Schema.GetBuilder(_swaggerModeler).BuildServiceType(referenceKey); handled = true; } } return handled; }
private void TryBuildDefaultResponse(string methodName, OperationResponse response, Method method, IType headerType) { IType errorModel = null; if (SwaggerOperationProducesJson()) { if (TryBuildResponseBody(methodName, response, s => GenerateErrorModelName(s), out errorModel)) { method.DefaultResponse = new Response(errorModel, headerType); } } }
private bool TryBuildResponse(string methodName, HttpStatusCode responseStatusCode, OperationResponse response, Method method, List<Stack<IType>> types, IType headerType) { bool handled = false; IType serviceType; if (SwaggerOperationProducesJson()) { if (TryBuildResponseBody(methodName, response, s => GenerateResponseObjectName(s, responseStatusCode), out serviceType)) { method.Responses[responseStatusCode] = new Response(serviceType, headerType); BuildMethodReturnTypeStack(serviceType, types); handled = true; } } return handled; }
private bool TryBuildEmptyResponse(string methodName, HttpStatusCode responseStatusCode, OperationResponse response, Method method, List<Stack<IType>> types, IType headerType) { bool handled = false; if (response.Schema == null) { method.Responses[responseStatusCode] = new Response(null, headerType); handled = true; } else { if (_operation.Produces.IsNullOrEmpty()) { method.Responses[responseStatusCode] = new Response(new PrimaryType(KnownPrimaryType.Object), headerType); BuildMethodReturnTypeStack(new PrimaryType(KnownPrimaryType.Object), types); handled = true; } var unwrapedSchemaProperties = _swaggerModeler.Resolver.Unwrap(response.Schema).Properties; if (unwrapedSchemaProperties != null && unwrapedSchemaProperties.Any()) { Logger.LogWarning(Resources.NoProduceOperationWithBody, methodName); } } return handled; }
private bool TryBuildStreamResponse(HttpStatusCode responseStatusCode, OperationResponse response, Method method, List<Stack<IType>> types, IType headerType) { bool handled = false; if (SwaggerOperationProducesNotEmpty()) { if (response.Schema != null) { IType serviceType = response.Schema.GetBuilder(_swaggerModeler) .BuildServiceType(response.Schema.Reference.StripDefinitionPath()); Debug.Assert(serviceType != null); BuildMethodReturnTypeStack(serviceType, types); var compositeType = serviceType as CompositeType; if (compositeType != null) { VerifyFirstPropertyIsByteArray(compositeType); } method.Responses[responseStatusCode] = new Response(serviceType, headerType); handled = true; } } return handled; }