private void AddRequestFields(IList <ServiceFieldInfo> requestFields, SwaggerParameter swaggerParameter, string serviceMethodName, string httpMethod, SwaggerService swaggerService, NamedTextPosition position) { string kind = swaggerParameter.In; if (kind == SwaggerParameterKind.Path || kind == SwaggerParameterKind.Query || kind == SwaggerParameterKind.Header) { string typeName = swaggerService.TryGetFacilityTypeName(swaggerParameter, position); if (typeName != null) { if (typeName.EndsWith("[]", StringComparison.Ordinal)) { typeName = "string"; } var attributes = new List <ServiceAttributeInfo>(); if (swaggerParameter.Obsolete.GetValueOrDefault()) { attributes.Add(new ServiceAttributeInfo("obsolete")); } string fieldName = swaggerParameter.Identifier ?? swaggerParameter.Name; if (!ServiceDefinitionUtility.IsValidName(fieldName)) { fieldName = CodeGenUtility.ToCamelCase(fieldName); } if (kind == SwaggerParameterKind.Query) { var parameters = new List <ServiceAttributeParameterInfo>(); if (httpMethod != "GET") { parameters.Add(new ServiceAttributeParameterInfo("from", "query")); } if (fieldName != swaggerParameter.Name) { parameters.Add(new ServiceAttributeParameterInfo("name", swaggerParameter.Name)); } if (parameters.Count != 0) { attributes.Add(new ServiceAttributeInfo("http", parameters)); } } else if (kind == SwaggerParameterKind.Header) { attributes.Add(new ServiceAttributeInfo("http", new[] { new ServiceAttributeParameterInfo("from", "header"), new ServiceAttributeParameterInfo("name", swaggerParameter.Name), })); } requestFields.Add(new ServiceFieldInfo( fieldName, typeName: typeName, attributes: attributes, summary: PrepareSummary(swaggerParameter.Description), position: position)); } } else if (kind == SwaggerParameterKind.Body) { var bodySchema = swaggerService.ResolveDefinition(swaggerParameter.Schema, position); if ((bodySchema.Value.Type ?? SwaggerSchemaType.Object) == SwaggerSchemaType.Object && (bodySchema.Key == null || bodySchema.Key.Equals(serviceMethodName + "Request", StringComparison.OrdinalIgnoreCase))) { AddFieldsFromSchema(requestFields, swaggerService, position, bodySchema); } else { string typeName = bodySchema.Key ?? SwaggerUtility.FilterBodyTypeName(swaggerService.TryGetFacilityTypeName(bodySchema.Value, position)); if (typeName != null) { requestFields.Add(new ServiceFieldInfo( bodySchema.Value.Identifier ?? "body", typeName: typeName, attributes: new[] { new ServiceAttributeInfo("http", new[] { new ServiceAttributeParameterInfo("from", "body", position) }) }, summary: PrepareSummary(swaggerParameter.Description), position: position)); } } } }
internal static SwaggerParameter ResolveParameter(this SwaggerService swaggerService, SwaggerParameter swaggerParameter, NamedTextPosition position) { if (swaggerParameter.Ref != null) { const string refPrefix = "#/parameters/"; if (!swaggerParameter.Ref.StartsWith(refPrefix, StringComparison.Ordinal)) { throw new ServiceDefinitionException("Parameter $ref must start with '#/parameters/'.", position); } string name = UnescapeRefPart(swaggerParameter.Ref.Substring(refPrefix.Length)); if (!swaggerService.Parameters.TryGetValue(name, out swaggerParameter)) { throw new ServiceDefinitionException($"Missing parameter named '{name}'.", position); } } return(swaggerParameter); }