RicoSuter / NJsonSchema

JSON Schema reader, generator and validator for .NET
http://NJsonSchema.org
MIT License
1.37k stars 529 forks source link

Fixed the bug. "System.InvalidOperationException: Could not resolve the path '#/paths/~1audienceCategories~1%7Ba " #1703

Open hesi726 opened 2 months ago

hesi726 commented 2 months ago

in https://editor.swagger.io/, the follows yaml is legal.

openapi: 3.0.1
info:
  title: Media Owner Full-Stack API
  version: 1.0.89
servers:
  - url: https://api.abc.com/fs/v1
paths:
  "/audienceCategoryGroups/{audience-category-group-uuid}/audienceCategories":
    get:
      operationId: getAllAudienceCategoriesByGroup
      parameters:
        - in: path
          name: audience-category-group-uuid
          schema:
            type: string
          required: true
      responses:
        "200":
          description: Returns requested List of Audience Category Group
          content:
            application/json:
              schema:
                type: object
                properties:
                  audience_category_list:
                    type: array
                    items:
                      $ref: "#/_paths/~1audienceCategories~1%7Baudience-category-uuid%7D/get/responses\
                        /200/content/application~1json/schema"
  "/audienceCategories/{audience-category-uuid}":
    get:
      operationId: getAudienceCategoryByUUID
      parameters:
        - in: path
          name: audience-category-uuid
          schema:
            type: string
          required: true
      responses:
        "200":
          description: Returns requested Audience Category
          content:
            application/json:
              schema:
                allOf:
                  - type: object
                    properties:
                      name:
                        type: string
                        minLength: 1
                        maxLength: 100
                        description: Name of the Audience Category

But when i use nswag product csharp code, it throws the follow exception: System.InvalidOperationException: Could not resolve the path '#/paths/~1audienceCategories~1%7Baudience-category-uuid%7D/get/responses/200/content/application~1json/schema'.

And i modifyed the code in \NSwag-master\src\NJsonSchema\NJsonSchema\JsonReferenceResolver.cs in the ResolveDocumentReferenceWithoutDereferencing method, before "return null" , insert the follow code:

            var originalSegment = firstSegment;
#if NETSTANDARD1_2_OR_GREATER
            firstSegment = HttpUtility.UrlDecode(firstSegment);
#else
            firstSegment = WebUtility.UrlDecode(firstSegment);
#endif
            firstSegment = firstSegment.Replace("~1", "/");
            if (firstSegment == "paths") firstSegment = "_paths"; 
            if (originalSegment != firstSegment)
            {
                segments[0] = firstSegment;
                return ResolveDocumentReferenceWithoutDereferencing(obj, segments, targetType, contractResolver, checkedObjects);
            }

Fixed. But it seems that is not a routine modifications. So , How to ?