Skip to content

Example value is switching type #1224

@richardkaspar

Description

@richardkaspar

Describe the bug
Reading an OpenAPI document containing an example value of type integer will switch the type to string.
Microsoft.OpenApi.Readers 1.6.3

To Reproduce
Use the following code with Microsoft.OpenApi.Readers 1.6.3.
Open the two files in a compare tool.
Code:

            using var stream = new FileStream(readFile, FileMode.Open, FileAccess.Read);

            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: example
  description: Sample description
  version: 0.1.9
paths:
  /foo:
    get:
      responses:
        '200':
          description: bla bla
components:
  examples:
    FooInt:
      value: 666

writeFile:

openapi: 3.0.1
info:
  title: example
  description: Sample description
  version: 0.1.9
paths:
  /foo:
    get:
      responses:
        '200':
          description: bla bla
components:
  examples:
    FooInt:
      value: '666'

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

Screenshots/Code Snippets
grafik

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:bugA broken experience

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions