Skip to content

Example value ist switching type (string -> date-time) #1230

@richardkaspar

Description

@richardkaspar

Describe the bug
Reading an OpenAPI document switches the type of a simple string value to a date-time value.
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.
The time zone of the computer ist UTC+01:00.
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: { }
components:
  schemas:
    Foo:
      type: object
      properties:
        list:
          type: array
          items:
            $ref: '#/components/schemas/Foo2'
      example:
        list:
          - duration: '00:04'
    Foo2:
      type: object
      properties:
        duration:
          type: string

writeFile:

openapi: 3.0.1
info:
  title: example
  description: Sample description
  version: 0.1.9
paths: { }
components:
  schemas:
    Foo:
      type: object
      properties:
        list:
          type: array
          items:
            $ref: '#/components/schemas/Foo2'
      example:
        list:
          - duration: '2023-04-24T00:04:00.0000000+02:00'
    Foo2:
      type: object
      properties:
        duration:
          type: string

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