예제 #1
0
 private bool Equals(
     ApiOperationSchemaMap other)
 => SchemaKey == other.SchemaKey &&
 LocatedArea == other.LocatedArea &&
 SegmentName == other.SegmentName &&
 Path == other.Path &&
 OperationType == other.OperationType &&
 ParentSchemaKey == other.ParentSchemaKey;
예제 #2
0
    private static void CollectSchema(
        IDictionary <string, OpenApiSchema> componentsSchemas,
        OpenApiSchema?apiSchema,
        SchemaMapLocatedAreaType locatedArea,
        string apiPath,
        OperationType apiOperationType,
        string?parentApiSchema,
        List <ApiOperationSchemaMap> list)
    {
        if (apiSchema is null)
        {
            return;
        }

        string schemaKey;

        (schemaKey, apiSchema) = ConsolidateSchemaObjectTypes(apiSchema);

        if (schemaKey.Length == 0 ||
            schemaKey == nameof(ProblemDetails) ||
            schemaKey.Equals(Microsoft.OpenApi.Models.NameConstants.Pagination, StringComparison.OrdinalIgnoreCase))
        {
            return;
        }

        var apiOperationSchemaMap = new ApiOperationSchemaMap(schemaKey, locatedArea, apiPath, apiOperationType, parentApiSchema);

        if (list.Any(x => x.Equals(apiOperationSchemaMap)))
        {
            return;
        }

        list.Add(apiOperationSchemaMap);
        if (apiSchema.Properties.Any())
        {
            Collect(
                componentsSchemas,
                apiSchema.Properties.ToList(),
                locatedArea,
                apiPath,
                apiOperationType,
                schemaKey,
                list);
        }
        else if (apiSchema.AllOf.Count == 2 &&
                 (Microsoft.OpenApi.Models.NameConstants.Pagination.Equals(apiSchema.AllOf[0].Reference?.Id, StringComparison.OrdinalIgnoreCase) ||
                  Microsoft.OpenApi.Models.NameConstants.Pagination.Equals(apiSchema.AllOf[1].Reference?.Id, StringComparison.OrdinalIgnoreCase)))
        {
            string?subSchemaKey = null;
            if (!Microsoft.OpenApi.Models.NameConstants.Pagination.Equals(apiSchema.AllOf[0].Reference?.Id, StringComparison.OrdinalIgnoreCase))
            {
                subSchemaKey = apiSchema.AllOf[0].GetModelName();
            }

            if (!Microsoft.OpenApi.Models.NameConstants.Pagination.Equals(apiSchema.AllOf[1].Reference?.Id, StringComparison.OrdinalIgnoreCase))
            {
                subSchemaKey = apiSchema.AllOf[1].GetModelName();
            }

            if (subSchemaKey is not null)
            {
                var subApiSchema = componentsSchemas.Single(x => x.Key.Equals(schemaKey, StringComparison.OrdinalIgnoreCase)).Value;
                Collect(
                    componentsSchemas,
                    subApiSchema.Properties.ToList(),
                    locatedArea,
                    apiPath,
                    apiOperationType,
                    subSchemaKey,
                    list);
            }
        }
        else if (apiSchema.IsTypeArray() &&
                 apiSchema.Items?.Reference?.Id is not null)
        {
            var subSchemaKey             = apiSchema.Items.GetModelName();
            var subApiOperationSchemaMap = new ApiOperationSchemaMap(subSchemaKey, locatedArea, apiPath, apiOperationType, parentApiSchema);
            if (!list.Any(x => x.Equals(subApiOperationSchemaMap)))
            {
                list.Add(subApiOperationSchemaMap);

                var subApiSchema = componentsSchemas.Single(x => x.Key.Equals(subSchemaKey, StringComparison.OrdinalIgnoreCase)).Value;
                if (subApiSchema.Properties.Any())
                {
                    Collect(
                        componentsSchemas,
                        subApiSchema.Properties.ToList(),
                        locatedArea,
                        apiPath,
                        apiOperationType,
                        subSchemaKey,
                        list);
                }
            }
        }
    }