Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hesi726 opened this issue Jun 13, 2024 · 0 comments

Comments

@hesi726
Copy link

hesi726 commented Jun 13, 2024

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/1audienceCategories1%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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant