Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Reader changes external reference #986

Copy link
Copy link
@richardkaspar

Description

@richardkaspar
Issue body actions

Describe the bug
Microsoft.OpenApi.Readers 1.3.2 changes external references, that contains the character #.
The behavior of Microsoft.OpenApi.Readers 1.2.3 is as expected. It does not change external references. I did not check other Versions.
Example:
Reference in the OpenAPI file: https://gigantic-server.com/schemas/Monster#/?id=foo
After reading: https://gigantic-server.com/schemas/Monster#/components/schemas//?id=foo

To Reproduce
Use the following code to read 'readFile' and write 'writeFile'.
Open the two files in a compare tool.
Code:

        using var stream = new FileStream(readFile, FileMode.Open);
        var doc =
            new OpenApiStreamReader(
                    new OpenApiReaderSettings
                    {
                        ReferenceResolution = ReferenceResolutionSetting.DoNotResolveReferences
                    })
               .Read(stream, out _);

        var sb = new StringBuilder();

        var writer = new OpenApiYamlWriter(new StringWriter(sb, new CultureInfo("en_us")));

        doc.SerializeAsV3(writer);

        File.WriteAllText(writeFile, sb.ToString());

readFile:

    openapi: 3.0.1
    info:
      title: anyOf-oneOf
      license:
        name: MIT
      version: 1.0.0
    paths: { }
    components:
      schemas:
        Nested:
          type: object
          properties:
            AnyOf:
              anyOf:
                - $ref: '#/components/schemas/OneOf'
                - $ref: file:///C:/MySchemas.json#/definitions/ArrayObject
                - $ref: https://gigantic-server.com/schemas/Monster#/?id=foo
                - $ref: '#/components/schemas/ExtRef'
            OneOf:
              oneOf:
                - $ref: ../foo/schemas.yaml#/components/schemas/Number
                - $ref: '#/components/schemas/ExtRef'
                - $ref: '#/components/schemas/AnyOf'
                - type: string
        OneOf:
          oneOf:
            - $ref: ../foo/schemas.yaml#/components/schemas/Number
            - $ref: file:///C:/MySchemas.json#/definitions/ArrayObject
            - $ref: https://gigantic-server.com/schemas/Monster#/?id=foo
            - $ref: '#/components/schemas/ExtRef'
            - $ref: '#/components/schemas/AnyOf'
            - type: string
        AnyOf:
          anyOf:
            - $ref: '#/components/schemas/OneOf'
            - $ref: ../foo/schemas.yaml#/components/schemas/Number
            - $ref: file:///C:/MySchemas.json#/definitions/ArrayObject
            - $ref: https://gigantic-server.com/schemas/Monster#/?id=foo
            - $ref: '#/components/schemas/ExtRef'
        ExtRef:
          $ref: https://www.mid.de/OpenAPI/Schema/foo#/

writeFile:

    openapi: 3.0.1
    info:
      title: anyOf-oneOf
      license:
        name: MIT
      version: 1.0.0
    paths: { }
    components:
      schemas:
        Nested:
          type: object
          properties:
            AnyOf:
              anyOf:
                - $ref: '#/components/schemas/OneOf'
                - $ref: file:///C:/MySchemas.json#/components/schemas//definitions/ArrayObject
                - $ref: https://gigantic-server.com/schemas/Monster#/components/schemas//?id=foo
                - $ref: '#/components/schemas/ExtRef'
            OneOf:
              oneOf:
                - $ref: ../foo/schemas.yaml#/components/schemas/Number
                - $ref: '#/components/schemas/ExtRef'
                - $ref: '#/components/schemas/AnyOf'
                - type: string
        OneOf:
          oneOf:
            - $ref: ../foo/schemas.yaml#/components/schemas/Number
            - $ref: file:///C:/MySchemas.json#/components/schemas//definitions/ArrayObject
            - $ref: https://gigantic-server.com/schemas/Monster#/components/schemas//?id=foo
            - $ref: '#/components/schemas/ExtRef'
            - $ref: '#/components/schemas/AnyOf'
            - type: string
        AnyOf:
          anyOf:
            - $ref: '#/components/schemas/OneOf'
            - $ref: ../foo/schemas.yaml#/components/schemas/Number
            - $ref: file:///C:/MySchemas.json#/components/schemas//definitions/ArrayObject
            - $ref: https://gigantic-server.com/schemas/Monster#/components/schemas//?id=foo
            - $ref: '#/components/schemas/ExtRef'
        ExtRef:
          $ref: https://www.mid.de/OpenAPI/Schema/foo#/components/schemas//

Expected behavior
The content of writeFile and readFile should be equal.

Screenshots/Code Snippets
grafik

Additional context

Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

type:bugA broken experienceA broken experience

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.