Repository navigation
Closed
Description
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.
Additional context
Metadata
Metadata
Assignees
Labels
type:bugA broken experienceA broken experience

Activity
darrelmiller commentedon Sep 8, 2022
Thank you for reporting this. This issue seems to be as a result of us adding support for inlining external references to OpenAPI descriptions. We currently don't support external references to files that are not OpenAPI descriptions (what we call fragments). However, we should not be changing the URL to external files that are fragments. I will investigate.